Skip to content

Commit a619f4d

Browse files
committed
All tests passing
1 parent b2f03f2 commit a619f4d

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

openapi-generator/lib/src/models/generator_arguments.dart

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,7 @@ class GeneratorArguments {
4747
/// Use a custom pubspec file when generating.
4848
///
4949
/// Defaults to the pubspec at the root of [Directory.current].
50-
final String? _pubspecPath;
51-
52-
String? get pubspecPath => _pubspecPath != null
53-
? _pubspecPath!.startsWith('./')
54-
? _pubspecPath!.replaceFirst('.', Directory.current.path)
55-
: _pubspecPath!.startsWith('../')
56-
? _pubspecPath!.replaceFirst('..', Directory.current.parent.path)
57-
: _pubspecPath
58-
: _pubspecPath;
50+
final String? pubspecPath;
5951

6052
/// The directory where the generated sources will be placed.
6153
///
@@ -163,7 +155,7 @@ class GeneratorArguments {
163155
annotations.readPropertyOrDefault('useNextGen', useNextGen),
164156
cachePath = annotations.readPropertyOrDefault(
165157
'cachePath', cachePath ?? defaultCachedPath),
166-
_pubspecPath = annotations.readPropertyOrDefault<String>(
158+
pubspecPath = annotations.readPropertyOrDefault<String>(
167159
'projectPubspecPath',
168160
pubspecPath ??
169161
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml');
@@ -206,13 +198,7 @@ class GeneratorArguments {
206198
Future<String> get inputFileOrFetch async {
207199
final curr = Directory.current;
208200
if (_inputFile.isNotEmpty) {
209-
if (_inputFile.startsWith(r'./')) {
210-
return _inputFile.replaceFirst('.', curr.path);
211-
} else if (_inputFile.startsWith('../')) {
212-
return _inputFile.replaceFirst('..', curr.parent.path);
213-
} else {
214-
return _inputFile;
215-
}
201+
return _inputFile;
216202
}
217203

218204
try {

openapi-generator/test/builder_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
outputDirectory: 'api/petstore_api')
3030
'''),
3131
contains(
32-
'generate -o api/petstore_api -i ${Directory.current.parent.path}/openapi-spec.yaml -g dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,prependFormOrBodyParameters=false,pubAuthor=Johnny dep...,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none,dateLibrary=core,serializationLibrary=built_value'));
32+
'generate -o api/petstore_api -i ../openapi-spec.yaml -g dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,prependFormOrBodyParameters=false,pubAuthor=Johnny dep...,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none,dateLibrary=core,serializationLibrary=built_value'));
3333
});
3434

3535
test('to generate command with import and type mappings', () async {
@@ -42,7 +42,7 @@ void main() {
4242
generatorName: Generator.dio)
4343
'''),
4444
contains(
45-
'generate -o ${Directory.current.path} -i ${Directory.current.parent.path}/openapi-spec.yaml -g dart-dio --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
45+
'generate -o ${Directory.current.path} -i ../openapi-spec.yaml -g dart-dio --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
4646
});
4747

4848
test('to generate command with inline schema mappings', () async {
@@ -55,7 +55,7 @@ void main() {
5555
generatorName: Generator.dio)
5656
'''),
5757
contains('''
58-
generate -o ${Directory.current.path} -i ${Directory.current.parent.path}/openapi-spec.yaml -g dart-dio --inline-schema-name-mappings=inline_object_2=SomethingMapped,inline_object_4=nothing_new --type-mappings=int-or-string=IntOrString
58+
generate -o ${Directory.current.path} -i ../openapi-spec.yaml -g dart-dio --inline-schema-name-mappings=inline_object_2=SomethingMapped,inline_object_4=nothing_new --type-mappings=int-or-string=IntOrString
5959
'''
6060
.trim()));
6161
});
@@ -87,7 +87,7 @@ void main() {
8787
outputDirectory: 'api/petstore_api')
8888
'''),
8989
contains('''
90-
generate -o api/petstore_api -i ${Directory.current.parent.path}/openapi-spec.yaml -g dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,prependFormOrBodyParameters=false,pubAuthor=Johnny dep...,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none,dateLibrary=core,serializationLibrary=built_value
90+
generate -o api/petstore_api -i ../openapi-spec.yaml -g dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,prependFormOrBodyParameters=false,pubAuthor=Johnny dep...,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none,dateLibrary=core,serializationLibrary=built_value
9191
'''
9292
.trim()));
9393
});
@@ -103,7 +103,7 @@ void main() {
103103
generatorName: Generator.dioAlt)
104104
'''),
105105
contains(
106-
'generate -o ${Directory.current.path} -i ${Directory.current.parent.path}/openapi-spec.yaml -g dart2-api --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
106+
'generate -o ${Directory.current.path} -i ../openapi-spec.yaml -g dart2-api --import-mappings=IntOrString=./int_or_string.dart --type-mappings=int-or-string=IntOrString'));
107107
});
108108
});
109109

openapi-generator/test/gen_on_spec_changes_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void main() {
2727
await loadSpec(specPath: './thisIsSomeInvalidPath.wrong');
2828
fail('Should\'ve thrown as not supported file type.');
2929
} catch (e, _) {
30-
expect(e as String, 'Invalid spec file format');
30+
expect((e as OutputMessage).message, 'Invalid spec file format.');
3131
}
3232
});
3333
test('throws an error for missing config file', () async {

openapi-generator/test/generator_arguments_test.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ void main() {
2323
test('shouldFetchDependencies',
2424
() => expect(args.shouldFetchDependencies, isTrue));
2525
test('skipValidation', () => expect(args.skipValidation, isFalse));
26+
test(
27+
'pubspecPath',
28+
() => expect(
29+
args.pubspecPath, '${Directory.current.path}/pubspec.yaml'));
2630
group('inputFile', () {
2731
test('errors when no spec is found', () async {
2832
await args.inputFileOrFetch.onError((e, __) {
@@ -95,7 +99,8 @@ void main() {
9599
typeMapping: {'package': 'type'},
96100
reservedWordsMapping: {'const': 'final'},
97101
inlineSchemaNameMapping: {'L': 'R'},
98-
additionalProperties: AdditionalProperties(wrapper: Wrapper.fvm));
102+
additionalProperties: AdditionalProperties(wrapper: Wrapper.fvm),
103+
pubspecPath: 'testing/pubspec.yaml');
99104
test('alwaysRun', () => expect(args.alwaysRun, isTrue));
100105
test('useNextGen', () => expect(args.useNextGen, isTrue));
101106
test('cachePath', () => expect(args.cachePath, 'test'));
@@ -122,6 +127,8 @@ void main() {
122127
test('generatorName', () => expect(args.generatorName, 'dart2-api'));
123128
test('shouldGenerateSources',
124129
() => expect(args.shouldGenerateSources, isTrue));
130+
test('pubspecPath',
131+
() => expect(args.pubspecPath, 'testing/pubspec.yaml'));
125132
test(
126133
'jarArgs',
127134
() async => expect(
@@ -170,7 +177,7 @@ void main() {
170177
expect(args.typeMappings, {'key': 'value'});
171178
expect(args.reservedWordsMappings, {'const': 'final'});
172179
expect(args.inlineSchemaNameMappings, {'200resp': 'OkResp'});
173-
180+
expect(args.pubspecPath, './test/specs/dart_pubspec.test.yaml');
174181
expect(args.isRemote, isFalse);
175182
expect(args.generatorName, 'dart-dio');
176183
expect(args.shouldGenerateSources, isTrue);

openapi-generator/test/specs/test_config.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
1919
additionalProperties: AdditionalProperties(wrapper: Wrapper.fvm),
2020
inlineSchemaNameMappings: {'200resp': 'OkResp'},
2121
overwriteExistingFiles: true,
22+
projectPubspecPath: './test/specs/dart_pubspec.test.yaml',
2223
)
2324
class TestClassConfig extends OpenapiGeneratorConfig {}

0 commit comments

Comments
 (0)