Skip to content

Commit

Permalink
Add option to disable annotated file updates (gibahjoe#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Apr 9, 2024
1 parent 2eab4ab commit 1c0ea8c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class Openapi {
/// Include in depth logging output from run commands.
final bool debugLogging;

/// Whether to disable updating the timestamp in the annotated file.
final bool updateAnnotatedFileTimestamp;

const Openapi({
this.additionalProperties,
this.skipSpecValidation = false,
Expand All @@ -129,6 +132,7 @@ class Openapi {
this.cachePath,
this.projectPubspecPath,
this.debugLogging = false,
this.updateAnnotatedFileTimestamp = true,
});
}

Expand Down
7 changes: 6 additions & 1 deletion openapi-generator/lib/src/models/generator_arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class GeneratorArguments {
/// Customizes the way inline schema are handled.
final InlineSchemaOptions? inlineSchemaOptions;

/// Whether to update the timestamp in the annotated file
final bool updateAnnotatedFileTimestamp;

GeneratorArguments({required src_gen.ConstantReader annotations})
: templateDirectory = annotations.readPropertyOrNull('templateDirectory'),
generator =
Expand Down Expand Up @@ -112,7 +115,9 @@ class GeneratorArguments {
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml'),
isDebug = annotations.readPropertyOrDefault('debugLogging', false),
inputSpec =
annotations.readPropertyOrDefault('inputSpec', InputSpec.json());
annotations.readPropertyOrDefault('inputSpec', InputSpec.json()),
updateAnnotatedFileTimestamp = annotations.readPropertyOrDefault(
'updateAnnotatedFileTimestamp', true);

/// The stringified name of the [Generator].
String get generatorName => generator == Generator.dart
Expand Down
35 changes: 19 additions & 16 deletions openapi-generator/lib/src/openapi_generator_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,27 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
),
),
);
await updateAnnotatedFile(annotatedPath: annotatedPath).then(
(_) => logOutputMessage(
log: log,
communication: OutputMessage(
message: 'Successfully updated annotated file.',
level: Level.CONFIG,

if (args.updateAnnotatedFileTimestamp) {
await updateAnnotatedFile(annotatedPath: annotatedPath).then(
(_) => logOutputMessage(
log: log,
communication: OutputMessage(
message: 'Successfully updated annotated file.',
level: Level.CONFIG,
),
),
),
onError: (e, st) => logOutputMessage(
log: log,
communication: OutputMessage(
message: 'Failed to update annotated class file.',
level: Level.WARNING,
additionalContext: e,
stackTrace: st,
onError: (e, st) => logOutputMessage(
log: log,
communication: OutputMessage(
message: 'Failed to update annotated class file.',
level: Level.WARNING,
additionalContext: e,
stackTrace: st,
),
),
),
);
);
}
}
return '';
}
Expand Down

0 comments on commit 1c0ea8c

Please sign in to comment.