Skip to content

Commit 7f8770b

Browse files
authored
Merge pull request #145 from ricardoboss/issues/144-disable-cache
feat: Added option to disable caching
2 parents 6224377 + d1ae279 commit 7f8770b

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
@@ -129,6 +129,10 @@ class Openapi {
129129
/// Defaults to true
130130
final bool updateAnnotatedFile;
131131

132+
/// Whether to disable caching the spec file. Defaults to `true` if the
133+
/// [inputSpec] is not a [RemoteSpec].
134+
final bool disableCache;
135+
132136
const Openapi({
133137
this.additionalProperties,
134138
this.skipSpecValidation = false,
@@ -150,7 +154,8 @@ class Openapi {
150154
this.projectPubspecPath,
151155
this.debugLogging = false,
152156
this.updateAnnotatedFile = true,
153-
});
157+
bool? disableCache,
158+
}) : disableCache = disableCache ?? inputSpec is! RemoteSpec;
154159
}
155160

156161
/// 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.
@@ -130,7 +134,8 @@ class GeneratorArguments {
130134
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml'),
131135
isDebug = annotations.readPropertyOrDefault('debugLogging', false),
132136
inputSpec =
133-
annotations.readPropertyOrDefault('inputSpec', InputSpec.json());
137+
annotations.readPropertyOrDefault('inputSpec', InputSpec.json()),
138+
disableCache = annotations.readPropertyOrDefault('disableCache', false);
134139

135140
/// The stringified name of the [Generator].
136141
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
@@ -192,32 +192,41 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
192192
await runOpenApiJar(arguments: args);
193193
await fetchDependencies(baseCommand: baseCommand, args: args);
194194
await generateSources(baseCommand: baseCommand, args: args);
195-
if (!args.hasLocalCache) {
195+
if (args.disableCache) {
196196
logOutputMessage(
197197
log: log,
198198
communication: OutputMessage(
199-
message: 'No local cache found. Creating one.',
200-
level: Level.CONFIG,
199+
message: 'Cache disabled. Skipping cache update.',
201200
),
202201
);
203202
} else {
203+
if (!args.hasLocalCache) {
204+
logOutputMessage(
205+
log: log,
206+
communication: OutputMessage(
207+
message: 'No local cache found. Creating one.',
208+
level: Level.CONFIG,
209+
),
210+
);
211+
} else {
212+
logOutputMessage(
213+
log: log,
214+
communication: OutputMessage(
215+
message: 'Local cache found. Overwriting existing one.',
216+
level: Level.CONFIG,
217+
),
218+
);
219+
}
220+
await cacheSpec(
221+
outputLocation: args.cachePath,
222+
spec: await loadSpec(specConfig: args.inputSpec));
204223
logOutputMessage(
205224
log: log,
206225
communication: OutputMessage(
207-
message: 'Local cache found. Overwriting existing one.',
208-
level: Level.CONFIG,
226+
message: 'Successfully cached spec changes.',
209227
),
210228
);
211229
}
212-
await cacheSpec(
213-
outputLocation: args.cachePath,
214-
spec: await loadSpec(specConfig: args.inputSpec));
215-
logOutputMessage(
216-
log: log,
217-
communication: OutputMessage(
218-
message: 'Successfully cached spec changes.',
219-
),
220-
);
221230
}
222231
} catch (e, st) {
223232
logOutputMessage(

0 commit comments

Comments
 (0)