Skip to content

Commit d5949a1

Browse files
Fix command plugin when run on targets with dependencies
1 parent fc0bc08 commit d5949a1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Plugins/OpenAPIGeneratorCommand/plugin.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,24 @@ extension SwiftOpenAPIGeneratorPlugin: CommandPlugin {
8181
log("- ✅ OpenAPI code generation for target '\(target.name)' successfully completed.")
8282
hadASuccessfulRun = true
8383
} catch let error as PluginError {
84-
if targetNameArguments.isEmpty, case .fileErrors(let errors) = error,
84+
if case .fileErrors(let errors) = error,
8585
Set(errors.map(\.fileKind)) == Set(FileError.Kind.allCases),
8686
errors.map(\.issue).allSatisfy({ $0 == FileError.Issue.noFilesFound })
8787
{
88-
// The command plugin was run with no --target argument so its looping over all targets.
89-
// If a target does not have any of the required files, this should only be considered an error
90-
// if the plugin is being explicitly run on a target, either using the build plugin, or using the
91-
// command plugin with a --target argument.
92-
log("- Skipping because target isn't configured for OpenAPI code generation.")
93-
continue
88+
// The error is that neither of the required files are present for code generation for this target.
89+
// This should only be considered an error if this target was explicitly provided as a target for
90+
// code generation with --target.
91+
// We may get this error for other targets if:
92+
//
93+
// 1. The command plugin was run with no --target arguments, in which case the plugin loops over
94+
// all targets; or
95+
// 2. This target is a dependency of a target that was requested using --target.
96+
//
97+
// In either of these cases, we should not consider this an error and skip the target.
98+
if !targetNameArguments.contains(target.name) {
99+
log("- Skipping because target isn't configured for OpenAPI code generation.")
100+
continue
101+
}
94102
}
95103

96104
if error.isMisconfigurationError {

0 commit comments

Comments
 (0)