diff --git a/.licenseignore b/.licenseignore index dab614423..5820d02f6 100644 --- a/.licenseignore +++ b/.licenseignore @@ -43,3 +43,4 @@ Examples/streaming-chatgpt-proxy/players.txt **/Makefile **/*.html .editorconfig +IntegrationTest/**/Empty.swift diff --git a/IntegrationTest/Package.swift b/IntegrationTest/Package.swift index a15544ccc..0875530ca 100644 --- a/IntegrationTest/Package.swift +++ b/IntegrationTest/Package.swift @@ -51,5 +51,12 @@ let package = Package( name: "MockTransportServer", dependencies: ["Server", .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")] ), + // Targets to integration test the command plugin + .target(name: "Empty"), + .target(name: "TypesAOT", dependencies: [.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")]), + .target( + name: "TypesAOTWithDependency", + dependencies: ["Empty", .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")] + ), ] ) diff --git a/IntegrationTest/Sources/Empty/Empty.swift b/IntegrationTest/Sources/Empty/Empty.swift new file mode 100644 index 000000000..e69de29bb diff --git a/IntegrationTest/Sources/TypesAOT/Empty.swift b/IntegrationTest/Sources/TypesAOT/Empty.swift new file mode 100644 index 000000000..e69de29bb diff --git a/IntegrationTest/Sources/TypesAOT/openapi-generator-config.yaml b/IntegrationTest/Sources/TypesAOT/openapi-generator-config.yaml new file mode 100644 index 000000000..a12e67bf7 --- /dev/null +++ b/IntegrationTest/Sources/TypesAOT/openapi-generator-config.yaml @@ -0,0 +1,4 @@ +generate: + - types +accessModifier: package +namingStrategy: idiomatic diff --git a/IntegrationTest/Sources/TypesAOT/openapi.yaml b/IntegrationTest/Sources/TypesAOT/openapi.yaml new file mode 120000 index 000000000..1c2a243ef --- /dev/null +++ b/IntegrationTest/Sources/TypesAOT/openapi.yaml @@ -0,0 +1 @@ +../openapi.yaml \ No newline at end of file diff --git a/IntegrationTest/Sources/TypesAOTWithDependency/Empty.swift b/IntegrationTest/Sources/TypesAOTWithDependency/Empty.swift new file mode 100644 index 000000000..e69de29bb diff --git a/IntegrationTest/Sources/TypesAOTWithDependency/openapi-generator-config.yaml b/IntegrationTest/Sources/TypesAOTWithDependency/openapi-generator-config.yaml new file mode 100644 index 000000000..a12e67bf7 --- /dev/null +++ b/IntegrationTest/Sources/TypesAOTWithDependency/openapi-generator-config.yaml @@ -0,0 +1,4 @@ +generate: + - types +accessModifier: package +namingStrategy: idiomatic diff --git a/IntegrationTest/Sources/TypesAOTWithDependency/openapi.yaml b/IntegrationTest/Sources/TypesAOTWithDependency/openapi.yaml new file mode 120000 index 000000000..1c2a243ef --- /dev/null +++ b/IntegrationTest/Sources/TypesAOTWithDependency/openapi.yaml @@ -0,0 +1 @@ +../openapi.yaml \ No newline at end of file diff --git a/Plugins/OpenAPIGeneratorCommand/plugin.swift b/Plugins/OpenAPIGeneratorCommand/plugin.swift index 9b3d6524d..d0e3d6f3e 100644 --- a/Plugins/OpenAPIGeneratorCommand/plugin.swift +++ b/Plugins/OpenAPIGeneratorCommand/plugin.swift @@ -81,16 +81,23 @@ extension SwiftOpenAPIGeneratorPlugin: CommandPlugin { log("- ✅ OpenAPI code generation for target '\(target.name)' successfully completed.") hadASuccessfulRun = true } catch let error as PluginError { - if targetNameArguments.isEmpty, case .fileErrors(let errors) = error, - Set(errors.map(\.fileKind)) == Set(FileError.Kind.allCases), + if case .fileErrors(let errors) = error, Set(errors.map(\.fileKind)) == Set(FileError.Kind.allCases), errors.map(\.issue).allSatisfy({ $0 == FileError.Issue.noFilesFound }) { - // The command plugin was run with no --target argument so its looping over all targets. - // If a target does not have any of the required files, this should only be considered an error - // if the plugin is being explicitly run on a target, either using the build plugin, or using the - // command plugin with a --target argument. - log("- Skipping because target isn't configured for OpenAPI code generation.") - continue + // The error is that neither of the required files are present for code generation for this target. + // This should only be considered an error if this target was explicitly provided as a target for + // code generation with --target. + // We may get this error for other targets if: + // + // 1. The command plugin was run with no --target arguments, in which case the plugin loops over + // all targets; or + // 2. This target is a dependency of a target that was requested using --target. + // + // In either of these cases, we should not consider this an error and skip the target. + if !targetNameArguments.contains(target.name) { + log("- Skipping because target isn't configured for OpenAPI code generation.") + continue + } } if error.isMisconfigurationError { diff --git a/scripts/run-integration-test.sh b/scripts/run-integration-test.sh index f4196cfab..84a698c1e 100755 --- a/scripts/run-integration-test.sh +++ b/scripts/run-integration-test.sh @@ -49,4 +49,22 @@ log "Running command plugin on integration test package: ${INTEGRATION_TEST_PACK swift package --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ --allow-writing-to-package-directory generate-code-from-openapi +log "Running command plugin on integration test package AOT target: ${INTEGRATION_TEST_PACKAGE_PATH}" +swift package --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ + --allow-writing-to-package-directory generate-code-from-openapi \ + --target TypesAOT + +log "Building integration test package AOT target: ${INTEGRATION_TEST_PACKAGE_PATH}" +swift build --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ + --target TypesAOT + +log "Running command plugin on integration test package AOT target with dependency: ${INTEGRATION_TEST_PACKAGE_PATH}" +swift package --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ + --allow-writing-to-package-directory generate-code-from-openapi \ + --target TypesAOTWithDependency + +log "Building integration test package AOT target with dependency: ${INTEGRATION_TEST_PACKAGE_PATH}" +swift build --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ + --target TypesAOTWithDependency + log "✅ Successfully built integration test package."