Skip to content

Commit 4d5daaf

Browse files
committed
Added option to disable caching
1 parent 2eab4ab commit 4d5daaf

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class Openapi {
111111
/// Include in depth logging output from run commands.
112112
final bool debugLogging;
113113

114+
/// Whether to disable caching the spec file. Defaults to `true` if the
115+
/// [inputSpec] is not a [RemoteSpec].
116+
final bool disableCache;
117+
114118
const Openapi({
115119
this.additionalProperties,
116120
this.skipSpecValidation = false,
@@ -129,7 +133,8 @@ class Openapi {
129133
this.cachePath,
130134
this.projectPubspecPath,
131135
this.debugLogging = false,
132-
});
136+
bool? disableCache,
137+
}) : disableCache = disableCache ?? inputSpec is! RemoteSpec;
133138
}
134139

135140
/// Provides the input spec file to be used.

openapi-generator/lib/src/models/generator_arguments.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class GeneratorArguments {
2020
///
2121
/// The default location is: .dart_tool/openapi-generator-cache.json
2222
final String cachePath;
23+
24+
/// Informs the generator to disable the cache.
25+
final bool disableCache;
26+
2327
final bool isDebug;
2428

2529
/// Use a custom pubspec file when generating.
@@ -112,7 +116,8 @@ class GeneratorArguments {
112116
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml'),
113117
isDebug = annotations.readPropertyOrDefault('debugLogging', false),
114118
inputSpec =
115-
annotations.readPropertyOrDefault('inputSpec', InputSpec.json());
119+
annotations.readPropertyOrDefault('inputSpec', InputSpec.json()),
120+
disableCache = annotations.readPropertyOrDefault('disableCache', false);
116121

117122
/// The stringified name of the [Generator].
118123
String get generatorName => generator == Generator.dart

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,32 +170,41 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
170170
await runOpenApiJar(arguments: args);
171171
await fetchDependencies(baseCommand: baseCommand, args: args);
172172
await generateSources(baseCommand: baseCommand, args: args);
173-
if (!args.hasLocalCache) {
173+
if (args.disableCache) {
174174
logOutputMessage(
175175
log: log,
176176
communication: OutputMessage(
177-
message: 'No local cache found. Creating one.',
178-
level: Level.CONFIG,
177+
message: 'Cache disabled. Skipping cache update.',
179178
),
180179
);
181180
} else {
181+
if (!args.hasLocalCache) {
182+
logOutputMessage(
183+
log: log,
184+
communication: OutputMessage(
185+
message: 'No local cache found. Creating one.',
186+
level: Level.CONFIG,
187+
),
188+
);
189+
} else {
190+
logOutputMessage(
191+
log: log,
192+
communication: OutputMessage(
193+
message: 'Local cache found. Overwriting existing one.',
194+
level: Level.CONFIG,
195+
),
196+
);
197+
}
198+
await cacheSpec(
199+
outputLocation: args.cachePath,
200+
spec: await loadSpec(specConfig: args.inputSpec));
182201
logOutputMessage(
183202
log: log,
184203
communication: OutputMessage(
185-
message: 'Local cache found. Overwriting existing one.',
186-
level: Level.CONFIG,
204+
message: 'Successfully cached spec changes.',
187205
),
188206
);
189207
}
190-
await cacheSpec(
191-
outputLocation: args.cachePath,
192-
spec: await loadSpec(specConfig: args.inputSpec));
193-
logOutputMessage(
194-
log: log,
195-
communication: OutputMessage(
196-
message: 'Successfully cached spec changes.',
197-
),
198-
);
199208
}
200209
} catch (e, st) {
201210
logOutputMessage(

0 commit comments

Comments
 (0)