Skip to content

Commit a99d277

Browse files
committed
moved things around
1 parent c63324a commit a99d277

File tree

9 files changed

+52
-28
lines changed

9 files changed

+52
-28
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: petstore_api
22
version: 1.0.0
33
description: OpenAPI API client
4+
authors:
5+
- Johnny depp <author@homepage>
6+
homepage: homepage
47
environment:
5-
sdk: ">=2.0.0 <3.0.0"
8+
sdk: '>=2.0.0 <3.0.0'
69
dependencies:
7-
jaguar_retrofit: ^2.8.8
8-
jaguar_serializer: ^2.2.12
10+
http: '>=0.12.0 <0.13.0'
911
dev_dependencies:
10-
jaguar_retrofit_gen: ^2.8.10
11-
jaguar_serializer_cli: ^2.2.8
12-
build_runner: ^1.6.5
12+
test: ^1.3.0

example/lib/openapi_config.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
22

33
@Openapi(
44
additionalProperties:
5-
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny depp'),
5+
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny depp'),
66
inputSpecFile: 'spec/openapi-spec.yaml',
7-
generatorName: 'dart-jaguar',
7+
generatorName: 'dart',
8+
alwaysRun: true,
89
outputDirectory: 'api/petstore_api')
910
class OpenapiConfig extends OpenapiGeneratorConfig {
1011
}

example/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ environment:
1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
openapi_generator_annotations: ^1.0.2
22+
openapi_generator_annotations: ^1.0.5
2323
petstore_api:
2424
path: api/petstore_api
2525
provider: ^4.0.4
@@ -33,7 +33,8 @@ dev_dependencies:
3333
flutter_test:
3434
sdk: flutter
3535
build_runner: ^1.7.4
36-
openapi_generator: ^0.1.2
36+
openapi_generator:
37+
path: ../openapi-generator/
3738

3839

3940
# For information on the generic Dart part of this file, see the

openapi-generator-annotations/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.0.6
1+
## 1.0.7
22

33
- Added support for specifying template directory using -t
44

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Openapi {
1616
/// folder containing the template files
1717
///
1818
/// -t
19-
final String templateDir;
19+
final String templateDirectory;
2020

2121
/// Generator to use (dart|dart-jaguar|dart-dio)
2222
///
@@ -47,7 +47,7 @@ class Openapi {
4747
this.overwriteExistingFiles,
4848
this.skipValidateSpec = false,
4949
this.inputSpecFile,
50-
this.templateDir,
50+
this.templateDirectory,
5151
this.generatorName,
5252
this.outputDirectory,
5353
this.alwaysRun = false});

openapi-generator-annotations/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: openapi_generator_annotations
22
description: Annotation package for openapi_generator https://pub.dev/packages/openapi_generator.
3-
version: 1.0.6
3+
version: 1.0.7
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66

openapi-generator/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## 1.0.6
1+
## 1.0.7
22

3-
- added support for -t (templateDir)
3+
- added support for -t (templateDirectory)
44
- minor bug fix
55

66
## 1.0.5

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
3333

3434
var separator = '?*?';
3535
var command = 'generate';
36-
var inputFile = annotation.read('inputSpecFile')?.stringValue ?? '';
36+
37+
var inputFile = _readFieldValueAsString(annotation, 'inputSpecFile', '');
3738
if (inputFile.isNotEmpty) {
3839
command = '$command$separator-i$separator${inputFile}';
3940
}
4041

41-
var templateDir = annotation.read('templateDir')?.stringValue ?? '';
42+
var templateDir =
43+
_readFieldValueAsString(annotation, 'templateDirectory', '');
4244
if (templateDir.isNotEmpty) {
4345
command = '$command$separator-t$separator${templateDir}';
4446
}
4547

46-
var generator = annotation.read('generatorName')?.stringValue ?? 'dart';
48+
var generator =
49+
_readFieldValueAsString(annotation, 'generatorName', 'dart');
4750
if (generator != 'dart' &&
4851
generator != 'dart-dio' &&
4952
generator != 'dart-jaguar') {
@@ -53,7 +56,8 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
5356
}
5457
command = '$command$separator-g$separator$generator';
5558

56-
var outputDirectory = annotation.read('outputDirectory').stringValue ?? '';
59+
var outputDirectory =
60+
_readFieldValueAsString(annotation, 'outputDirectory', '');
5761
if (outputDirectory.isNotEmpty) {
5862
if (path.isAbsolute(outputDirectory)) {
5963
throw InvalidGenerationSourceError(
@@ -66,7 +70,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
6670
// The created directory is returned as a Future.
6771
.then((Directory directory) {});
6872
} else {
69-
var alwaysRun = annotation.read('alwaysRun')?.boolValue ?? false;
73+
var alwaysRun = _readFieldValueAsBool(annotation, 'alwaysRun', false);
7074
var filePath = path.join(outputDirectory, 'lib/api.dart');
7175
if (!alwaysRun && await File(filePath).exists()) {
7276
print(
@@ -89,16 +93,20 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
8993
.revive()
9094
.namedArguments
9195
.entries
92-
.forEach((entry) => {
93-
additionalProperties =
94-
'$additionalProperties${additionalProperties.isEmpty ? '' : ','}${entry.key}=${entry.value.toStringValue()}'
95-
});
96+
.forEach((entry) =>
97+
{
98+
additionalProperties =
99+
'$additionalProperties${additionalProperties.isEmpty ? '' : ','}${entry
100+
.key}=${entry.value.toStringValue()}'
101+
});
96102

97103
if (additionalProperties != null && additionalProperties.isNotEmpty) {
98104
command =
99-
'$command$separator--additional-properties=${additionalProperties}';
105+
'$command$separator--additional-properties=${additionalProperties}';
100106
}
101107

108+
print('openapi-generator ===> ${command.replaceAll(separator, ' ')}');
109+
102110
var binPath = await Isolate.resolvePackageUri(
103111
Uri.parse('package:openapi_generator_cli/openapi-generator.jar'));
104112

@@ -151,6 +159,20 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
151159
String getMapAsString(Map<dynamic, dynamic> data) {
152160
return data.entries.map((entry) => '${entry.key}=${entry.value}').join(',');
153161
}
162+
163+
String _readFieldValueAsString(ConstantReader annotation, String fieldName,
164+
[String defaultValue]) {
165+
var reader = annotation.read(fieldName);
166+
167+
return reader.isNull ? defaultValue : reader.stringValue ?? defaultValue;
168+
}
169+
170+
bool _readFieldValueAsBool(ConstantReader annotation, String fieldName,
171+
[bool defaultValue]) {
172+
var reader = annotation.read(fieldName);
173+
174+
return reader.isNull ? defaultValue : reader.boolValue ?? defaultValue;
175+
}
154176
}
155177

156178
//abstract class RevivableInstance implements ConstantReader {

openapi-generator/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: openapi_generator
22
description: Generator for openapi client sdk inspired by the npm impplementation of openapi-generator-cli.
3-
version: 1.0.6
3+
version: 1.0.7
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66
environment:
@@ -11,7 +11,7 @@ dependencies:
1111
source_gen: ^0.9.0
1212
path: ^1.6.4
1313
cli_util: ^0.1.3+2
14-
openapi_generator_annotations: ^1.0.3
14+
openapi_generator_annotations: ^1.0.7
1515
analyzer: ^0.39.4
1616
openapi_generator_cli: ^1.0.5
1717

0 commit comments

Comments
 (0)