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

Added option to disable caching #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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,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,
Expand All @@ -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.
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 @@ -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.
Expand Down Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions openapi-generator/lib/src/openapi_generator_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,41 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
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(
Expand Down
Loading