Skip to content

Commit 8e148ad

Browse files
Merge branch 'main' into update-streaming-proxy-example
2 parents df30d35 + 9218c26 commit 8e148ad

File tree

10 files changed

+276
-77
lines changed

10 files changed

+276
-77
lines changed

.github/workflows/main.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,70 @@ jobs:
1616
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
1717
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
1818
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
19+
windows_6_0_enabled: true
20+
windows_nightly_6_1_enabled: true
21+
windows_nightly_main_enabled: true
22+
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
23+
windows_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error"
24+
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
25+
26+
construct-integration-test-matrix:
27+
name: Construct integration matrix
28+
runs-on: ubuntu-latest
29+
outputs:
30+
integration-test-matrix: '${{ steps.generate-matrix.outputs.integration-test-matrix }}'
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
with:
35+
persist-credentials: false
36+
- id: generate-matrix
37+
run: echo "integration-test-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
38+
env:
39+
MATRIX_LINUX_SETUP_COMMAND: apt-get update -y && apt-get install -yq jq && git config --global --add safe.directory /swift-openapi-generator/.git && git config --global --add safe.directory /swift-openapi-generator
40+
MATRIX_LINUX_COMMAND: SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${workspace} ./scripts/run-integration-test.sh
41+
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
1942

2043
integration-test:
2144
name: Integration test
22-
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
45+
needs: construct-integration-test-matrix
46+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
2347
with:
2448
name: "Integration test"
25-
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${GITHUB_WORKSPACE} ./scripts/run-integration-test.sh"
49+
matrix_string: '${{ needs.construct-integration-test-matrix.outputs.integration-test-matrix }}'
50+
51+
construct-example-packages-matrix:
52+
name: Construct example packages matrix
53+
runs-on: ubuntu-latest
54+
outputs:
55+
example-packages-matrix: '${{ steps.generate-matrix.outputs.example-packages-matrix }}'
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
with:
60+
persist-credentials: false
61+
- id: generate-matrix
62+
run: echo "example-packages-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
63+
env:
64+
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-openapi-generator
65+
MATRIX_LINUX_COMMAND: ./scripts/test-examples.sh
66+
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
2667

2768
example-packages:
2869
name: Example packages
29-
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
70+
needs: construct-example-packages-matrix
71+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
3072
with:
3173
name: "Example packages"
32-
matrix_linux_command: "./scripts/test-examples.sh"
74+
matrix_string: '${{ needs.construct-example-packages-matrix.outputs.example-packages-matrix }}'
75+
76+
macos-tests:
77+
name: macOS tests
78+
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
79+
with:
80+
runner_pool: nightly
81+
build_scheme: swift-openapi-generator-Package
82+
ios_xcode_build_enabled: false
83+
watchos_xcode_build_enabled: false
84+
tvos_xcode_build_enabled: false
85+
visionos_xcode_build_enabled: false

.github/workflows/pull_request.yml

Lines changed: 102 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,111 @@
11
name: PR
22

33
on:
4-
pull_request:
5-
types: [opened, reopened, synchronize]
4+
pull_request:
5+
types: [opened, reopened, synchronize]
66

77
jobs:
8-
soundness:
9-
name: Soundness
10-
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
11-
with:
12-
api_breakage_check_enabled: false
13-
license_header_check_project_name: "SwiftOpenAPIGenerator"
14-
yamllint_check_enabled: false
8+
soundness:
9+
name: Soundness
10+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
11+
with:
12+
api_breakage_check_enabled: false
13+
license_header_check_project_name: "SwiftOpenAPIGenerator"
14+
yamllint_check_enabled: false
15+
16+
unit-tests:
17+
name: Unit tests
18+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
19+
with:
20+
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
21+
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
22+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
23+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
24+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
25+
windows_6_0_enabled: true
26+
windows_nightly_6_1_enabled: true
27+
windows_nightly_main_enabled: true
28+
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
29+
windows_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error"
30+
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
1531

