Skip to content
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

Full compatibility with the "ExistentialAny" upcoming feature #99

Merged
merged 7 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ struct ParameterDescription: Equatable, Codable {
/// For example, in `bar baz: String = "hi"`, `name` is `baz`.
var name: String? = nil

/// The existential any keyword.
///
/// For example, in `bar baz: any Client = ...`, `any` is the keyword referred to here.
var anyKeyword: Bool = false

/// The type name of the parameter.
///
/// For example, in `bar baz: String = "hi"`, `type` is `String`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ struct TextBasedRenderer: RendererProtocol {
}
}
words.append(":")
if parameterDescription.anyKeyword {
words.append("any")
}
words.append(parameterDescription.type)
if let defaultValue = parameterDescription.defaultValue {
words.append("=")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ struct ClientFileTranslator: FileTranslator {
type: Constants.Configuration.typeName,
defaultValue: .dot("init").call([])
),
.init(label: "transport", type: Constants.Client.Transport.typeName),
.init(
label: "transport",
anyKeyword: true,
type: Constants.Client.Transport.typeName
),
.init(
label: "middlewares",
type: "[\(Constants.Client.Middleware.typeName)]",
type: "[any \(Constants.Client.Middleware.typeName)]",
defaultValue: .literal(.array([]))
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ fileprivate extension FileTranslator {
accessModifier: config.access,
kind: .function(name: "encode"),
parameters: [
.init(label: "to", name: "encoder", type: "Encoder")
.init(label: "to", name: "encoder", anyKeyword: true, type: "Encoder")
],
keywords: [
.throws
Expand All @@ -610,7 +610,7 @@ fileprivate extension FileTranslator {
accessModifier: config.access,
kind: .initializer,
parameters: [
.init(label: "from", name: "decoder", type: "Decoder")
.init(label: "from", name: "decoder", anyKeyword: true, type: "Decoder")
],
keywords: [
.throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ServerFileTranslator: FileTranslator {
.init(
label: "on",
name: "transport",
anyKeyword: true,
type: Constants.Server.Transport.typeName
),
.init(
Expand All @@ -93,7 +94,7 @@ struct ServerFileTranslator: FileTranslator {
),
.init(
label: "middlewares",
type: "[\(Constants.Server.Middleware.typeName)]",
type: "[any \(Constants.Server.Middleware.typeName)]",
defaultValue: .literal(.array([]))
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public struct Client: APIProtocol {
public init(
serverURL: URL,
configuration: Configuration = .init(),
transport: ClientTransport,
middlewares: [ClientMiddleware] = []
transport: any ClientTransport,
middlewares: [any ClientMiddleware] = []
) {
self.client = .init(
serverURL: serverURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ extension APIProtocol {
/// - configuration: A set of configuration values for the server.
/// - middlewares: A list of middlewares to call before the handler.
public func registerHandlers(
on transport: ServerTransport,
on transport: any ServerTransport,
serverURL: URL = .defaultOpenAPIServerURL,
configuration: Configuration = .init(),
middlewares: [ServerMiddleware] = []
middlewares: [any ServerMiddleware] = []
) throws {
let server = UniversalServer(
serverURL: serverURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ public enum Components {
/// - Parameters:
/// - value1:
public init(value1: Components.Schemas.ExtraInfo) { self.value1 = value1 }
public init(from decoder: Decoder) throws { value1 = try .init(from: decoder) }
public func encode(to encoder: Encoder) throws { try value1.encode(to: encoder) }
public init(from decoder: any Decoder) throws { value1 = try .init(from: decoder) }
public func encode(to encoder: any Encoder) throws {
try value1.encode(to: encoder)
}
}
/// Extra information about the error.
///
Expand Down Expand Up @@ -268,7 +270,7 @@ public enum Components {
/// - foo:
public init(foo: Swift.String? = nil) { self.foo = foo }
public enum CodingKeys: String, CodingKey { case foo }
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
foo = try container.decodeIfPresent(Swift.String.self, forKey: .foo)
try decoder.ensureNoAdditionalProperties(knownKeys: ["foo"])
Expand All @@ -293,12 +295,12 @@ public enum Components {
self.additionalProperties = additionalProperties
}
public enum CodingKeys: String, CodingKey { case foo }
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
foo = try container.decodeIfPresent(Swift.String.self, forKey: .foo)
additionalProperties = try decoder.decodeAdditionalProperties(knownKeys: ["foo"])
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(foo, forKey: .foo)
try encoder.encodeAdditionalProperties(additionalProperties)
Expand All @@ -323,12 +325,12 @@ public enum Components {
self.additionalProperties = additionalProperties
}
public enum CodingKeys: String, CodingKey { case foo }
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
foo = try container.decodeIfPresent(Swift.String.self, forKey: .foo)
additionalProperties = try decoder.decodeAdditionalProperties(knownKeys: ["foo"])
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(foo, forKey: .foo)
try encoder.encodeAdditionalProperties(additionalProperties)
Expand Down Expand Up @@ -374,11 +376,11 @@ public enum Components {
self.value1 = value1
self.value2 = value2
}
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
value1 = try .init(from: decoder)
value2 = try .init(from: decoder)
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
try value1.encode(to: encoder)
try value2.encode(to: encoder)
}
Expand Down Expand Up @@ -412,7 +414,7 @@ public enum Components {
self.value1 = value1
self.value2 = value2
}
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
value1 = try? .init(from: decoder)
value2 = try? .init(from: decoder)
try DecodingError.verifyAtLeastOneSchemaIsNotNil(
Expand All @@ -421,7 +423,7 @@ public enum Components {
codingPath: decoder.codingPath
)
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
try value1?.encode(to: encoder)
try value2?.encode(to: encoder)
}
Expand Down Expand Up @@ -449,7 +451,7 @@ public enum Components {
case case4(Components.Schemas.OneOfAny.Case4Payload)
/// Parsed a case that was not defined in the OpenAPI document.
case undocumented(OpenAPIRuntime.OpenAPIValueContainer)
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
do {
self = .case1(try .init(from: decoder))
return
Expand All @@ -470,7 +472,7 @@ public enum Components {
let value = try container.decode(OpenAPIRuntime.OpenAPIValueContainer.self)
self = .undocumented(value)
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
switch self {
case let .case1(value): try value.encode(to: encoder)
case let .case2(value): try value.encode(to: encoder)
Expand Down Expand Up @@ -540,11 +542,11 @@ public enum Components {
self.value1 = value1
self.value2 = value2
}
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
value1 = try .init(from: decoder)
value2 = try .init(from: decoder)
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
try value1.encode(to: encoder)
try value2.encode(to: encoder)
}
Expand All @@ -558,7 +560,7 @@ public enum Components {
/// Parsed a case that was not defined in the OpenAPI document.
case undocumented(OpenAPIRuntime.OpenAPIObjectContainer)
public enum CodingKeys: String, CodingKey { case kind }
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let discriminator = try container.decode(String.self, forKey: .kind)
switch discriminator {
Expand All @@ -570,7 +572,7 @@ public enum Components {
self = .undocumented(value)
}
}
public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
switch self {
case let .Walk(value): try value.encode(to: encoder)
case let .MessagedExercise(value): try value.encode(to: encoder)
Expand All @@ -583,7 +585,7 @@ public enum Components {
public struct DeprecatedObject: Codable, Equatable, Hashable, Sendable {
/// Creates a new `DeprecatedObject`.
public init() {}
public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
try decoder.ensureNoAdditionalProperties(knownKeys: [])
}
}
Expand Down