Skip to content

Commit 9eafc8e

Browse files
authored
Merge pull request #107 from gibahjoe/upgrade-5.0-start
feat: update openapi jar to 7.0
2 parents 23d7594 + 5d6407a commit 9eafc8e

25 files changed

+385
-570
lines changed

README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ Annotate a dart class with @Openapi() annotation
7474
7575
```dart
7676
@Openapi(
77-
additionalProperties:
78-
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
79-
inputSpecFile: 'example/openapi-spec.yaml',
80-
generatorName: Generator.dart,
81-
outputDirectory: 'api/petstore_api')
82-
class Example {}
77+
additionalProperties:
78+
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
79+
inputSpec:
80+
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
81+
typeMappings: {'Pet': 'ExamplePet'},
82+
generatorName: Generator.dio,
83+
runSourceGenOnOutput: true,
84+
outputDirectory: 'api/petstore_api',
85+
)
8386
```
8487

8588
Run
@@ -99,7 +102,8 @@ The api sdk will be generated in the folder specified in the annotation. See exa
99102

100103
## Next Generation
101104

102-
There is some new functionality slated to be added to the generator. This version will have the ability to:
105+
As of version 5.0 of this library, there is some new functionality slated to be added to the generator. This version
106+
will have the ability to:
103107

104108
- cache changes in the OAS spec
105109
- Rerun when there ares difference in the cached copy and current copy
@@ -118,25 +122,18 @@ New:
118122

119123
```dart
120124
@Openapi(
121-
additionalProperties:
122-
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
123-
inputSpecFile: 'example/openapi-spec.yaml',
124-
generatorName: Generator.dart,
125-
outputDirectory: 'api/petstore_api',
126-
cachePath: 'some/preferred/directory/cache.json',
127-
useNextGen: true
125+
additionalProperties:
126+
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
127+
inputSpec:
128+
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
129+
typeMappings: {'Pet': 'ExamplePet'},
130+
generatorName: Generator.dio,
131+
runSourceGenOnOutput: true,
132+
outputDirectory: 'api/petstore_api',
128133
)
129134
class Example {}
130135
```
131136

132-
**IMPORTANT** With the new changes comes 2 new annotation properties:
133-
134-
- useNextGen (boolean)
135-
- Default: `false`
136-
- cachePath (String)
137-
- Default: `.dart_tool/openapi-generator-cache.json`
138-
- Must be a path to a `json` file.
139-
- Can only be set when `useNextGen` is `true`
140137

141138
## Contributing
142139

example/api/petstore_api/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
sdk: '>=2.15.0 <3.0.0'
88

99
dependencies:
10-
dio: '^5.0.0'
10+
dio: '^5.2.0'
1111
one_of: '>=1.5.0 <2.0.0'
1212
one_of_serializer: '>=1.5.0 <2.0.0'
1313
built_value: '>=8.4.0 <9.0.0'

example/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Openapi Generator last run: : 2023-08-20T13:11:18.157121
1+
// Openapi Generator last run: : 2024-01-16T01:49:21.940229
22
import 'package:flutter/material.dart';
33
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
44

@@ -9,11 +9,11 @@ void main() {
99
@Openapi(
1010
additionalProperties:
1111
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
12-
inputSpecFile: 'openapi-spec.yaml',
12+
inputSpec:
13+
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
1314
typeMappings: {'Pet': 'ExamplePet'},
1415
generatorName: Generator.dio,
1516
runSourceGenOnOutput: true,
16-
useNextGen: true,
1717
outputDirectory: 'api/petstore_api',
1818
)
1919
class MyApp extends StatelessWidget {
@@ -124,4 +124,4 @@ class _MyHomePageState extends State<MyHomePage> {
124124
), // This trailing comma makes auto-formatting nicer for build methods.
125125
);
126126
}
127-
}
127+
}

