Skip to content

Commit b4c15ee

Browse files
authored
fix: Notify build_runner of dependency on inputSpec (#187)
1 parent 28f82c5 commit b4c15ee

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

openapi-generator/lib/src/openapi_generator_runner.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
5757
: 'dart';
5858

5959
return generatorV2(
60-
args: args,
61-
baseCommand: baseCommand,
62-
annotatedPath: buildStep.inputId.path);
60+
args: args, baseCommand: baseCommand, buildStep: buildStep);
6361
}
6462
} catch (e, st) {
6563
late OutputMessage communication;
@@ -178,7 +176,8 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
178176
FutureOr<String> generatorV2(
179177
{required GeneratorArguments args,
180178
required String baseCommand,
181-
required String annotatedPath}) async {
179+
required BuildStep buildStep}) async {
180+
final annotatedPath = buildStep.inputId.path;
182181
if (args.isRemote) {
183182
logOutputMessage(
184183
log: log,
@@ -190,6 +189,16 @@ class OpenapiGenerator extends GeneratorForAnnotation<annots.Openapi> {
190189
);
191190
}
192191
try {
192+
// Notify build_runner of dependency on inputSpec
193+
if (args.inputSpec is! annots.RemoteSpec &&
194+
!path.isAbsolute(args.inputSpec.path)) {
195+
final maybeAssetId =
196+
AssetId(buildStep.inputId.package, args.inputSpec.path);
197+
// Check if asset can be read. If so, build_runner will mark the asset
198+
// as a dependency and re-run the builder when it is modified.
199+
await buildStep.canRead(maybeAssetId);
200+
}
201+
193202
if (!await hasDiff(args: args) && args.skipIfSpecIsUnchanged) {
194203
logOutputMessage(
195204
log: log,

0 commit comments

Comments
 (0)