Skip to content

Commit 43b8062

Browse files
committed
updated code
1 parent ed60f71 commit 43b8062

File tree

6 files changed

+110
-51
lines changed

6 files changed

+110
-51
lines changed

example/lib/main.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:openapi/';
32

4-
import '../petstore/api/lib/api.dart';
53

64
void main() => runApp(MyApp());
75

@@ -51,7 +49,6 @@ class _MyHomePageState extends State<MyHomePage> {
5149
int _counter = 0;
5250

5351
void _incrementCounter() {
54-
ApiClient().
5552
setState(() {
5653
// This call to setState tells the Flutter framework that something has
5754
// changed in this State, which causes it to rerun the build method below

example/lib/openAPiConfig.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ import 'package:flutter/material.dart';
22
import 'package:meta/meta.dart';
33
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
44

5-
@Openapi(inputSpecFile: 'spec/openapi-spec.yaml',generator: 'dart',outputDirectory: 'petstore/api')
5+
@Openapi(
6+
additionalProperties:
7+
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
8+
inputSpecFile: 'spec/openapi-spec.yaml',
9+
generatorName: 'dart-jaguar',
10+
outputDirectory: 'petstore/api')
611
class OpenapiGeneratorCo extends OpenapiGeneratorConfig {}

example/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ dependencies:
2121
sdk: flutter
2222
openapi_generator_annotations:
2323
path: ../openapi-generator-annotations
24+
petstore_api:
25+
path: petstore/api
2426

2527

2628
# The following adds the Cupertino Icons font to your application.

openapi-generator-annotations/lib/openapi_generator_annotations.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
library openapi_generator_annotations;
55

66
export 'src/openapi_generator_annotations_base.dart';
7-
8-
// TODO: Export any libraries intended for clients of this package.

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

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,92 @@ abstract class OpenapiGeneratorConfig {
1313
/// specifies if the existing files should be overwritten during the generation
1414
/// -s, --skip-overwrite
1515
bool overwriteExistingFiles;
16-
17-
/// Skips the default behavior of validating an input specification.
18-
/// --skip-validate-spec
19-
bool validateSpec;
2016
}
2117

2218
class Openapi {
2319
final String baseUrl;
24-
final Map<String, String> additionalProperties;
20+
21+
final AdditionalProperties additionalProperties;
2522
final String inputSpecFile;
26-
final String generator;
23+
24+
/// generator to use (see list command for list)
25+
/// -g, --generator-name
26+
final String generatorName;
27+
28+
/// where to write the generated files (current dir by default)
29+
/// -o, --output
2730
final String outputDirectory;
2831

32+
/// specifies if the existing files should be overwritten during the generation
33+
/// -s, --skip-overwrite
34+
final bool overwriteExistingFiles;
35+
36+
/// Skips the default behavior of validating an input specification.
37+
/// --skip-validate-spec
38+
final bool validateSpec;
39+
2940
const Openapi(
3041
{this.additionalProperties,
42+
this.overwriteExistingFiles,
43+
this.validateSpec = true,
3144
this.inputSpecFile,
32-
this.generator,
45+
this.generatorName,
3346
this.outputDirectory,
3447
this.baseUrl});
3548
}
49+
3650
class AdditionalProperties {
3751
/// toggles whether unicode identifiers are allowed in names or not, default is false
38-
bool allowUnicodeIdentifiers=false;
52+
final bool allowUnicodeIdentifiers;
53+
3954
/// Whether to ensure parameter names are unique in an operation (rename parameters that are not).
40-
bool ensureUniqueParams=true;
55+
final bool ensureUniqueParams;
56+
4157
/// Add form or body parameters to the beginning of the parameter list.
42-
bool prependFormOrBodyParameters = false;
58+
final bool prependFormOrBodyParameters;
59+
4360
/// Author name in generated pubspec
44-
String pubAuthor;
61+
final String pubAuthor;
62+
4563
/// Email address of the author in generated pubspec
46-
String pubAuthorEmail ;
64+
final String pubAuthorEmail;
65+
4766
/// Description in generated pubspec
48-
String pubDescription;
67+
final String pubDescription;
68+
4969
/// Homepage in generated pubspec
50-
String pubHomepage;
70+
final String pubHomepage;
71+
5172
/// Name in generated pubspec
52-
String pubName;
73+
final String pubName;
74+
5375
/// Version in generated pubspec
54-
String pubVersion;
76+
final String pubVersion;
77+
5578
/// Sort model properties to place required parameters before optional parameters.
56-
bool sortModelPropertiesByRequiredFlag=true;
57-
/// Sort method arguments to place required parameters before optional parameters.
58-
bool sortParamsByRequiredFlag = true;
59-
/// Source folder for generated code
60-
bool sourceFolder;
61-
// useEnumExtension Allow the 'x-enum-values' extension for enums null
79+
final bool sortModelPropertiesByRequiredFlag;
80+
81+
/// Sort method arguments to place required parameters before optional parameters.
82+
final bool sortParamsByRequiredFlag;
83+
84+
/// Source folder for generated code
85+
final bool sourceFolder;
86+
87+
const AdditionalProperties(
88+
{this.allowUnicodeIdentifiers = false,
89+
this.ensureUniqueParams = true,
90+
this.prependFormOrBodyParameters = false,
91+
this.pubAuthor,
92+
this.pubAuthorEmail,
93+
this.pubDescription,
94+
this.pubHomepage,
95+
this.pubName,
96+
this.pubVersion,
97+
this.sortModelPropertiesByRequiredFlag = true,
98+
this.sortParamsByRequiredFlag = true,
99+
this.sourceFolder});
100+
101+
String _append(String base, String str) {
102+
return '$base,$str';
103+
}
62104
}

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
3030
todo: '`$friendlyName` need to extends the [OpenapiConfig] class.',
3131
);
3232
}
33-
String separator='?*?';
34-
String command = 'generate';
35-
String inputFile = annotation.read('inputSpecFile').stringValue ?? '';
33+
//print('===> ${classElement.source.}');
34+
var separator = '?*?';
35+
var command = 'generate';
36+
var inputFile = annotation.read('inputSpecFile')?.stringValue ?? '';
3637
if (inputFile.isNotEmpty) {
3738
if (path.isAbsolute(inputFile)) {
3839
throw InvalidGenerationSourceError(
@@ -48,7 +49,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
4849
command = '$command$separator-i$separator${inputFile}';
4950
}
5051

51-
var generator = annotation.read('generator').stringValue ?? 'dart';
52+
var generator = annotation.read('generatorName')?.stringValue ?? 'dart';
5253
command = '$command$separator-g$separator$generator';
5354

5455
var outputDirectory = annotation.read('outputDirectory').stringValue ?? '';
@@ -60,20 +61,30 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
6061
}
6162
// outputDirectory = path.absolute( Directory.current.path,outputDirectory);
6263
if (!await FileSystemEntity.isDirectory(outputDirectory)) {
63-
new Directory(outputDirectory).create(recursive: true)
64-
// The created directory is returned as a Future.
64+
await Directory(outputDirectory).create(recursive: true)
65+
// The created directory is returned as a Future.
6566
.then((Directory directory) {
6667
print(directory.path);
6768
});
6869
}
6970
command = '$command$separator-o$separator${outputDirectory}';
7071
}
71-
var additionalProperties = annotation.read('additionalProperties').mapValue;
72-
if (additionalProperties != null) {
72+
var additionalProperties = '';
73+
annotation
74+
.read('additionalProperties')
75+
.revive()
76+
.namedArguments
77+
.entries
78+
.forEach((entry) => {
79+
additionalProperties =
80+
'$additionalProperties${additionalProperties.isEmpty ? '' : ','}${entry.key}=${entry.value.toStringValue()}'
81+
});
82+
print(additionalProperties);
83+
if (additionalProperties != null && additionalProperties.isNotEmpty) {
7384
command =
74-
'$command$separator--additional-properties=${additionalProperties.entries.map((entry) => '${entry.key.toStringValue()}=${entry.value.toStringValue()}').join(',')}';
85+
'$command$separator--additional-properties=${additionalProperties}';
7586
}
76-
command='$command$separator-Dcolor';
87+
command = '$command$separator-Dcolor';
7788

7889
print(command);
7990
var binPath = await Isolate.resolvePackageUri(
@@ -82,9 +93,9 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
8293
// var command = '${JAVA_OPTS} -jar "" ${arguments.join(' ')}';
8394

8495
print(
85-
"${FileSystemEntity.isFileSync(binPath.toFilePath(windows: Platform.isWindows))} exists ===>");
96+
'${FileSystemEntity.isFileSync(binPath.toFilePath(windows: Platform.isWindows))} exists ===>');
8697

87-
Process.run('java', [
98+
await Process.run('java', [
8899
'-jar',
89100
"${"${binPath.path}"}",
90101
...command.split(separator).toList(),
@@ -93,17 +104,6 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
93104
print(pr.stdout);
94105
print(pr.stderr);
95106
});
96-
// String arguments=command.split(" ")
97-
// var binPath = 'openapi-generator.jar';
98-
// var JAVA_OPTS = Platform.environment['JAVA_OPTS'] ?? '';
99-
// var consoleCommand = '${JAVA_OPTS} -jar "" ${arguments.join(' ')}';
100-
// Process.run('java', ["-jar", "${"${binPath}"}", ...arguments],
101-
// workingDirectory: 'bin')
102-
// .then((ProcessResult pr) {
103-
// print(pr.exitCode);
104-
// print(pr.stdout);
105-
// print(pr.stderr);
106-
// });
107107
return '';
108108
}
109109

@@ -115,4 +115,19 @@ class OpenapiGenerator extends GeneratorForAnnotation<Openapi> {
115115
String getMapAsString(Map<dynamic, dynamic> data) {
116116
return data.entries.map((entry) => '${entry.key}=${entry.value}').join(',');
117117
}
118+
119+
AdditionalProperties _reviveAdditionalProperties(ConstantReader read) {
120+
var reviveable = read.revive();
121+
return AdditionalProperties(
122+
allowUnicodeIdentifiers:
123+
reviveable.namedArguments['allowUnicodeIdentifiers'].toBoolValue());
124+
}
118125
}
126+
127+
//abstract class RevivableInstance implements ConstantReader {
128+
// Uri get uri;
129+
// String get name;
130+
// String get constructor;
131+
// List<ConstantReader> get positionalArguments;
132+
// Map<String, ConstantReader> get namedArguments;
133+
//}

0 commit comments

Comments
 (0)