Skip to content

Commit

Permalink
Merge branch 'warnings' of github.com:javiercbk/json_to_dart into war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
javiercbk committed Jul 31, 2019
2 parents 487efb0 + b9e552d commit 914bcee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/model_generator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dart_style/dart_style.dart';
import 'package:json_ast/json_ast.dart' show parse, Settings;
import './helpers.dart';
import './syntax.dart';

Expand All @@ -8,6 +9,7 @@ class DartCode extends WithWarning<String> {
String get code => this.result;
}

/// A Hint is a user type correction.
class Hint {
final String path;
final String type;
Expand All @@ -33,12 +35,13 @@ class ModelGenerator {
return this.hints.firstWhere((h) => h.path == path, orElse: () => null);
}

List<Warning> _generateClassDefinition(String className, Map<dynamic, dynamic> jsonRawData, String path) {
List<Warning> _generateClassDefinition(String className, Map<dynamic, dynamic> jsonRawData, String path, Node astNode) {
List<Warning> warnings = new List<Warning>();
if (jsonRawData is List) {
// if first element is an array, start in the first element.
_generateClassDefinition(className, jsonRawData[0], path);
} else {

final keys = jsonRawData.keys;
ClassDefinition classDefinition = new ClassDefinition(className, _privateFields);
keys.forEach((key) {
Expand Down Expand Up @@ -107,7 +110,8 @@ class ModelGenerator {
/// might be returned
DartCode generateUnsafeDart(String rawJson) {
final Map<String, dynamic> jsonRawData = decodeJSON(rawJson);
List<Warning> warnings = _generateClassDefinition(_rootClassName, jsonRawData, "");
final astNode = parse(rawJson, Settings());
List<Warning> warnings = _generateClassDefinition(_rootClassName, jsonRawData, "", astNode);
return new DartCode(allClasses.map((c) => c.toString()).join('\n'), warnings);
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ homepage: https://github.com/javiercbk/json_to_dart
environment:
sdk: ">=2.0.0"
dependencies:
json_ast: "^1.0.0"
convert: "^2.0.1"
dart_style: "^1.0.10"

Expand Down

0 comments on commit 914bcee

Please sign in to comment.