Skip to content

Commit 4c5d1fd

Browse files
authored
Merge pull request #29 from bartektartanus/master
Option to use flutter wrapper - fvm or flutterw
2 parents 78df61d + cec0fef commit 4c5d1fd

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class AdditionalProperties {
119119
/// Allow the 'x-enum-values' extension for enums
120120
final bool useEnumExtension;
121121

122+
/// Flutter wrapper to use (none|flutterw|fvm)
123+
final Wrapper wrapper;
124+
122125
const AdditionalProperties(
123126
{this.allowUnicodeIdentifiers = false,
124127
this.ensureUniqueParams = true,
@@ -132,7 +135,8 @@ class AdditionalProperties {
132135
this.pubVersion,
133136
this.sortModelPropertiesByRequiredFlag = true,
134137
this.sortParamsByRequiredFlag = true,
135-
this.sourceFolder});
138+
this.sourceFolder,
139+
this.wrapper = Wrapper.none});
136140
}
137141

138142
class JaguarProperties extends AdditionalProperties {
@@ -220,3 +224,4 @@ enum SerializationFormat { JSON, PROTO }
220224

221225
/// The name of the generator to use
222226
enum Generator { DART, DART_DIO, DART2_API, DART_JAGUAR }
227+
enum Wrapper {fvm, flutterw, none}

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: 2.0.0
3+
version: 2.1.0
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66

openapi-generator-cli/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: openapi_generator_cli
22
description: A dart wrapper around openapi-generator inspired by the node implementation.
3-
version: 2.0.0
3+
version: 2.1.0
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66
environment:

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
106106
}
107107

108108
if (exitCode == 0) {
109-
var installOutput = await Process.run('flutter', ['pub', 'get'],
109+
final command = _getCommandWithWrapper('flutter', ['pub', 'get'], annotation);
110+
var installOutput = await Process.run(command.executable, command.arguments,
110111
runInShell: Platform.isWindows,
111112
workingDirectory: '$outputDirectory');
112113

@@ -133,7 +134,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
133134
case annots.Generator.DART_DIO:
134135
case annots.Generator.DART_JAGUAR:
135136
try {
136-
var runnerOutput = await runSourceGen(outputDirectory);
137+
var runnerOutput = await runSourceGen(annotation, outputDirectory);
137138
print(
138139
'OpenapiGenerator :: build runner exited with code ${runnerOutput.exitCode} ::');
139140
} catch (e) {
@@ -150,11 +151,12 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
150151
return '';
151152
}
152153

153-
Future<ProcessResult> runSourceGen(String outputDirectory) async {
154+
Future<ProcessResult> runSourceGen(ConstantReader annotation, String outputDirectory) async {
154155
print('OpenapiGenerator :: running source code generation ::');
155156
var c = 'pub run build_runner build --delete-conflicting-outputs';
157+
final command = _getCommandWithWrapper('flutter', c.split(' ').toList(), annotation);
156158
ProcessResult runnerOutput;
157-
runnerOutput = await Process.run('flutter', c.split(' ').toList(),
159+
runnerOutput = await Process.run(command.executable, command.arguments,
158160
runInShell: Platform.isWindows, workingDirectory: '$outputDirectory');
159161
print(runnerOutput.stderr);
160162
return runnerOutput;
@@ -259,6 +261,19 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
259261
.join(',');
260262
}
261263

264+
Command _getCommandWithWrapper(String command, List<String> arguments, ConstantReader annotation){
265+
final wrapper = annotation.read('additionalProperties')?.read('wrapper')?.enumValue<annots.Wrapper>() ?? annots.Wrapper.none;
266+
switch(wrapper){
267+
case annots.Wrapper.flutterw:
268+
return Command('./flutterw', arguments);
269+
case annots.Wrapper.fvm:
270+
return Command('fvm', [command, ...arguments]);
271+
case annots.Wrapper.none:
272+
default:
273+
return Command(command, arguments);
274+
}
275+
}
276+
262277
String _readFieldValueAsString(ConstantReader annotation, String fieldName,
263278
[String defaultValue]) {
264279
var reader = annotation.read(fieldName);
@@ -280,3 +295,10 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
280295
return reader.isNull ? defaultValue : reader.boolValue ?? defaultValue;
281296
}
282297
}
298+
299+
class Command {
300+
final String executable;
301+
final List<String> arguments;
302+
303+
Command(this.executable, this.arguments);
304+
}

openapi-generator/pubspec.yaml

Lines changed: 3 additions & 3 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: 2.0.0
3+
version: 2.1.0
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66
environment:
@@ -10,9 +10,9 @@ dependencies:
1010
build: '>=1.3.0 <=1.10.3'
1111
source_gen: ^0.9.10+1
1212
path: ^1.7.0
13-
openapi_generator_annotations: ^2.0.0
13+
openapi_generator_annotations: ^2.1.0
1414
analyzer: '>=0.40.0 <=0.41.1'
15-
openapi_generator_cli: ^2.0.0
15+
openapi_generator_cli: ^2.1.0
1616

1717
dev_dependencies:
1818
pedantic: ^1.9.2

0 commit comments

Comments
 (0)