Skip to content

Commit 317a874

Browse files
committed
Support json_schema
1 parent 14c9b0e commit 317a874

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

Flutter/json_to_dart/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.3
2+
3+
* Support json_schema
4+
15
## 2.0.2
26

37
* Fix wrong copyWith method

Flutter/json_to_dart/lib/main_controller.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
1010
import 'package:get/get.dart';
1111
import 'package:intl/intl.dart';
1212
import 'package:json_to_dart/l10n/app_localizations.dart';
13+
import 'package:json_schema/json_schema.dart';
1314
import 'package:json_to_dart_library/json_to_dart_library.dart' hide StringE;
1415

1516
import 'models/config.dart';
@@ -69,12 +70,18 @@ class MainController extends GetxController with JsonToDartControllerMixin {
6970
inputText = text.replaceAll('.0', '.1');
7071
}
7172

72-
final dynamic jsonData =
73-
await compute<String, dynamic>(jsonDecode, inputText)
74-
.onError((Object? error, StackTrace stackTrace) {
73+
dynamic jsonData = await compute<String, dynamic>(jsonDecode, inputText)
74+
.onError((Object? error, StackTrace stackTrace) {
7575
handleError(error, stackTrace);
7676
});
7777

78+
// If the JSON data is a Map and contains a valid JSON Schema, convert it
79+
if (jsonData is Map && JsonSchemaHelper.isJsonSchema(jsonData)) {
80+
jsonData = JsonSchemaHelper.createJsonWithJsonSchema(
81+
JsonSchema.create(jsonData),
82+
);
83+
}
84+
7885
final DartObject? extendedObject = dynamicToDartObject(jsonData);
7986
// final DartObject? extendedObject =
8087
// await compute<dynamic, DartObject?>(createDartObject, jsonData)

Flutter/json_to_dart/pubspec.lock

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,22 @@ packages:
429429
url: "https://pub.flutter-io.cn"
430430
source: hosted
431431
version: "4.9.0"
432+
json_schema:
433+
dependency: transitive
434+
description:
435+
name: json_schema
436+
sha256: fc8c3e280c7647ed8e94f2565ba107ef4aff94b096764b8460a7e1ae39f20382
437+
url: "https://pub.flutter-io.cn"
438+
source: hosted
439+
version: "5.2.1"
432440
json_to_dart_library:
433441
dependency: "direct main"
434442
description:
435443
name: json_to_dart_library
436-
sha256: "68f5ad7fe24f8750636102e2ca9b43c4e6d0d70e96dc1a6a4aba5aac5cd2804b"
444+
sha256: "28522d55035b2a1a569746d31bdc1775db690e3a04561d83bbebba258f1ad5b7"
437445
url: "https://pub.flutter-io.cn"
438446
source: hosted
439-
version: "0.0.5"
447+
version: "0.0.6"
440448
leak_tracker:
441449
dependency: transitive
442450
description:
@@ -629,6 +637,22 @@ packages:
629637
url: "https://pub.flutter-io.cn"
630638
source: hosted
631639
version: "1.5.0"
640+
quiver:
641+
dependency: transitive
642+
description:
643+
name: quiver
644+
sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2
645+
url: "https://pub.flutter-io.cn"
646+
source: hosted
647+
version: "3.2.2"
648+
rfc_6901:
649+
dependency: transitive
650+
description:
651+
name: rfc_6901
652+
sha256: df1bbfa3d023009598f19636d6114c6ac1e0b7bb7bf6a260f0e6e6ce91416820
653+
url: "https://pub.flutter-io.cn"
654+
source: hosted
655+
version: "0.2.0"
632656
shelf:
633657
dependency: transitive
634658
description:
@@ -738,6 +762,14 @@ packages:
738762
url: "https://pub.flutter-io.cn"
739763
source: hosted
740764
version: "2.2.2"
765+
uri:
766+
dependency: transitive
767+
description:
768+
name: uri
769+
sha256: "889eea21e953187c6099802b7b4cf5219ba8f3518f604a1033064d45b1b8268a"
770+
url: "https://pub.flutter-io.cn"
771+
source: hosted
772+
version: "1.0.0"
741773
vector_math:
742774
dependency: transitive
743775
description:

Flutter/json_to_dart/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: The tool to convert json to dart code.
1111
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1212
# Read more about iOS versioning at
1313
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14-
version: 2.0.2
14+
version: 2.0.3
1515

1616
environment:
1717
sdk: ">=3.5.0 <4.0.0"
@@ -34,7 +34,7 @@ dependencies:
3434

3535
hive: any
3636
hive_flutter: any
37-
json_to_dart_library: ^0.0.5
37+
json_to_dart_library: ^0.0.6
3838
nested: any
3939

4040
dependency_overrides:

0 commit comments

Comments
 (0)