Skip to content

Commit

Permalink
feat(cli): bumped official generator version to 7.2
Browse files Browse the repository at this point in the history
feat(annotation): removed deprecated properties from annotation

BREAKING CHANGE: removed various deprecated methods and properties such as inputSpecFile
feat(generator): moved completely to newgen
  • Loading branch information
gibahjoe committed Jan 16, 2024
1 parent fb4e8e8 commit 51d3683
Show file tree
Hide file tree
Showing 23 changed files with 351 additions and 518 deletions.
7 changes: 3 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Openapi Generator last run: : 2023-08-20T13:11:18.157121
// Openapi Generator last run: : 2023-10-01T09:26:15.827402
import 'package:flutter/material.dart';
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

Expand All @@ -9,12 +9,11 @@ void main() {
@Openapi(
additionalProperties:
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
inputSpecFile: 'openapi-spec.yaml',
inputSpec: InputSpec(path: 'openapi-spec.yaml'),
inputSpec:
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
typeMappings: {'Pet': 'ExamplePet'},
generatorName: Generator.dio,
runSourceGenOnOutput: true,
useNextGen: true,
outputDirectory: 'api/petstore_api',
)
class MyApp extends StatelessWidget {
Expand Down
2 changes: 1 addition & 1 deletion openapi-generator-annotations/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
@Openapi(
additionalProperties:
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
inputSpecFile: 'example/openapi-spec.yaml',
inputSpec: InputSpec(path: 'example/openapi-spec.yaml'),
generatorName: Generator.dio,
outputDirectory: 'api/petstore_api',
// useNextGen: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';

/// Config base class
/// Your annotated class must extend this config class
@Deprecated(
'You do not need to extend this anymore (See example). This class would be removed in the next major release.')
abstract class OpenapiGeneratorConfig {}

class Openapi {
/// Additional properties to pass to the compiler (CSV)
///
Expand All @@ -26,12 +20,6 @@ class Openapi {
/// --api-package
final String? apiPackage;

/// relative path or url to spec file
///
/// -i
@Deprecated('To be removed in the next major')
final String inputSpecFile;

/// Provides the access information to the input spec file.
///
/// For use with useNextGen.
Expand All @@ -43,7 +31,7 @@ class Openapi {
/// to be applied to the fetch request when the spec file is in a remote
/// location. There is also special handling for when the spec file lives within
/// AWS.
final InputSpec? inputSpec;
final InputSpec inputSpec;

/// folder containing the template files
///
Expand Down Expand Up @@ -80,12 +68,6 @@ class Openapi {
/// --reserved-words-mappings
final Map<String, String>? reservedWordsMappings;

/// Tells openapi-generator to always run during the build process
/// if set to false (the default), openapi-generator will skip processing if the [outputDirectory] already exists
@Deprecated(
'The generator will always run to determine if there are changes made on the input spec file')
final bool? alwaysRun;

/// if set to true, flutter pub get will be run on the [outputDirectory] after the code has been generated.
/// Defaults to true for backwards compatibility
final bool? fetchDependencies;
Expand Down Expand Up @@ -122,21 +104,6 @@ class Openapi {
/// e.g {'inline_object_2': 'SomethingMapped'}
final Map<String, String>? inlineSchemaNameMappings;

/// Use the next generation of the generator.
///
/// This annotation informs the generator to use the new generator pathway.
/// Enabling this option allows for incremental changes to the [inputSpecFile]
/// to be generated even though the annotation was unchanged.
///
/// Due to some limitations with build_runner and it only running when the
/// asset graph has changed, a generated line get injected at the beginning of
/// the file at the end of each run.
///
/// This will become the default behaviour in the next Major version (v5).
///
/// Default: false
final bool useNextGen;

/// The path where to store the cached copy of the specification.
///
/// For use with [useNextGen].
Expand All @@ -152,8 +119,7 @@ class Openapi {
this.additionalProperties,
this.overwriteExistingFiles,
this.skipSpecValidation = false,
@Deprecated('To be removed in the next major') required this.inputSpecFile,
this.inputSpec,
required this.inputSpec,
this.templateDirectory,
required this.generatorName,
this.outputDirectory,
Expand All @@ -165,9 +131,7 @@ class Openapi {
this.apiPackage,
this.fetchDependencies = true,
this.runSourceGenOnOutput = true,
this.alwaysRun = false,
this.cachePath,
this.useNextGen = false,
this.projectPubspecPath,
this.debugLogging = false,
});
Expand Down Expand Up @@ -365,10 +329,13 @@ class AdditionalProperties {
/// Allow the 'x-enum-values' extension for enums
final bool? useEnumExtension;

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

/// Flutter wrapper to use (none|flutterw|fvm)
final Wrapper wrapper;
Expand All @@ -392,7 +359,7 @@ class AdditionalProperties {
this.allowUnicodeIdentifiers = false,
this.ensureUniqueParams = true,
this.useEnumExtension = false,
this.enumUnknownDefaultCase = true,
this.enumUnknownDefaultCase = false,
this.prependFormOrBodyParameters = false,
this.pubAuthor,
this.pubAuthorEmail,
Expand All @@ -413,7 +380,7 @@ class AdditionalProperties {
allowUnicodeIdentifiers: map['allowUnicodeIdentifiers'] ?? false,
ensureUniqueParams: map['ensureUniqueParams'] ?? true,
useEnumExtension: map['useEnumExtension'] ?? true,
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? true,
enumUnknownDefaultCase: map['enumUnknownDefaultCase'] ?? false,
prependFormOrBodyParameters:
map['prependFormOrBodyParameters'] ?? false,
pubAuthor: map['pubAuthor'],
Expand Down Expand Up @@ -520,7 +487,7 @@ class DioProperties extends AdditionalProperties {
bool sortModelPropertiesByRequiredFlag = true,
bool sortParamsByRequiredFlag = true,
bool useEnumExtension = true,
bool enumUnknownDefaultCase = true,
bool enumUnknownDefaultCase = false,
String? sourceFolder,
Wrapper wrapper = Wrapper.none})
: super(
Expand Down Expand Up @@ -597,7 +564,7 @@ class DioAltProperties extends AdditionalProperties {
bool sortModelPropertiesByRequiredFlag = true,
bool sortParamsByRequiredFlag = true,
bool useEnumExtension = true,
bool enumUnknownDefaultCase = true,
bool enumUnknownDefaultCase = false,
String? sourceFolder,
Wrapper wrapper = Wrapper.none})
: super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ void main() {
group('OpenApi', () {
test('defaults', () {
final props = Openapi(
inputSpecFile: InputSpec.json().path,
inputSpec: InputSpec.json(),
generatorName: Generator.dart,
);
expect(props.additionalProperties, isNull);
expect(props.overwriteExistingFiles, isNull);
expect(props.skipSpecValidation, false);
expect(props.inputSpecFile, InputSpec.json().path);
expect(props.inputSpec!.path, InputSpec.json().path);
expect(props.templateDirectory, isNull);
expect(props.generatorName, Generator.dart);
Expand All @@ -28,37 +26,27 @@ void main() {
expect(props.apiPackage, isNull);
expect(props.fetchDependencies, true);
expect(props.runSourceGenOnOutput, true);
expect(props.alwaysRun, false);
expect(props.cachePath, isNull);
expect(props.useNextGen, false);
expect(props.projectPubspecPath, isNull);
expect(props.debugLogging, isFalse);
});
group('NextGen', () {
test('Sets cachePath', () {
final api = Openapi(
inputSpecFile: InputSpec.json().path,
inputSpec: InputSpec.json(),
generatorName: Generator.dart,
cachePath: 'somePath');
expect(api.cachePath, 'somePath');
});
test('Sets useNextGenFlag', () {
final api = Openapi(
inputSpecFile: InputSpec.json().path,
generatorName: Generator.dart,
useNextGen: true);
expect(api.useNextGen, isTrue);
});
test('Sets projectPubspecPath', () {
final api = Openapi(
inputSpecFile: InputSpec.json().path,
inputSpec: InputSpec.json(),
generatorName: Generator.dart,
projectPubspecPath: 'test');
expect(api.projectPubspecPath, 'test');
});
test('Set debug logging', () {
final api = Openapi(
inputSpecFile: InputSpec.json().path,
inputSpec: InputSpec.json(),
generatorName: Generator.dart,
debugLogging: true);
Expand Down
Binary file modified openapi-generator-cli/lib/openapi-generator.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-cli</artifactId>
<version>6.6.0</version>
<version>7.2.0</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions openapi-generator/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
@Openapi(
additionalProperties:
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep...'),
inputSpecFile: 'https://google.com',
inputSpec: InputSpec(path: 'openapi-spec.yaml'),
generatorName: Generator.dio,
outputDirectory: 'api/petstore_api',
)
class Example extends OpenapiGeneratorConfig {}
class Example {}
15 changes: 14 additions & 1 deletion openapi-generator/lib/src/extensions/type_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ extension ReadProperty on ConstantReader {
return defaultValue;
}

var property = readPropertyOrNull<T>(name);
if (property == null) {
return defaultValue;
}
return property;
}

T? readPropertyOrNull<T>(String name) {
final v = peek(name);
if (v == null) {
return null;
}

if (isA(v, InputSpec)) {
final revived = v.revive();

Expand Down Expand Up @@ -163,7 +176,7 @@ extension ReadProperty on ConstantReader {
} else if (isA(v, Enum)) {
return v.enumValue();
} else {
return defaultValue;
return null;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions openapi-generator/lib/src/gen_on_spec_changes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final _supportedRegexes = [jsonRegex, yamlRegex];
/// WARNING: THIS DOESN'T VALIDATE THE SPECIFICATION CONTENT
FutureOr<Map<String, dynamic>> loadSpec(
{required InputSpec specConfig, bool isCached = false}) async {
print('loadSpec - ' + specConfig.path);
// If the spec file doesn't match any of the currently supported spec formats
// reject the request.
if (!_supportedRegexes
Expand Down
Loading

0 comments on commit 51d3683

Please sign in to comment.