platform/packages/json_god/test/shared.dart

52 lines
1.4 KiB
Dart
Raw Normal View History

2021-03-07 15:56:09 +00:00
import 'package:logging/logging.dart';
2021-05-14 12:24:45 +00:00
import 'package:angel3_json_god/angel3_json_god.dart';
2021-03-07 15:56:09 +00:00
import 'package:stack_trace/stack_trace.dart';
void printRecord(LogRecord rec) {
print(rec);
if (rec.error != null) print(rec.error);
2021-05-14 12:24:45 +00:00
if (rec.stackTrace != null) print(Chain.forTrace(rec.stackTrace!).terse);
2021-03-07 15:56:09 +00:00
}
class SampleNestedClass {
2021-04-10 12:42:55 +00:00
String? bar;
2021-03-07 15:56:09 +00:00
2021-04-10 12:42:55 +00:00
SampleNestedClass([String? this.bar]);
2021-03-07 15:56:09 +00:00
}
class SampleClass {
2021-04-10 12:42:55 +00:00
String? hello;
2021-03-07 15:56:09 +00:00
List<SampleNestedClass> nested = [];
2021-04-10 12:42:55 +00:00
SampleClass([String? this.hello]);
2021-03-07 15:56:09 +00:00
}
@WithSchemaUrl(
"http://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/babelrc.json")
class BabelRc {
List<String> presets;
List<String> plugins;
BabelRc(
{List<String> this.presets: const [],
List<String> this.plugins: const []});
}
@WithSchema(const {
r"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Validated Sample Class",
"description": "Sample schema for validation via JSON God",
"type": "object",
"hello": const {"description": "A friendly greeting.", "type": "string"},
"nested": const {
"description": "A list of NestedSampleClass items within this instance.",
"type": "array",
"items": const {
"type": "object",
"bar": const {"description": "Filler text", "type": "string"}
}
},
"required": const ["hello", "nested"]
})
class ValidatedSampleClass {}