Skip to content

Commit

Permalink
Merge branch 'main' into hd-soar-0013-idiomatic-naming-strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 authored Dec 16, 2024
2 parents e1f5e42 + a5052b9 commit ae13b02
Show file tree
Hide file tree
Showing 31 changed files with 785 additions and 372 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_enabled: false

Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pull_request_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PR label

on:
pull_request:
types: [labeled, unlabeled, opened, reopened, synchronize]

jobs:
semver-label-check:
name: Semantic version label check
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Check for Semantic Version label
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
3 changes: 2 additions & 1 deletion .swiftformatignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Tests/OpenAPIGeneratorReferenceTests/Resources
Sources/swift-openapi-generator/Documentation.docc
Examples/**/Generated/*
Examples/**/GeneratedSources/*
Examples/**/GeneratedSources/*
**Package.swift
2 changes: 1 addition & 1 deletion Examples/manual-generation-generator-cli-example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# The following values can be changed here, or passed on the command line.
SWIFT_OPENAPI_GENERATOR_GIT_URL ?= https://github.com/apple/swift-openapi-generator
SWIFT_OPENAPI_GENERATOR_GIT_TAG ?= 1.0.0
SWIFT_OPENAPI_GENERATOR_GIT_TAG ?= 1.5.0
SWIFT_OPENAPI_GENERATOR_CLONE_DIR ?= $(CURRENT_MAKEFILE_DIR)/.swift-openapi-generator
SWIFT_OPENAPI_GENERATOR_BUILD_CONFIGURATION ?= debug
OPENAPI_YAML_PATH ?= $(CURRENT_MAKEFILE_DIR)/openapi.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ internal struct Client: APIProtocol {
default:
return .undocumented(
statusCode: response.status.code,
.init()
.init(
headerFields: response.headerFields,
body: responseBody
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ extension APIProtocol {
/// Server URLs defined in the OpenAPI document.
internal enum Servers {
/// Example service deployment.
internal enum Server1 {
/// Example service deployment.
internal static func url() throws -> Foundation.URL {
try Foundation.URL(
validatingOpenAPIServerURL: "https://example.com/api",
variables: []
)
}
}
/// Example service deployment.
@available(*, deprecated, renamed: "Servers.Server1.url")
internal static func server1() throws -> Foundation.URL {
try Foundation.URL(
validatingOpenAPIServerURL: "https://example.com/api",
Expand Down Expand Up @@ -123,10 +134,10 @@ internal enum Operations {
self.headers = headers
}
}
@frozen internal enum Output: Sendable, Hashable {
internal enum Output: Sendable, Hashable {
internal struct Ok: Sendable, Hashable {
/// - Remark: Generated from `#/paths/greet/GET/responses/200/content`.
@frozen internal enum Body: Sendable, Hashable {
internal enum Body: Sendable, Hashable {
/// - Remark: Generated from `#/paths/greet/GET/responses/200/content/application\/json`.
case json(Components.Schemas.Greeting)
/// The associated value of the enum case if `self` is `.json`.
Expand Down Expand Up @@ -180,7 +191,7 @@ internal enum Operations {
/// A response with a code that is not documented in the OpenAPI document.
case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload)
}
@frozen internal enum AcceptableContentType: AcceptableProtocol {
internal enum AcceptableContentType: AcceptableProtocol {
case json
case other(Swift.String)
internal init?(rawValue: Swift.String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import struct Foundation.Data
import struct Foundation.Date
#endif
import HTTPTypes
package struct Client: APIProtocol {
internal struct Client: APIProtocol {
/// The underlying HTTP client.
private let client: UniversalClient
/// Creates a new client.
Expand All @@ -21,7 +21,7 @@ package struct Client: APIProtocol {
/// - configuration: A set of configuration values for the client.
/// - transport: A transport that performs HTTP operations.
/// - middlewares: A list of middlewares to call before the transport.
package init(
internal init(
serverURL: Foundation.URL,
configuration: Configuration = .init(),
transport: any ClientTransport,
Expand All @@ -39,7 +39,7 @@ package struct Client: APIProtocol {
}
/// - Remark: HTTP `GET /greet`.
/// - Remark: Generated from `#/paths//greet/get(getGreeting)`.
package func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
internal func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
try await client.send(
input: input,
forOperation: Operations.getGreeting.id,
Expand Down Expand Up @@ -93,7 +93,10 @@ package struct Client: APIProtocol {
default:
return .undocumented(
statusCode: response.status.code,
.init()
.init(
headerFields: response.headerFields,
body: responseBody
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import struct Foundation.Data
import struct Foundation.Date
#endif
/// A type that performs HTTP operations defined by the OpenAPI document.
package protocol APIProtocol: Sendable {
internal protocol APIProtocol: Sendable {
/// - Remark: HTTP `GET /greet`.
/// - Remark: Generated from `#/paths//greet/get(getGreeting)`.
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output
Expand All @@ -20,7 +20,7 @@ package protocol APIProtocol: Sendable {
extension APIProtocol {
/// - Remark: HTTP `GET /greet`.
/// - Remark: Generated from `#/paths//greet/get(getGreeting)`.
package func getGreeting(
internal func getGreeting(
query: Operations.getGreeting.Input.Query = .init(),
headers: Operations.getGreeting.Input.Headers = .init()
) async throws -> Operations.getGreeting.Output {
Expand All @@ -32,9 +32,20 @@ extension APIProtocol {
}

/// Server URLs defined in the OpenAPI document.
package enum Servers {
internal enum Servers {
/// Example service deployment.
package static func server1() throws -> Foundation.URL {
internal enum Server1 {
/// Example service deployment.
internal static func url() throws -> Foundation.URL {
try Foundation.URL(
validatingOpenAPIServerURL: "https://example.com/api",
variables: []
)
}
}
/// Example service deployment.
@available(*, deprecated, renamed: "Servers.Server1.url")
internal static func server1() throws -> Foundation.URL {
try Foundation.URL(
validatingOpenAPIServerURL: "https://example.com/api",
variables: []
Expand All @@ -43,97 +54,97 @@ package enum Servers {
}

/// Types generated from the components section of the OpenAPI document.
package enum Components {
internal enum Components {
/// Types generated from the `#/components/schemas` section of the OpenAPI document.
package enum Schemas {
internal enum Schemas {
/// A value with the greeting contents.
///
/// - Remark: Generated from `#/components/schemas/Greeting`.
package struct Greeting: Codable, Hashable, Sendable {
internal struct Greeting: Codable, Hashable, Sendable {
/// The string representation of the greeting.
///
/// - Remark: Generated from `#/components/schemas/Greeting/message`.
package var message: Swift.String
internal var message: Swift.String
/// Creates a new `Greeting`.
///
/// - Parameters:
/// - message: The string representation of the greeting.
package init(message: Swift.String) {
internal init(message: Swift.String) {
self.message = message
}
package enum CodingKeys: String, CodingKey {
internal enum CodingKeys: String, CodingKey {
case message
}
}
}
/// Types generated from the `#/components/parameters` section of the OpenAPI document.
package enum Parameters {}
internal enum Parameters {}
/// Types generated from the `#/components/requestBodies` section of the OpenAPI document.
package enum RequestBodies {}
internal enum RequestBodies {}
/// Types generated from the `#/components/responses` section of the OpenAPI document.
package enum Responses {}
internal enum Responses {}
/// Types generated from the `#/components/headers` section of the OpenAPI document.
package enum Headers {}
internal enum Headers {}
}

/// API operations, with input and output types, generated from `#/paths` in the OpenAPI document.
package enum Operations {
internal enum Operations {
/// - Remark: HTTP `GET /greet`.
/// - Remark: Generated from `#/paths//greet/get(getGreeting)`.
package enum getGreeting {
package static let id: Swift.String = "getGreeting"
package struct Input: Sendable, Hashable {
internal enum getGreeting {
internal static let id: Swift.String = "getGreeting"
internal struct Input: Sendable, Hashable {
/// - Remark: Generated from `#/paths/greet/GET/query`.
package struct Query: Sendable, Hashable {
internal struct Query: Sendable, Hashable {
/// The name used in the returned greeting.
///
/// - Remark: Generated from `#/paths/greet/GET/query/name`.
package var name: Swift.String?
internal var name: Swift.String?
/// Creates a new `Query`.
///
/// - Parameters:
/// - name: The name used in the returned greeting.
package init(name: Swift.String? = nil) {
internal init(name: Swift.String? = nil) {
self.name = name
}
}
package var query: Operations.getGreeting.Input.Query
internal var query: Operations.getGreeting.Input.Query
/// - Remark: Generated from `#/paths/greet/GET/header`.
package struct Headers: Sendable, Hashable {
package var accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.getGreeting.AcceptableContentType>]
internal struct Headers: Sendable, Hashable {
internal var accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.getGreeting.AcceptableContentType>]
/// Creates a new `Headers`.
///
/// - Parameters:
/// - accept:
package init(accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.getGreeting.AcceptableContentType>] = .defaultValues()) {
internal init(accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.getGreeting.AcceptableContentType>] = .defaultValues()) {
self.accept = accept
}
}
package var headers: Operations.getGreeting.Input.Headers
internal var headers: Operations.getGreeting.Input.Headers
/// Creates a new `Input`.
///
/// - Parameters:
/// - query:
/// - headers:
package init(
internal init(
query: Operations.getGreeting.Input.Query = .init(),
headers: Operations.getGreeting.Input.Headers = .init()
) {
self.query = query
self.headers = headers
}
}
@frozen package enum Output: Sendable, Hashable {
package struct Ok: Sendable, Hashable {
internal enum Output: Sendable, Hashable {
internal struct Ok: Sendable, Hashable {
/// - Remark: Generated from `#/paths/greet/GET/responses/200/content`.
@frozen package enum Body: Sendable, Hashable {
internal enum Body: Sendable, Hashable {
/// - Remark: Generated from `#/paths/greet/GET/responses/200/content/application\/json`.
case json(Components.Schemas.Greeting)
/// The associated value of the enum case if `self` is `.json`.
///
/// - Throws: An error if `self` is not `.json`.
/// - SeeAlso: `.json`.
package var json: Components.Schemas.Greeting {
internal var json: Components.Schemas.Greeting {
get throws {
switch self {
case let .json(body):
Expand All @@ -143,12 +154,12 @@ package enum Operations {
}
}
/// Received HTTP response body
package var body: Operations.getGreeting.Output.Ok.Body
internal var body: Operations.getGreeting.Output.Ok.Body
/// Creates a new `Ok`.
///
/// - Parameters:
/// - body: Received HTTP response body
package init(body: Operations.getGreeting.Output.Ok.Body) {
internal init(body: Operations.getGreeting.Output.Ok.Body) {
self.body = body
}
}
Expand All @@ -162,7 +173,7 @@ package enum Operations {
///
/// - Throws: An error if `self` is not `.ok`.
/// - SeeAlso: `.ok`.
package var ok: Operations.getGreeting.Output.Ok {
internal var ok: Operations.getGreeting.Output.Ok {
get throws {
switch self {
case let .ok(response):
Expand All @@ -180,26 +191,26 @@ package enum Operations {
/// A response with a code that is not documented in the OpenAPI document.
case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload)
}
@frozen package enum AcceptableContentType: AcceptableProtocol {
internal enum AcceptableContentType: AcceptableProtocol {
case json
case other(Swift.String)
package init?(rawValue: Swift.String) {
internal init?(rawValue: Swift.String) {
switch rawValue.lowercased() {
case "application/json":
self = .json
default:
self = .other(rawValue)
}
}
package var rawValue: Swift.String {
internal var rawValue: Swift.String {
switch self {
case let .other(string):
return string
case .json:
return "application/json"
}
}
package static var allCases: [Self] {
internal static var allCases: [Self] {
[
.json
]
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTest/Sources/MockTransportClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ struct MockClientTransport: ClientTransport {
}

func run() async throws {
let client = Client(serverURL: try Servers.server1(), transport: MockClientTransport())
let client = Client(serverURL: try Servers.Server1.url(), transport: MockClientTransport())
_ = try await client.getGreeting(.init())
}
2 changes: 1 addition & 1 deletion IntegrationTest/Sources/MockTransportServer/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ class MockServerTransport: ServerTransport {
func initializeServer() throws {
let handler = SimpleAPIImpl()
let transport = MockServerTransport()
try handler.registerHandlers(on: transport, serverURL: Servers.server1())
try handler.registerHandlers(on: transport, serverURL: Servers.Server1.url())
}
Loading

0 comments on commit ae13b02

Please sign in to comment.