16-
unit-tests:
17-
name: Unit tests
18-
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
32+
compatibility-test:
33+
name: Compatibility test
34+
runs-on: ubuntu-latest
35+
container:
36+
image: swift:latest
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
1940
with:
20-
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
21-
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
22-
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
23-
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
24-
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
25-
26-
integration-test:
27-
name: Integration test
28-
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
41+
persist-credentials: false
42+
- name: Run OpenAPI document compatibilty test
43+
env:
44+
SWIFT_OPENAPI_COMPATIBILITY_TEST_ENABLE: "true"
45+
SWIFT_OPENAPI_COMPATIBILITY_TEST_SKIP_BUILD: "true"
46+
SWIFT_OPENAPI_COMPATIBILITY_TEST_FILTER: OpenAPIGeneratorReferenceTests.CompatibilityTest
47+
SWIFT_OPENAPI_COMPATIBILITY_TEST_PARALLEL_CODEGEN: "true"
48+
SWIFT_OPENAPI_COMPATIBILITY_TEST_NUM_BUILD_JOBS: 1
49+
run: swift test --filter ${SWIFT_OPENAPI_COMPATIBILITY_TEST_FILTER}
50+
51+
construct-integration-test-matrix:
52+
name: Construct integration matrix
53+
runs-on: ubuntu-latest
54+
outputs:
55+
integration-test-matrix: '${{ steps.generate-matrix.outputs.integration-test-matrix }}'
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
2959
with:
30-
name: "Integration test"
31-
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${GITHUB_WORKSPACE} ./scripts/run-integration-test.sh"
32-
matrix_linux_nightly_main_enabled: false
33-
34-
compatibility-test:
35-
name: Compatibility test
36-
runs-on: ubuntu-latest
37-
container:
38-
image: swift:latest
39-
steps:
40-
- name: Checkout repository
41-
uses: actions/checkout@v4
42-
with:
43-
persist-credentials: false
44-
- name: Run OpenAPI document compatibilty test
45-
env:
46-
SWIFT_OPENAPI_COMPATIBILITY_TEST_ENABLE: "true"
47-
SWIFT_OPENAPI_COMPATIBILITY_TEST_SKIP_BUILD: "true"
48-
SWIFT_OPENAPI_COMPATIBILITY_TEST_FILTER: OpenAPIGeneratorReferenceTests.CompatibilityTest
49-
SWIFT_OPENAPI_COMPATIBILITY_TEST_PARALLEL_CODEGEN: "true"
50-
SWIFT_OPENAPI_COMPATIBILITY_TEST_NUM_BUILD_JOBS: 1
51-
run: swift test --filter ${SWIFT_OPENAPI_COMPATIBILITY_TEST_FILTER}
52-
53-
example-packages:
54-
name: Example packages
55-
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
60+
persist-credentials: false
61+
- id: generate-matrix
62+
run: echo "integration-test-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
63+
env:
64+
MATRIX_LINUX_SETUP_COMMAND: apt-get update -y && apt-get install -yq jq && git config --global --add safe.directory /swift-openapi-generator/.git && git config --global --add safe.directory /swift-openapi-generator
65+
MATRIX_LINUX_COMMAND: SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${workspace} ./scripts/run-integration-test.sh
66+
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
67+
68+
integration-test:
69+
name: Integration test
70+
needs: construct-integration-test-matrix
71+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
72+
with:
73+
name: "Integration test"
74+
matrix_string: '${{ needs.construct-integration-test-matrix.outputs.integration-test-matrix }}'
75+
76+
construct-example-packages-matrix:
77+
name: Construct example packages matrix
78+
runs-on: ubuntu-latest
79+
outputs:
80+
example-packages-matrix: '${{ steps.generate-matrix.outputs.example-packages-matrix }}'
81+
steps:
82+
- name: Checkout repository
83+
uses: actions/checkout@v4
5684
with:
57-
name: "Example packages"
58-
matrix_linux_command: "./scripts/test-examples.sh"
59-
matrix_linux_nightly_main_enabled: false
85+
persist-credentials: false
86+
- id: generate-matrix
87+
run: echo "example-packages-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
88+
env:
89+
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-openapi-generator
90+
MATRIX_LINUX_COMMAND: ./scripts/test-examples.sh
91+
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
92+
93+
example-packages:
94+
name: Example packages
95+
needs: construct-example-packages-matrix
96+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
97+
with:
98+
name: "Example packages"
99+
matrix_string: '${{ needs.construct-example-packages-matrix.outputs.example-packages-matrix }}'
100+
101+
102+
macos-tests:
103+
name: macOS tests
104+
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
105+
with:
106+
runner_pool: general
107+
build_scheme: swift-openapi-generator-Package
108+
ios_xcode_build_enabled: false
109+
watchos_xcode_build_enabled: false
110+
tvos_xcode_build_enabled: false
111+
visionos_xcode_build_enabled: false

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let package = Package(
5454
// Tests-only: Runtime library linked by generated code, and also
5555
// helps keep the runtime library new enough to work with the generated
5656
// code.
57-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.3.2"),
57+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.8.2"),
5858
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
5959
],
6060
targets: [
@@ -111,7 +111,10 @@ let package = Package(
111111
.testTarget(
112112
name: "OpenAPIGeneratorTests",
113113
dependencies: [
114-
"swift-openapi-generator", .product(name: "ArgumentParser", package: "swift-argument-parser"),
114+
"_OpenAPIGeneratorCore",
115+
// Everything except windows: https://github.com/swiftlang/swift-package-manager/issues/6367
116+
.target(name: "swift-openapi-generator", condition: .when(platforms: [.android, .linux, .macOS, .openbsd, .wasi, .custom("freebsd")])),
117+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
115118
],
116119
resources: [.copy("Resources")],
117120
swiftSettings: swiftSettings

Plugins/PluginsShared/PluginUtils.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ enum PluginUtils {
6464

6565
/// Find the config file.
6666
private static func findConfig(inputFiles: FileList, targetName: String) -> Result<Path, FileError> {
67-
let matchedConfigs = inputFiles.filter { supportedConfigFiles.contains($0.path.lastComponent) }.map(\.path)
67+
let matchedConfigs = inputFiles.filter { supportedConfigFiles.contains($0.path.lastComponent_fixed) }
68+
.map(\.path)
6869
guard matchedConfigs.count > 0 else {
6970
return .failure(FileError(targetName: targetName, fileKind: .config, issue: .noFilesFound))
7071
}
@@ -78,7 +79,7 @@ enum PluginUtils {
7879

7980
/// Find the document file.
8081
private static func findDocument(inputFiles: FileList, targetName: String) -> Result<Path, FileError> {
81-
let matchedDocs = inputFiles.filter { supportedDocFiles.contains($0.path.lastComponent) }.map(\.path)
82+
let matchedDocs = inputFiles.filter { supportedDocFiles.contains($0.path.lastComponent_fixed) }.map(\.path)
8283
guard matchedDocs.count > 0 else {
8384
return .failure(FileError(targetName: targetName, fileKind: .document, issue: .noFilesFound))
8485
}
@@ -97,3 +98,24 @@ extension Array where Element == String {
9798
return "\(self.dropLast().joined(separator: separator))\(lastSeparator)\(self.last!)"
9899
}
99100
}
101+
102+
extension PackagePlugin.Path {
103+
/// Workaround for the ``lastComponent`` property being broken on Windows
104+
/// due to hardcoded assumptions about the path separator being forward slash.
105+
@available(_PackageDescription, deprecated: 6.0, message: "Use `URL` type instead of `Path`.") public
106+
var lastComponent_fixed: String
107+
{
108+
#if !os(Windows)
109+
lastComponent
110+
#else
111+
// Find the last path separator.
112+
guard let idx = string.lastIndex(where: { $0 == "/" || $0 == "\\" }) else {
113+
// No path separators, so the basename is the whole string.
114+
return self.string
115+
}
116+
// Otherwise, it's the string from (but not including) the last path
117+
// separator.
118+
return String(self.string.suffix(from: self.string.index(after: idx)))
119+
#endif
120+
}
121+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ See also [Supported OpenAPI features][supported-openapi-features].
9999

100100
### Supported platforms and minimum versions
101101

102-
The generator is used during development and is supported on macOS and Linux.
102+
The generator is used during development and is supported on macOS, Linux, and Windows.
103103

104104
The generated code, runtime library, and transports are supported on more
105105
platforms, listed below.
106106

107-
| Component | macOS | Linux | iOS | tvOS | watchOS | visionOS |
107+
| Component | macOS | Linux, Windows | iOS | tvOS | watchOS | visionOS |
108108
| ----------------------------------: | :--- | :--- | :- | :-- | :----- | :------ |
109109
| Generator plugin and CLI | ✅ 10.15+ || ✖️ | ✖️ | ✖️ | ✖️ |
110110
| Generated code and runtime library | ✅ 10.15+ || ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ |

Tests/OpenAPIGeneratorReferenceTests/CompatabilityTest.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,9 @@ fileprivate extension CompatibilityTest {
314314

315315
// Build the package.
316316
let process = Process()
317-
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
317+
process.executableURL = try resolveExecutable("swift")
318318
process.arguments = [
319-
"swift", "build", "--package-path", packageDir.path, "-Xswiftc", "-Xllvm", "-Xswiftc",
320-
"-vectorize-slp=false",
319+
"build", "--package-path", packageDir.path, "-Xswiftc", "-Xllvm", "-Xswiftc", "-vectorize-slp=false",
321320
]
322321
if let numBuildJobs = compatibilityTestNumBuildJobs {
323322
process.arguments!.append(contentsOf: ["-j", String(numBuildJobs)])
@@ -358,14 +357,12 @@ fileprivate extension CompatibilityTest {
358357
func log(_ message: String) { print("\(name) \(message)") }
359358

360359
var testCaseName: String {
361-
/// The `name` property is `<test-suite-name>.<test-case-name>` on Linux,
362-
/// and `-[<test-suite-name> <test-case-name>]` on macOS.
360+
/// The `name` property is `-[<test-suite-name> <test-case-name>]` on Apple platforms (e.g. with an Objective-C runtime),
361+
/// and `<test-suite-name>.<test-case-name>` elsewhere.
363362
#if canImport(Darwin)
364363
return String(name.split(separator: " ", maxSplits: 2).last!.dropLast())
365-
#elseif os(Linux)
366-
return String(name.split(separator: ".", maxSplits: 2).last!)
367364
#else
368-
#error("Platform not supported")
365+
return String(name.split(separator: ".", maxSplits: 2).last!)
369366
#endif
370367
}
371368
}
@@ -417,7 +414,7 @@ fileprivate extension URLSession {
417414
func data(from url: URL) async throws -> (Data, URLResponse) {
418415
#if canImport(Darwin)
419416
return try await data(from: url, delegate: nil)
420-
#elseif os(Linux)
417+
#else
421418
return try await withCheckedThrowingContinuation { continuation in
422419
dataTask(with: URLRequest(url: url)) { data, response, error in
423420
if let error {
@@ -432,8 +429,6 @@ fileprivate extension URLSession {
432429
}
433430
.resume()
434431
}
435-
#else
436-
#error("Platform not supported")
437432
#endif
438433
}
439434
}

0 commit comments

Comments
 (0)