-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenAPI documents for the toolchains and Swift evolution APIs #841
Open
czechboy0
wants to merge
5
commits into
swiftlang:main
Choose a base branch
from
czechboy0:hd-add-openapi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+934
−0
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fddcb30
Add a Swift.org API OpenAPI document
czechboy0 1389b03
Added download.swift.org OpenAPI doc as well, more polish
czechboy0 aa67272
Further clarify language
czechboy0 d1adabe
Fix up proposal states
czechboy0 01a55b2
Add descriptions to the fallback anyOf values
czechboy0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ | |
/_posts/* @timsneath @tkremenek @shahmishal | ||
|
||
/gsoc*/ @ktoso | ||
|
||
/openapi/ @czechboy0 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.build | ||
.swiftpm | ||
Package.resolved |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// swift-tools-version: 6.0 | ||
import PackageDescription | ||
|
||
let clientNames: [String] = [ | ||
"swiftorgClient", | ||
"downloadswiftorgClient", | ||
] | ||
|
||
let package = Package( | ||
name: "TestSwiftOrgClient", | ||
platforms: [ | ||
.macOS(.v13), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"), | ||
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"), | ||
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "Shared", | ||
path: "Shared" | ||
) | ||
] + clientNames.map { name in | ||
.executableTarget( | ||
name: name, | ||
dependencies: [ | ||
"Shared", | ||
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), | ||
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"), | ||
], | ||
path: name, | ||
plugins: [ | ||
.plugin(name: "OpenAPIGenerator", package: "swift-openapi-generator"), | ||
] | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Test Swift.org client | ||
|
||
This simple Swift package contains a Swift HTTP Client that can be used to test the Swift.org API. | ||
|
||
It is generated from the OpenAPI document of Swift.org and generated using Swift OpenAPI Generator. | ||
|
||
## Usage | ||
|
||
You can run it either against the Swift.org API or against a locally running API. | ||
|
||
By default, the tool runs against the production Swift.org APIs. | ||
|
||
Run against production using: | ||
``` | ||
SWIFTORG_SERVER_NAME=prod swift run swiftorgClient | ||
DOWNLOADSWIFTORG_SERVER_NAME=prod swift run downloadswiftorgClient | ||
``` | ||
|
||
Run against a locally running server using: | ||
``` | ||
SWIFTORG_SERVER_NAME=local swift run swiftorgClient | ||
``` | ||
|
||
The exact server URLs are defined in the OpenAPI document. | ||
|
||
If the tool detects a deserialization error, possibly because the OpenAPI document does not correctly parse the returned data, it will exit with a non-zero exit code. | ||
|
||
If all test cases run successfully, the tool exits with 0. | ||
|
||
Sample output: | ||
|
||
``` | ||
% SWIFTORG_SERVER_NAME=prod swift run swiftorgClient | ||
Testing SwiftOrg API at https://www.swift.org/api/v1... | ||
✅ listReleases | ||
✅ listDevToolchains(main, amazonlinux2) | ||
✅ listDevToolchains(main, centos7) | ||
✅ listDevToolchains(main, macos) | ||
✅ listDevToolchains(main, ubi9) | ||
✅ listDevToolchains(main, ubuntu2004) | ||
✅ listDevToolchains(main, ubuntu2204) | ||
✅ listDevToolchains(main, windows10) | ||
✅ listDevToolchains(6.0, amazonlinux2) | ||
✅ listDevToolchains(6.0, centos7) | ||
✅ listDevToolchains(6.0, macos) | ||
✅ listDevToolchains(6.0, ubi9) | ||
✅ listDevToolchains(6.0, ubuntu2004) | ||
✅ listDevToolchains(6.0, ubuntu2204) | ||
✅ listDevToolchains(6.0, windows10) | ||
✅ listStaticSDKDevToolchains(main) | ||
✅ listStaticSDKDevToolchains(6.0) | ||
% DOWNLOADSWIFTORG_SERVER_NAME=prod swift run downloadswiftorgClient | ||
✅ listProposals | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
|
||
package struct Test: Sendable { | ||
package var name: String | ||
package var work: @Sendable () async throws -> Void | ||
|
||
package init(name: String, work: @Sendable @escaping () async throws -> Void) { | ||
self.name = name | ||
self.work = work | ||
} | ||
} | ||
|
||
package struct Tester { | ||
package static func run(_ tests: [Test]) async throws { | ||
var results: [(String, Error?)] = [] | ||
func runTest(_ test: Test) async { | ||
do { | ||
try await test.work() | ||
results.append((test.name, nil)) | ||
print("✅ \(test.name)") | ||
} catch { | ||
results.append((test.name, error)) | ||
print("❌ \(test.name): \(String(describing: error))") | ||
} | ||
} | ||
for test in tests { | ||
await runTest(test) | ||
} | ||
let failed = results.contains(where: { $0.1 != nil }) | ||
exit(failed ? 1 : 0) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
openapi/TestSwiftOrgClient/downloadswiftorgClient/Issue847Workaround.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import OpenAPIRuntime | ||
import HTTPTypes | ||
import Foundation | ||
|
||
// Workaround for issue: https://github.com/swiftlang/swift-org-website/issues/847 | ||
struct Issue847WorkaroundMiddleware: ClientMiddleware { | ||
func intercept( | ||
_ request: HTTPRequest, | ||
body: HTTPBody?, | ||
baseURL: URL, | ||
operationID: String, | ||
next: (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?) | ||
) async throws -> (HTTPResponse, HTTPBody?) { | ||
var (response, responseBody) = try await next(request, body, baseURL) | ||
guard | ||
operationID == "listProposals" && | ||
response.status.code == 200 && | ||
response.headerFields[.contentType] == "application/octet-stream" | ||
else { | ||
return (response, responseBody) | ||
} | ||
response.headerFields[.contentType] = "application/json" | ||
return (response, responseBody) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
openapi/TestSwiftOrgClient/downloadswiftorgClient/Tool.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import OpenAPIURLSession | ||
import Foundation | ||
import Shared | ||
|
||
enum DownloadSwiftOrgServerName: String { | ||
case prod | ||
} | ||
|
||
@main | ||
struct Tool { | ||
static func main() async throws { | ||
let serverURL: URL | ||
if | ||
let name = ProcessInfo.processInfo.environment["DOWNLOADSWIFTORG_SERVER_NAME"], | ||
let serverName = DownloadSwiftOrgServerName(rawValue: name) | ||
{ | ||
switch serverName { | ||
case .prod: | ||
serverURL = try Servers.Server1.url() | ||
} | ||
} else { | ||
serverURL = try Servers.Server1.url() | ||
} | ||
|
||
print("Testing download.swift.org API at \(serverURL.absoluteString)...") | ||
|
||
let client = Client( | ||
serverURL: serverURL, | ||
transport: URLSessionTransport(), | ||
middlewares: [ | ||
Issue847WorkaroundMiddleware(), | ||
] | ||
) | ||
|
||
let tests: [Test] = [ | ||
.init( | ||
name: "listProposals", | ||
work: { _ = try await client.listProposals().ok.body.json } | ||
), | ||
] | ||
try await Tester.run(tests) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
openapi/TestSwiftOrgClient/downloadswiftorgClient/openapi-generator-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../openapi-generator-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../downloadswiftorg.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
generate: | ||
- types | ||
- client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import OpenAPIURLSession | ||
import Foundation | ||
import Shared | ||
|
||
enum SwiftOrgServerName: String { | ||
case prod | ||
case local | ||
} | ||
|
||
@main | ||
struct Tool { | ||
static func main() async throws { | ||
let serverURL: URL | ||
if | ||
let name = ProcessInfo.processInfo.environment["SWIFTORG_SERVER_NAME"], | ||
let serverName = SwiftOrgServerName(rawValue: name) | ||
{ | ||
switch serverName { | ||
case .prod: | ||
serverURL = try Servers.Server1.url() | ||
case .local: | ||
serverURL = try Servers.Server2.url() | ||
} | ||
} else { | ||
serverURL = try Servers.Server1.url() | ||
} | ||
|
||
print("Testing swift.org API at \(serverURL.absoluteString)...") | ||
|
||
let client = Client( | ||
serverURL: serverURL, | ||
transport: URLSessionTransport() | ||
) | ||
|
||
var tests: [Test] = [ | ||
.init( | ||
name: "listReleases", | ||
work: { _ = try await client.listReleases().ok.body.json } | ||
), | ||
] | ||
for branch in Components.Schemas.KnownSourceBranch.allCases { | ||
for platform in Components.Schemas.KnownPlatformIdentifier.allCases { | ||
tests.append( | ||
.init( | ||
name: "listDevToolchains(\(branch.rawValue), \(platform.rawValue))", | ||
work: { | ||
_ = try await client.listDevToolchains(.init( | ||
path: .init( | ||
branch: branch, | ||
platform: platform | ||
) | ||
)).ok.body.json | ||
} | ||
) | ||
) | ||
} | ||
} | ||
for branch in Components.Schemas.KnownSourceBranch.allCases { | ||
tests.append( | ||
.init( | ||
name: "listStaticSDKDevToolchains(\(branch.rawValue))", | ||
work: { | ||
_ = try await client.listStaticSDKDevToolchains(.init(path: .init(branch: branch))).ok.body.json | ||
} | ||
) | ||
) | ||
} | ||
|
||
try await Tester.run(tests) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
openapi/TestSwiftOrgClient/swiftorgClient/openapi-generator-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../openapi-generator-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../swiftorg.yaml |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to review future changes to the OpenAPI documents, but that'd require me to receive write access - I'll leave that up to the SWWG to decide whether that's valuable for me to have or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shahmishal if we're happy with this we'll need to add @czechboy0 to the access list for the repo