Skip to content

Commit

Permalink
Don't add imports for dart:core objects
Browse files Browse the repository at this point in the history
Fixed typo
Updated docs to make paths clearer for custom objects
  • Loading branch information
NicolaVerbeeck committed Oct 5, 2022
1 parent ec4d0a3 commit 2e0a5e6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## [6.0.1] - 2022-10-05
- Don't create dart:core imports for custom objects

## [6.0.0] - 2022-10-04
- Added the ability to specify simple fields in a more compact way, inline.

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ UnknownEnumTestObject:

## Custom object

Support for custom objects that are not generated by the model generator
Support for custom objects that are not generated by the model generator.

Paths are either local to the project, package specifications (package:...) or dart:core

```yaml
CustomObject:
Expand Down
4 changes: 3 additions & 1 deletion lib/config/yml_generator_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ class YmlGeneratorConfig {
return [baseDirectory];
} else if (path.startsWith('package:')) {
return [path];
} else if (path == 'dart:core') {
return [];
} else {
return ['$baseDirectory/$path'];
}
Expand Down Expand Up @@ -355,7 +357,7 @@ class YmlGeneratorConfig {
models.firstWhereOrNull((model) => model.name == itemType.name);
if (model == null) {
throw Exception(
'getModelByname is null: because `${itemType.name}` was not added to the config file');
'getModelByName is null: because `${itemType.name}` was not added to the config file');
}
return model;
}
Expand Down
9 changes: 9 additions & 0 deletions test/config/yml_generator_config/custom-dart-core.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Person:
type: object
properties:
address:
type: Address

Address:
type: custom
path: dart:core
9 changes: 8 additions & 1 deletion test/config/yml_generator_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ void main() {
expect(config.getPathsForName(pubspecConfig, 'List<Person>').toList(),
['model']);
});
test('Get paths with dart:core model', () {
final pubspecConfig =
PubspecConfig(ConfigTestHelper.getPubspecConfig('normal'));
final config = YmlGeneratorConfig(pubspecConfig,
ConfigTestHelper.getYmlGeneratorConfig('custom-dart-core'));
expect(config.getPathsForName(pubspecConfig, 'Address').toList(), []);
});
test('Get path with invalid model', () {
final pubspecConfig =
PubspecConfig(ConfigTestHelper.getPubspecConfig('normal'));
Expand All @@ -296,7 +303,7 @@ void main() {
}
expect(hasError, true);
expect(errorMessage,
'Exception: getModelByname is null: because `TESTING` was not added to the config file');
'Exception: getModelByName is null: because `TESTING` was not added to the config file');
});
});
});
Expand Down

0 comments on commit 2e0a5e6

Please sign in to comment.