openapi-generator-annotations/example/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
33
@Openapi(
44
additionalProperties:
55
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
6-
inputSpecFile: 'example/openapi-spec.yaml',
6+
inputSpec: InputSpec(path: 'example/openapi-spec.yaml'),
77
generatorName: Generator.dio,
88
outputDirectory: 'api/petstore_api',
99
// useNextGen: true,

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

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import 'dart:io';
44
import 'package:crypto/crypto.dart';
55
import 'package:meta/meta.dart';
66

7-
/// Config base class
8-
/// Your annotated class must extend this config class
9-
@Deprecated(
10-
'You do not need to extend this anymore (See example). This class would be removed in the next major release.')
11-
abstract class OpenapiGeneratorConfig {}
12-
137
class Openapi {
148
/// Additional properties to pass to the compiler (CSV)
159
///
@@ -26,12 +20,6 @@ class Openapi {
2620
/// --api-package
2721
final String? apiPackage;
2822

29-
/// relative path or url to spec file
30-
///
31-
/// -i
32-
@Deprecated('To be removed in the next major')
33-
final String inputSpecFile;
34-
3523
/// Provides the access information to the input spec file.
3624
///
3725
/// For use with useNextGen.
@@ -43,7 +31,7 @@ class Openapi {
4331
/// to be applied to the fetch request when the spec file is in a remote
4432
/// location. There is also special handling for when the spec file lives within
4533
/// AWS.
46-
final InputSpec? inputSpec;
34+
final InputSpec inputSpec;
4735

4836
/// folder containing the template files
4937
///
@@ -80,12 +68,6 @@ class Openapi {
8068
/// --reserved-words-mappings
8169
final Map<String, String>? reservedWordsMappings;
8270

83-
/// Tells openapi-generator to always run during the build process
84-
/// if set to false (the default), openapi-generator will skip processing if the [outputDirectory] already exists
85-
@Deprecated(
86-
'The generator will always run to determine if there are changes made on the input spec file')
87-
final bool? alwaysRun;
88-
8971
/// if set to true, flutter pub get will be run on the [outputDirectory] after the code has been generated.
9072
/// Defaults to true for backwards compatibility
9173
final bool? fetchDependencies;
@@ -122,21 +104,6 @@ class Openapi {
122104
/// e.g {'inline_object_2': 'SomethingMapped'}
123105
final Map<String, String>? inlineSchemaNameMappings;
124106

125-
/// Use the next generation of the generator.
126-
///
127-
/// This annotation informs the generator to use the new generator pathway.
128-
/// Enabling this option allows for incremental changes to the [inputSpecFile]
129-
/// to be generated even though the annotation was unchanged.
130-
///
131-
/// Due to some limitations with build_runner and it only running when the
132-
/// asset graph has changed, a generated line get injected at the beginning of
133-
/// the file at the end of each run.
134-
///
135-
/// This will become the default behaviour in the next Major version (v5).
136-
///
137-
/// Default: false
138-
final bool useNextGen;
139-
140107
/// The path where to store the cached copy of the specification.
141108
///
142109
/// For use with [useNextGen].
@@ -152,8 +119,7 @@ class Openapi {
152119
this.additionalProperties,
153120
this.overwriteExistingFiles,
154121
this.skipSpecValidation = false,
155-
required this.inputSpecFile,
156-
this.inputSpec,
122+
required this.inputSpec,
157123
this.templateDirectory,
158124
required this.generatorName,
159125
this.outputDirectory,
@@ -165,9 +131,7 @@ class Openapi {
165131
this.apiPackage,
166132
this.fetchDependencies = true,
167133
this.runSourceGenOnOutput = true,
168-
this.alwaysRun = false,
169134
this.cachePath,
170-
this.useNextGen = false,
171135
this.projectPubspecPath,
172136
this.debugLogging = false,
173137
});
@@ -179,30 +143,18 @@ class Openapi {
179143
/// Includes the option to use the default json or yaml paths.
180144
class InputSpec {
181145
final String path;
182-
final bool defaultYaml;
183-
final bool useYml;
184146

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

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

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

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

200156
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-
);
157+
: this(path: map['path']);
206158
}
207159

208160
/// Provides the location for the remote specification.
@@ -377,10 +329,13 @@ class AdditionalProperties {
377329
/// Allow the 'x-enum-values' extension for enums
378330
final bool? useEnumExtension;
379331

380-
/// With this option enabled, each enum will have a new case, 'unknown_default_open_api',
332+
/// If the server adds new enum cases, that are unknown by an old spec/client,
333+
/// the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api',
381334
/// so that when the server sends an enum case that is not known by the client/spec,
382-
/// they can safely fallback to this case
383-
final bool? enumUnknownDefaultCase;
335+
/// they can safely fallback to this case.
336+
///
337+
/// Default: false
338+
final bool enumUnknownDefaultCase;
384339

385340
/// Flutter wrapper to use (none|flutterw|fvm)
386341
final Wrapper wrapper;
@@ -404,7 +359,7 @@ class AdditionalProperties {
404359
this.allowUnicodeIdentifiers = false,
405360
this.ensureUniqueParams = true,
406361
this.useEnumExtension = false,
407-
this.enumUnknownDefaultCase = true,
362+
this.enumUnknownDefaultCase = false,
408363
this.prependFormOrBodyParameters = false,
409364
this.pubAuthor,
410365
this.pubAuthorEmail,
@@ -425,7 +380,7 @@ class AdditionalProperties {
425380
allowUnicodeIdentifiers: map['allowUnicodeIdentifiers'] ?? false,
426381
ensureUniqueParams: map['ensureUniqueParams'] ?? true,
427382
useEnumExtension: map['useEnumExtension'] ?? true,
428-
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? true,
383+
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? false,
429384
prependFormOrBodyParameters:
430385
map['prependFormOrBodyParameters'] ?? false,
431386
pubAuthor: map['pubAuthor'],
@@ -532,7 +487,7 @@ class DioProperties extends AdditionalProperties {
532487
bool sortModelPropertiesByRequiredFlag = true,
533488
bool sortParamsByRequiredFlag = true,
534489
bool useEnumExtension = true,
535-
bool enumUnknownDefaultCase = true,
490+
bool enumUnknownDefaultCase = false,
536491
String? sourceFolder,
537492
Wrapper wrapper = Wrapper.none})
538493
: super(
@@ -609,7 +564,7 @@ class DioAltProperties extends AdditionalProperties {
609564
bool sortModelPropertiesByRequiredFlag = true,
610565
bool sortParamsByRequiredFlag = true,
611566
bool useEnumExtension = true,
612-
bool enumUnknownDefaultCase = true,
567+
bool enumUnknownDefaultCase = false,
613568
String? sourceFolder,
614569
Wrapper wrapper = Wrapper.none})
615570
: super(

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ void main() {
99
group('OpenApi', () {
1010
test('defaults', () {
1111
final props = Openapi(
12-
inputSpecFile: InputSpec.empty().path,
13-
inputSpec: InputSpec.empty(),
12+
inputSpec: InputSpec.json(),
1413
generatorName: Generator.dart,
1514
);
1615
expect(props.additionalProperties, isNull);
1716
expect(props.overwriteExistingFiles, isNull);
1817
expect(props.skipSpecValidation, false);
19-
expect(props.inputSpecFile, InputSpec.empty().path);
20-
expect(props.inputSpec!.path, InputSpec.empty().path);
18+
expect(props.inputSpec!.path, InputSpec.json().path);
2119
expect(props.templateDirectory, isNull);
2220
expect(props.generatorName, Generator.dart);
2321
expect(props.outputDirectory, isNull);
@@ -28,58 +26,44 @@ void main() {
2826
expect(props.apiPackage, isNull);
2927
expect(props.fetchDependencies, true);
3028
expect(props.runSourceGenOnOutput, true);
31-
expect(props.alwaysRun, false);
3229
expect(props.cachePath, isNull);
33-
expect(props.useNextGen, false);
3430
expect(props.projectPubspecPath, isNull);
3531
expect(props.debugLogging, isFalse);
3632
});
3733
group('NextGen', () {
3834
test('Sets cachePath', () {
3935
final api = Openapi(
40-
inputSpecFile: InputSpec.empty().path,
36+
inputSpec: InputSpec.json(),
4137
generatorName: Generator.dart,
4238
cachePath: 'somePath');
4339
expect(api.cachePath, 'somePath');
4440
});
45-
test('Sets useNextGenFlag', () {
46-
final api = Openapi(
47-
inputSpecFile: InputSpec.empty().path,
48-
generatorName: Generator.dart,
49-
useNextGen: true);
50-
expect(api.useNextGen, isTrue);
51-
});
5241
test('Sets projectPubspecPath', () {
5342
final api = Openapi(
54-
inputSpecFile: InputSpec.empty().path,
43+
inputSpec: InputSpec.json(),
5544
generatorName: Generator.dart,
5645
projectPubspecPath: 'test');
5746
expect(api.projectPubspecPath, 'test');
5847
});
5948
test('Set debug logging', () {
6049
final api = Openapi(
61-
inputSpecFile: InputSpec.empty().path,
62-
inputSpec: InputSpec.empty(),
50+
inputSpec: InputSpec.json(),
6351
generatorName: Generator.dart,
6452
debugLogging: true);
6553
expect(api.debugLogging, isTrue);
6654
});
6755
group('InputSpec', () {
6856
group('local spec', () {
6957
test('provides default yaml path', () {
70-
expect(InputSpec.empty().path, 'openapi.yaml');
71-
expect(InputSpec.empty().defaultYaml, isTrue);
72-
expect(InputSpec.empty().useYml, isFalse);
58+
expect(InputSpec.yaml().path, 'openapi.yaml');
59+
expect(InputSpec.yaml(shortExtension: true).path, 'openapi.yml');
7360
});
7461
test('provides default yml path', () {
75-
expect(InputSpec.emptyYml().path, 'openapi.yml');
76-
expect(InputSpec.emptyYml().defaultYaml, isTrue);
77-
expect(InputSpec.emptyYml().useYml, isTrue);
62+
expect(InputSpec.yaml(shortExtension: true).path, 'openapi.yml');
63+
expect(InputSpec.yaml(shortExtension: false).path, 'openapi.yaml');
7864
});
7965
test('provides default json path', () {
80-
expect(InputSpec.emptyJson().path, 'openapi.json');
81-
expect(InputSpec.emptyJson().defaultYaml, isFalse);
82-
expect(InputSpec.emptyJson().useYml, isFalse);
66+
expect(InputSpec.json().path, 'openapi.json');
8367
});
8468
test('uses path', () {
8569
expect(InputSpec(path: 'path').path, 'path');
-89.9 KB
Binary file not shown.

openapi-generator-cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>org.openapitools</groupId>
4949
<artifactId>openapi-generator-cli</artifactId>
50-
<version>6.6.0</version>
50+
<version>7.2.0</version>
5151
</dependency>
5252

5353
<dependency>

openapi-generator/example/example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
33
@Openapi(
44
additionalProperties:
55
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep...'),
6-
inputSpecFile: 'https://google.com',
6+
inputSpec: InputSpec(path: 'openapi-spec.yaml'),
77
generatorName: Generator.dio,
88
outputDirectory: 'api/petstore_api',
99
)
10-
class Example extends OpenapiGeneratorConfig {}
10+
class Example {}

0 commit comments

Comments
 (0)