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

Generate @frozen enums for operation outputs and request/response bodies #109

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ extension TypesFileTranslator {
members: [Declaration]
) -> Declaration {
let bodyEnumDecl: Declaration = .enum(
isFrozen: true,
accessModifier: config.access,
name: typeName.shortSwiftName,
conformances: Constants.Operation.Output.conformances,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extension TypesFileTranslator {
}
let hasNoContent: Bool = bodyCases.isEmpty
let contentEnumDecl: Declaration = .enum(
isFrozen: true,
accessModifier: config.access,
name: bodyTypeName.shortSwiftName,
conformances: Constants.Operation.Body.conformances,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extension TypesFileTranslator {
}

let enumDecl: Declaration = .enum(
isFrozen: true,
accessModifier: config.access,
name: outputTypeName.shortSwiftName,
conformances: Constants.Operation.Output.conformances,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public enum Components {
}
/// Types generated from the `#/components/requestBodies` section of the OpenAPI document.
public enum RequestBodies {
public enum UpdatePetRequest: Sendable, Equatable, Hashable {
@frozen public enum UpdatePetRequest: Sendable, Equatable, Hashable {
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json`.
public struct jsonPayload: Codable, Equatable, Hashable, Sendable {
/// - Remark: Generated from `#/components/requestBodies/UpdatePetRequest/json/name`.
Expand Down Expand Up @@ -662,7 +662,7 @@ public enum Components {
}
/// Received HTTP response headers
public var headers: Components.Responses.ErrorBadRequest.Headers
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/json`.
public struct jsonPayload: Codable, Equatable, Hashable, Sendable {
/// - Remark: Generated from `#/components/responses/ErrorBadRequest/json/code`.
Expand Down Expand Up @@ -819,7 +819,7 @@ public enum Operations {
public init() {}
}
public var cookies: Operations.listPets.Input.Cookies
public enum Body: Sendable, Equatable, Hashable {}
@frozen public enum Body: Sendable, Equatable, Hashable {}
public var body: Operations.listPets.Input.Body?
/// Creates a new `Input`.
///
Expand All @@ -843,7 +843,7 @@ public enum Operations {
self.body = body
}
}
public enum Output: Sendable, Equatable, Hashable {
@frozen public enum Output: Sendable, Equatable, Hashable {
public struct Ok: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
public var My_Response_UUID: Swift.String
Expand All @@ -863,7 +863,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.listPets.Output.Ok.Headers
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Components.Schemas.Pets)
}
/// Received HTTP response body
Expand Down Expand Up @@ -894,7 +894,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.listPets.Output.Default.Headers
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Components.Schemas._Error)
}
/// Received HTTP response body
Expand Down Expand Up @@ -953,7 +953,7 @@ public enum Operations {
public init() {}
}
public var cookies: Operations.createPet.Input.Cookies
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Components.Schemas.CreatePetRequest)
}
public var body: Operations.createPet.Input.Body
Expand All @@ -979,7 +979,7 @@ public enum Operations {
self.body = body
}
}
public enum Output: Sendable, Equatable, Hashable {
@frozen public enum Output: Sendable, Equatable, Hashable {
public struct Created: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
public var X_Extra_Arguments: Components.Schemas.CodeError?
Expand All @@ -993,7 +993,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.createPet.Output.Created.Headers
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Components.Schemas.Pet)
}
/// Received HTTP response body
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public enum Operations {
public init() {}
}
public var cookies: Operations.probe.Input.Cookies
public enum Body: Sendable, Equatable, Hashable {}
@frozen public enum Body: Sendable, Equatable, Hashable {}
public var body: Operations.probe.Input.Body?
/// Creates a new `Input`.
///
Expand All @@ -1078,15 +1078,15 @@ public enum Operations {
self.body = body
}
}
public enum Output: Sendable, Equatable, Hashable {
@frozen public enum Output: Sendable, Equatable, Hashable {
public struct NoContent: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
/// Creates a new `Headers`.
public init() {}
}
/// Received HTTP response headers
public var headers: Operations.probe.Output.NoContent.Headers
public enum Body: Sendable, Equatable, Hashable {}
@frozen public enum Body: Sendable, Equatable, Hashable {}
/// Received HTTP response body
public var body: Operations.probe.Output.NoContent.Body?
/// Creates a new `NoContent`.
Expand Down Expand Up @@ -1168,15 +1168,15 @@ public enum Operations {
self.body = body
}
}
public enum Output: Sendable, Equatable, Hashable {
@frozen public enum Output: Sendable, Equatable, Hashable {
public struct NoContent: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
/// Creates a new `Headers`.
public init() {}
}
/// Received HTTP response headers
public var headers: Operations.updatePet.Output.NoContent.Headers
public enum Body: Sendable, Equatable, Hashable {}
@frozen public enum Body: Sendable, Equatable, Hashable {}
/// Received HTTP response body
public var body: Operations.updatePet.Output.NoContent.Body?
/// Creates a new `NoContent`.
Expand Down Expand Up @@ -1205,7 +1205,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.updatePet.Output.BadRequest.Headers
public enum Body: Sendable, Equatable, Hashable {
@frozen public enum Body: Sendable, Equatable, Hashable {
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/json`.
public struct jsonPayload: Codable, Equatable, Hashable, Sendable {
/// - Remark: Generated from `#/paths/pets/{petId}/PATCH/json/message`.
Expand Down Expand Up @@ -1277,7 +1277,7 @@ public enum Operations {
public init() {}
}
public var cookies: Operations.uploadAvatarForPet.Input.Cookies
public enum Body: Sendable, Equatable, Hashable { case binary(Foundation.Data) }
@frozen public enum Body: Sendable, Equatable, Hashable { case binary(Foundation.Data) }
public var body: Operations.uploadAvatarForPet.Input.Body
/// Creates a new `Input`.
///
Expand All @@ -1301,15 +1301,17 @@ public enum Operations {
self.body = body
}
}
public enum Output: Sendable, Equatable, Hashable {
@frozen public enum Output: Sendable, Equatable, Hashable {
public struct Ok: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
/// Creates a new `Headers`.
public init() {}
}
/// Received HTTP response headers
public var headers: Operations.uploadAvatarForPet.Output.Ok.Headers
public enum Body: Sendable, Equatable, Hashable { case binary(Foundation.Data) }
@frozen public enum Body: Sendable, Equatable, Hashable {
case binary(Foundation.Data)
}
/// Received HTTP response body
public var body: Operations.uploadAvatarForPet.Output.Ok.Body
/// Creates a new `Ok`.
Expand Down Expand Up @@ -1338,7 +1340,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.uploadAvatarForPet.Output.PreconditionFailed.Headers
public enum Body: Sendable, Equatable, Hashable { case json(Swift.String) }
@frozen public enum Body: Sendable, Equatable, Hashable { case json(Swift.String) }
/// Received HTTP response body
public var body: Operations.uploadAvatarForPet.Output.PreconditionFailed.Body
/// Creates a new `PreconditionFailed`.
Expand Down Expand Up @@ -1368,7 +1370,7 @@ public enum Operations {
}
/// Received HTTP response headers
public var headers: Operations.uploadAvatarForPet.Output.InternalServerError.Headers
public enum Body: Sendable, Equatable, Hashable { case text(Swift.String) }
@frozen public enum Body: Sendable, Equatable, Hashable { case text(Swift.String) }
/// Received HTTP response body
public var body: Operations.uploadAvatarForPet.Output.InternalServerError.Body
/// Creates a new `InternalServerError`.
Expand Down