This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update
Validator
json schemas (#25)
- Loading branch information
Showing
15 changed files
with
157 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'dart:io'; | ||
import 'package:path/path.dart' as p; | ||
|
||
void main() { | ||
final schemasPath = p.join('tbdex', 'hosted', 'json-schemas'); | ||
final outputDir = Directory('lib/src/protocol/json-schemas') | ||
..createSync(recursive: true); | ||
|
||
Directory(schemasPath) | ||
.listSync() | ||
.whereType<File>() | ||
.where((file) => file.path.endsWith('.json')) | ||
.forEach((file) { | ||
final json = file.readAsStringSync(); | ||
final dartCode = _generateCode(file.path, json); | ||
|
||
File(p.join(outputDir.path, '${_getFileName(file.path)}.dart')) | ||
.writeAsStringSync(dartCode); | ||
}); | ||
} | ||
|
||
String _generateCode(String filePath, String jsonString) => ''' | ||
class ${_getClassName(filePath)} { | ||
static const String json = r\'\'\' | ||
$jsonString\'\'\'; | ||
}'''; | ||
|
||
String _getFileName(String filePath) { | ||
var segments = p.split(filePath); | ||
final index = segments.indexOf('json-schemas'); | ||
final baseName = segments[index + 1].split('.').first; | ||
|
||
return '${_toSnakeCase(baseName)}_schema'; | ||
} | ||
|
||
String _getClassName(String filePath) { | ||
var segments = p.split(filePath); | ||
final index = segments.indexOf('json-schemas'); | ||
final baseName = segments[index + 1].split('.').first; | ||
|
||
return '${_toCamelCase(baseName)}Schema'; | ||
} | ||
|
||
String _toSnakeCase(String input) => input.replaceAll('-', '_').toLowerCase(); | ||
|
||
String _toCamelCase(String input) => input | ||
.split(RegExp('[_-]')) | ||
.map( | ||
(str) => str.isEmpty | ||
? '' | ||
: str[0].toUpperCase() + str.substring(1).toLowerCase(), | ||
) | ||
.join(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...c/protocol/json-schemas/order.schema.json → ...c/protocol/json-schemas/order_schema.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
class OrderSchema { | ||
static const String json = r''' | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://tbdex.dev/order.schema.json", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": {} | ||
}'''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...tocol/json-schemas/reputation.schema.json → ...tocol/json-schemas/reputation_schema.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
class ReputationSchema { | ||
static const String json = r''' | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://tbdex.dev/reputation.schema.json" | ||
}'''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters