diff --git a/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart b/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart index d7c73ac..866bf55 100644 --- a/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart +++ b/openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart @@ -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, @@ -129,6 +132,7 @@ class Openapi { this.cachePath, this.projectPubspecPath, this.debugLogging = false, + this.updateAnnotatedFileTimestamp = true, }); } diff --git a/openapi-generator/lib/src/models/generator_arguments.dart b/openapi-generator/lib/src/models/generator_arguments.dart index 2cbcbba..2c26da8 100644 --- a/openapi-generator/lib/src/models/generator_arguments.dart +++ b/openapi-generator/lib/src/models/generator_arguments.dart @@ -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 = @@ -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 diff --git a/openapi-generator/lib/src/openapi_generator_runner.dart b/openapi-generator/lib/src/openapi_generator_runner.dart index c92a140..a4f72ea 100755 --- a/openapi-generator/lib/src/openapi_generator_runner.dart +++ b/openapi-generator/lib/src/openapi_generator_runner.dart @@ -220,24 +220,27 @@ class OpenapiGenerator extends GeneratorForAnnotation { ), ), ); - 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 ''; }