Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Openapi {
/// -o, --output
final String? outputDirectory;

/// Defines whether the output directory should be cleaned up before generating the output.
///
/// e.g [''], ['lib/src']
final List<dynamic>? cleanSubOutputDirectory;

/// Skips the default behavior of validating an input specification.
///
/// --skip-validate-spec
Expand Down Expand Up @@ -118,6 +123,7 @@ class Openapi {
this.templateDirectory,
required this.generatorName,
this.outputDirectory,
this.cleanSubOutputDirectory,
this.typeMappings,
this.importMappings,
this.reservedWordsMappings,
Expand Down
2 changes: 1 addition & 1 deletion openapi-generator/lib/src/extensions/type_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension ReadProperty on ConstantReader {
} else if (isA(v, Set)) {
return v.setValue.map(convertToPropertyValue) as T;
} else if (isA(v, List)) {
return v.listValue.map(convertToPropertyValue) as T;
return v.listValue.map(convertToPropertyValue).toList() as T;
} else if (isA(v, Enum)) {
return v.enumValue();
} else {
Expand Down
5 changes: 5 additions & 0 deletions openapi-generator/lib/src/models/generator_arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class GeneratorArguments {
/// Default: Directory.current.path
final String? outputDirectory;

/// Defines whether the output directory should be cleaned up before generating the output.
final List<dynamic>? cleanSubOutputDirectory;

/// Informs the generator to run source gen on the output.
///
/// Default: true
Expand Down Expand Up @@ -105,6 +108,8 @@ class GeneratorArguments {
shouldFetchDependencies =
annotations.readPropertyOrDefault('fetchDependencies', true),
outputDirectory = annotations.readPropertyOrNull('outputDirectory'),
cleanSubOutputDirectory =
annotations.readPropertyOrNull('cleanSubOutputDirectory'),
cachePath =
annotations.readPropertyOrDefault('cachePath', defaultCachedPath),
pubspecPath = annotations.readPropertyOrDefault<String>(
Expand Down
27 changes: 27 additions & 0 deletions openapi-generator/lib/src/openapi_generator_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
),
);

if (arguments.cleanSubOutputDirectory != null) {
arguments.cleanSubOutputDirectory?.forEach((directory) {
final childDirectory =
Directory('${arguments.outputDirectory}/${directory.toString()}');
try {
final outputDirectory = Directory('${arguments.outputDirectory}')
.resolveSymbolicLinksSync();
// Make sure is sub directory, avoid ../../
if (childDirectory
.resolveSymbolicLinksSync()
.startsWith(outputDirectory)) {
childDirectory.delete(recursive: true);
}
} catch (e, st) {
logOutputMessage(
log: log,
communication: OutputMessage(
message: 'Output directory already empty',
additionalContext: e,
stackTrace: st,
level: Level.WARNING,
),
);
}
});
}

var binPath = (await Isolate.resolvePackageUri(
Uri.parse('package:openapi_generator_cli/openapi-generator.jar')))!
.toFilePath(windows: Platform.isWindows);
Expand Down
Loading