Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable annotated file updates #143

Closed
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 @@ -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
Loading