Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Examples/streaming-chatgpt-proxy/players.txt
**/Makefile
**/*.html
.editorconfig
IntegrationTest/**/Empty.swift
10 changes: 10 additions & 0 deletions IntegrationTest/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ 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")],
),
]
)
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
generate:
- types
accessModifier: package
namingStrategy: idiomatic
1 change: 1 addition & 0 deletions IntegrationTest/Sources/TypesAOT/openapi.yaml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
generate:
- types
accessModifier: package
namingStrategy: idiomatic
22 changes: 15 additions & 7 deletions Plugins/OpenAPIGeneratorCommand/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@ 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,
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 {
Expand Down
18 changes: 18 additions & 0 deletions scripts/run-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Loading