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..712cdce 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,10 @@ class Openapi { /// Include in depth logging output from run commands. final bool debugLogging; + /// Whether to disable caching the spec file. Defaults to `true` if the + /// [inputSpec] is not a [RemoteSpec]. + final bool disableCache; + const Openapi({ this.additionalProperties, this.skipSpecValidation = false, @@ -129,7 +133,8 @@ class Openapi { this.cachePath, this.projectPubspecPath, this.debugLogging = false, - }); + bool? disableCache, + }) : disableCache = disableCache ?? inputSpec is! RemoteSpec; } /// Provides the input spec file to be used. diff --git a/openapi-generator/lib/src/models/generator_arguments.dart b/openapi-generator/lib/src/models/generator_arguments.dart index 2cbcbba..3da2014 100644 --- a/openapi-generator/lib/src/models/generator_arguments.dart +++ b/openapi-generator/lib/src/models/generator_arguments.dart @@ -20,6 +20,10 @@ class GeneratorArguments { /// /// The default location is: .dart_tool/openapi-generator-cache.json final String cachePath; + + /// Informs the generator to disable the cache. + final bool disableCache; + final bool isDebug; /// Use a custom pubspec file when generating. @@ -112,7 +116,8 @@ 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()), + disableCache = annotations.readPropertyOrDefault('disableCache', false); /// 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..cf5827d 100755 --- a/openapi-generator/lib/src/openapi_generator_runner.dart +++ b/openapi-generator/lib/src/openapi_generator_runner.dart @@ -170,32 +170,41 @@ class OpenapiGenerator extends GeneratorForAnnotation { await runOpenApiJar(arguments: args); await fetchDependencies(baseCommand: baseCommand, args: args); await generateSources(baseCommand: baseCommand, args: args); - if (!args.hasLocalCache) { + if (args.disableCache) { logOutputMessage( log: log, communication: OutputMessage( - message: 'No local cache found. Creating one.', - level: Level.CONFIG, + message: 'Cache disabled. Skipping cache update.', ), ); } else { + if (!args.hasLocalCache) { + logOutputMessage( + log: log, + communication: OutputMessage( + message: 'No local cache found. Creating one.', + level: Level.CONFIG, + ), + ); + } else { + logOutputMessage( + log: log, + communication: OutputMessage( + message: 'Local cache found. Overwriting existing one.', + level: Level.CONFIG, + ), + ); + } + await cacheSpec( + outputLocation: args.cachePath, + spec: await loadSpec(specConfig: args.inputSpec)); logOutputMessage( log: log, communication: OutputMessage( - message: 'Local cache found. Overwriting existing one.', - level: Level.CONFIG, + message: 'Successfully cached spec changes.', ), ); } - await cacheSpec( - outputLocation: args.cachePath, - spec: await loadSpec(specConfig: args.inputSpec)); - logOutputMessage( - log: log, - communication: OutputMessage( - message: 'Successfully cached spec changes.', - ), - ); } } catch (e, st) { logOutputMessage(