Skip to content

Commit 0f0ffa0

Browse files
Merge pull request #118 from icapps/feature/DartCore
Don't add imports for dart:core objects
2 parents ec4d0a3 + 2e0a5e6 commit 0f0ffa0

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## [6.0.1] - 2022-10-05
3+
- Don't create dart:core imports for custom objects
4+
25
## [6.0.0] - 2022-10-04
36
- Added the ability to specify simple fields in a more compact way, inline.
47

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ UnknownEnumTestObject:
464464

465465
## Custom object
466466

467-
Support for custom objects that are not generated by the model generator
467+
Support for custom objects that are not generated by the model generator.
468+
469+
Paths are either local to the project, package specifications (package:...) or dart:core
468470

469471
```yaml
470472
CustomObject:

lib/config/yml_generator_config.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class YmlGeneratorConfig {
305305
return [baseDirectory];
306306
} else if (path.startsWith('package:')) {
307307
return [path];
308+
} else if (path == 'dart:core') {
309+
return [];
308310
} else {
309311
return ['$baseDirectory/$path'];
310312
}
@@ -355,7 +357,7 @@ class YmlGeneratorConfig {
355357
models.firstWhereOrNull((model) => model.name == itemType.name);
356358
if (model == null) {
357359
throw Exception(
358-
'getModelByname is null: because `${itemType.name}` was not added to the config file');
360+
'getModelByName is null: because `${itemType.name}` was not added to the config file');
359361
}
360362
return model;
361363
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Person:
2+
type: object
3+
properties:
4+
address:
5+
type: Address
6+
7+
Address:
8+
type: custom
9+
path: dart:core

test/config/yml_generator_config_test.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ void main() {
281281
expect(config.getPathsForName(pubspecConfig, 'List<Person>').toList(),
282282
['model']);
283283
});
284+
test('Get paths with dart:core model', () {
285+
final pubspecConfig =
286+
PubspecConfig(ConfigTestHelper.getPubspecConfig('normal'));
287+
final config = YmlGeneratorConfig(pubspecConfig,
288+
ConfigTestHelper.getYmlGeneratorConfig('custom-dart-core'));
289+
expect(config.getPathsForName(pubspecConfig, 'Address').toList(), []);
290+
});
284291
test('Get path with invalid model', () {
285292
final pubspecConfig =
286293
PubspecConfig(ConfigTestHelper.getPubspecConfig('normal'));
@@ -296,7 +303,7 @@ void main() {
296303
}
297304
expect(hasError, true);
298305
expect(errorMessage,
299-
'Exception: getModelByname is null: because `TESTING` was not added to the config file');
306+
'Exception: getModelByName is null: because `TESTING` was not added to the config file');
300307
});
301308
});
302309
});

0 commit comments

Comments
 (0)