Skip to content

Commit 51d3683

Browse files
committed
feat(cli): bumped official generator version to 7.2
feat(annotation): removed deprecated properties from annotation BREAKING CHANGE: removed various deprecated methods and properties such as inputSpecFile feat(generator): moved completely to newgen
1 parent fb4e8e8 commit 51d3683

23 files changed

+351
-518
lines changed

example/lib/main.dart

Lines changed: 3 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: : 2023-10-01T09:26:15.827402
22
import 'package:flutter/material.dart';
33
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
44

@@ -9,12 +9,11 @@ void main() {
99
@Openapi(
1010
additionalProperties:
1111
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
12-
inputSpecFile: 'openapi-spec.yaml',
13-
inputSpec: InputSpec(path: 'openapi-spec.yaml'),
12+
inputSpec:
13+
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
1414
typeMappings: {'Pet': 'ExamplePet'},
1515
generatorName: Generator.dio,
1616
runSourceGenOnOutput: true,
17-
useNextGen: true,
1817
outputDirectory: 'api/petstore_api',
1918
)
2019
class MyApp extends StatelessWidget {

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: 12 additions & 45 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-
@Deprecated('To be removed in the next major') 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
});
@@ -365,10 +329,13 @@ class AdditionalProperties {
365329
/// Allow the 'x-enum-values' extension for enums
366330
final bool? useEnumExtension;
367331

368-
/// 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',
369334
/// so that when the server sends an enum case that is not known by the client/spec,
370-
/// they can safely fallback to this case
371-
final bool? enumUnknownDefaultCase;
335+
/// they can safely fallback to this case.
336+
///
337+
/// Default: false
338+
final bool enumUnknownDefaultCase;
372339

373340
/// Flutter wrapper to use (none|flutterw|fvm)
374341
final Wrapper wrapper;
@@ -392,7 +359,7 @@ class AdditionalProperties {
392359
this.allowUnicodeIdentifiers = false,
393360
this.ensureUniqueParams = true,
394361
this.useEnumExtension = false,
395-
this.enumUnknownDefaultCase = true,
362+
this.enumUnknownDefaultCase = false,
396363
this.prependFormOrBodyParameters = false,
397364
this.pubAuthor,
398365
this.pubAuthorEmail,
@@ -413,7 +380,7 @@ class AdditionalProperties {
413380
allowUnicodeIdentifiers: map['allowUnicodeIdentifiers'] ?? false,
414381
ensureUniqueParams: map['ensureUniqueParams'] ?? true,
415382
useEnumExtension: map['useEnumExtension'] ?? true,
416-
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? true,
383+
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? false,
417384
prependFormOrBodyParameters:
418385
map['prependFormOrBodyParameters'] ?? false,
419386
pubAuthor: map['pubAuthor'],
@@ -520,7 +487,7 @@ class DioProperties extends AdditionalProperties {
520487
bool sortModelPropertiesByRequiredFlag = true,
521488
bool sortParamsByRequiredFlag = true,
522489
bool useEnumExtension = true,
523-
bool enumUnknownDefaultCase = true,
490+
bool enumUnknownDefaultCase = false,
524491
String? sourceFolder,
525492
Wrapper wrapper = Wrapper.none})
526493
: super(
@@ -597,7 +564,7 @@ class DioAltProperties extends AdditionalProperties {
597564
bool sortModelPropertiesByRequiredFlag = true,
598565
bool sortParamsByRequiredFlag = true,
599566
bool useEnumExtension = true,
600-
bool enumUnknownDefaultCase = true,
567+
bool enumUnknownDefaultCase = false,
601568
String? sourceFolder,
602569
Wrapper wrapper = Wrapper.none})
603570
: super(

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ void main() {
99
group('OpenApi', () {
1010
test('defaults', () {
1111
final props = Openapi(
12-
inputSpecFile: InputSpec.json().path,
1312
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.json().path);
2018
expect(props.inputSpec!.path, InputSpec.json().path);
2119
expect(props.templateDirectory, isNull);
2220
expect(props.generatorName, Generator.dart);
@@ -28,37 +26,27 @@ 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.json().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.json().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.json().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.json().path,
6250
inputSpec: InputSpec.json(),
6351
generatorName: Generator.dart,
6452
debugLogging: true);
-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 {}

openapi-generator/lib/src/extensions/type_methods.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ extension ReadProperty on ConstantReader {
8181
return defaultValue;
8282
}
8383

84+
var property = readPropertyOrNull<T>(name);
85+
if (property == null) {
86+
return defaultValue;
87+
}
88+
return property;
89+
}
90+
91+
T? readPropertyOrNull<T>(String name) {
92+
final v = peek(name);
93+
if (v == null) {
94+
return null;
95+
}
96+
8497
if (isA(v, InputSpec)) {
8598
final revived = v.revive();
8699

@@ -163,7 +176,7 @@ extension ReadProperty on ConstantReader {
163176
} else if (isA(v, Enum)) {
164177
return v.enumValue();
165178
} else {
166-
return defaultValue;
179+
return null;
167180
}
168181
}
169182
}

openapi-generator/lib/src/gen_on_spec_changes.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final _supportedRegexes = [jsonRegex, yamlRegex];
2929
/// WARNING: THIS DOESN'T VALIDATE THE SPECIFICATION CONTENT
3030
FutureOr<Map<String, dynamic>> loadSpec(
3131
{required InputSpec specConfig, bool isCached = false}) async {
32+
print('loadSpec - ' + specConfig.path);
3233
// If the spec file doesn't match any of the currently supported spec formats
3334
// reject the request.
3435
if (!_supportedRegexes

0 commit comments

Comments
 (0)