Skip to content

Commit 84f72df

Browse files
committed
refactor(annotations): changed inputspec methods to be more descriptive
BREAKING CHANGE: changed Inputspec.empty to Inputspec.json changed Inputspec.emptyYaml to Inputspec.yaml
1 parent 9970634 commit 84f72df

File tree

5 files changed

+27
-38
lines changed

5 files changed

+27
-38
lines changed

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ void main() {
1010
additionalProperties:
1111
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
1212
inputSpecFile: 'openapi-spec.yaml',
13+
inputSpec: InputSpec(path: 'openapi-spec.yaml'),
1314
typeMappings: {'Pet': 'ExamplePet'},
1415
generatorName: Generator.dio,
1516
runSourceGenOnOutput: true,

openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Openapi {
152152
this.additionalProperties,
153153
this.overwriteExistingFiles,
154154
this.skipSpecValidation = false,
155-
required this.inputSpecFile,
155+
@Deprecated('To be removed in the next major') required this.inputSpecFile,
156156
this.inputSpec,
157157
this.templateDirectory,
158158
required this.generatorName,
@@ -179,30 +179,18 @@ class Openapi {
179179
/// Includes the option to use the default json or yaml paths.
180180
class InputSpec {
181181
final String path;
182-
final bool defaultYaml;
183-
final bool useYml;
184182

185-
const InputSpec({String? path, this.defaultYaml = true, this.useYml = false})
186-
: path = path ??
187-
'openapi.${defaultYaml ? 'y${useYml ? '' : 'a'}ml' : 'json'}';
183+
const InputSpec({required this.path});
188184

189-
const InputSpec.empty() : this();
185+
const InputSpec.json() : this(path: 'openapi.json');
190186

191-
const InputSpec.emptyJson() : this(defaultYaml: false);
192-
const InputSpec.emptyYml() : this(useYml: true);
187+
const InputSpec.yaml({bool shortExtension = false})
188+
: this(path: 'openapi.y${shortExtension ? '' : 'a'}ml');
193189

194-
Map<String, dynamic> toJsonMap() => {
195-
'path': path,
196-
'defaultYaml': defaultYaml,
197-
'useYml': useYml,
198-
};
190+
Map<String, dynamic> toJsonMap() => {'path': path};
199191

200192
InputSpec.fromMap(Map<String, dynamic> map)
201-
: this(
202-
path: map['path'],
203-
defaultYaml: map['defaultYaml'] == 'true' ? true : false,
204-
useYml: map['useYml'] == 'true' ? true : false,
205-
);
193+
: this(path: map['path']);
206194
}
207195

208196
/// Provides the location for the remote specification.

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ void main() {
99
group('OpenApi', () {
1010
test('defaults', () {
1111
final props = Openapi(
12-
inputSpecFile: InputSpec.empty().path,
13-
inputSpec: InputSpec.empty(),
12+
inputSpecFile: InputSpec.json().path,
13+
inputSpec: InputSpec.json(),
1414
generatorName: Generator.dart,
1515
);
1616
expect(props.additionalProperties, isNull);
1717
expect(props.overwriteExistingFiles, isNull);
1818
expect(props.skipSpecValidation, false);
19-
expect(props.inputSpecFile, InputSpec.empty().path);
20-
expect(props.inputSpec!.path, InputSpec.empty().path);
19+
expect(props.inputSpecFile, InputSpec.json().path);
20+
expect(props.inputSpec!.path, InputSpec.json().path);
2121
expect(props.templateDirectory, isNull);
2222
expect(props.generatorName, Generator.dart);
2323
expect(props.outputDirectory, isNull);
@@ -37,49 +37,45 @@ void main() {
3737
group('NextGen', () {
3838
test('Sets cachePath', () {
3939
final api = Openapi(
40-
inputSpecFile: InputSpec.empty().path,
40+
inputSpecFile: InputSpec.json().path,
4141
generatorName: Generator.dart,
4242
cachePath: 'somePath');
4343
expect(api.cachePath, 'somePath');
4444
});
4545
test('Sets useNextGenFlag', () {
4646
final api = Openapi(
47-
inputSpecFile: InputSpec.empty().path,
47+
inputSpecFile: InputSpec.json().path,
4848
generatorName: Generator.dart,
4949
useNextGen: true);
5050
expect(api.useNextGen, isTrue);
5151
});
5252
test('Sets projectPubspecPath', () {
5353
final api = Openapi(
54-
inputSpecFile: InputSpec.empty().path,
54+
inputSpecFile: InputSpec.json().path,
5555
generatorName: Generator.dart,
5656
projectPubspecPath: 'test');
5757
expect(api.projectPubspecPath, 'test');
5858
});
5959
test('Set debug logging', () {
6060
final api = Openapi(
61-
inputSpecFile: InputSpec.empty().path,
62-
inputSpec: InputSpec.empty(),
61+
inputSpecFile: InputSpec.json().path,
62+
inputSpec: InputSpec.json(),
6363
generatorName: Generator.dart,
6464
debugLogging: true);
6565
expect(api.debugLogging, isTrue);
6666
});
6767
group('InputSpec', () {
6868
group('local spec', () {
6969
test('provides default yaml path', () {
70-
expect(InputSpec.empty().path, 'openapi.yaml');
71-
expect(InputSpec.empty().defaultYaml, isTrue);
72-
expect(InputSpec.empty().useYml, isFalse);
70+
expect(InputSpec.yaml().path, 'openapi.yaml');
71+
expect(InputSpec.yaml(shortExtension: true).path, 'openapi.yml');
7372
});
7473
test('provides default yml path', () {
75-
expect(InputSpec.emptyYml().path, 'openapi.yml');
76-
expect(InputSpec.emptyYml().defaultYaml, isTrue);
77-
expect(InputSpec.emptyYml().useYml, isTrue);
74+
expect(InputSpec.yaml(shortExtension: true).path, 'openapi.yml');
75+
expect(InputSpec.yaml(shortExtension: false).path, 'openapi.yaml');
7876
});
7977
test('provides default json path', () {
80-
expect(InputSpec.emptyJson().path, 'openapi.json');
81-
expect(InputSpec.emptyJson().defaultYaml, isFalse);
82-
expect(InputSpec.emptyJson().useYml, isFalse);
78+
expect(InputSpec.json().path, 'openapi.json');
8379
});
8480
test('uses path', () {
8581
expect(InputSpec(path: 'path').path, 'path');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class GeneratorArguments {
117117
required src_gen.ConstantReader annotations,
118118
bool alwaysRun = false,
119119
String inputSpecFile = '',
120-
InputSpec inputSpec = const InputSpec.empty(),
120+
InputSpec inputSpec = const InputSpec.json(),
121121
String templateDirectory = '',
122122
Generator generator = Generator.dart,
123123
Map<String, String> typeMapping = const {},

openapi-generator/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ dev_dependencies:
2424
source_gen_test:
2525
pedantic:
2626
coverage: ^1.6.3
27+
28+
dependency_overrides:
29+
openapi_generator_annotations:
30+
path: ../openapi-generator-annotations

0 commit comments

Comments
 (0)