Skip to content

Instantly share code, notes, and snippets.

@oboje
Last active August 9, 2024 21:31
Show Gist options
  • Save oboje/eb091d7270d5d3ff585ab2c41f1587c4 to your computer and use it in GitHub Desktop.
Save oboje/eb091d7270d5d3ff585ab2c41f1587c4 to your computer and use it in GitHub Desktop.
Models.swift
brew install openapi-generator
swift-openapi-generator generate \
--mode types \
--output-directory Generated \
model.yaml
openapi: 3.0.0
info:
title: Room Data API
version: 1.0.0
description: API specification for room and event data
paths:
/rooms/{roomId}:
get:
summary: Get room data
parameters:
- in: path
name: roomId
required: true
schema:
type: string
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/Room'
components:
schemas:
Room:
type: object
properties:
id:
type: string
name:
type: string
status:
type: string
enum: [public, private]
sharableLink:
type: string
format: uri
ownerId:
type: string
events:
type: array
items:
$ref: '#/components/schemas/Event'
usersIds:
type: array
items:
type: string
Event:
type: object
properties:
id:
type: string
status:
type: string
enum: [opened, closed]
title:
type: string
ownerId:
type: string
address:
$ref: '#/components/schemas/Address'
date:
type: number
format: double
description:
type: string
questions:
type: array
items:
$ref: '#/components/schemas/Question'
Address:
type: object
properties:
address:
type: string
coordinate:
$ref: '#/components/schemas/Coordinate'
Coordinate:
type: object
properties:
latitude:
type: number
format: double
longitude:
type: number
format: double
Question:
type: object
properties:
id:
type: string
title:
type: string
type:
type: string
enum: [boolean]
answers:
type: array
items:
$ref: '#/components/schemas/Answer'
Answer:
type: object
properties:
id:
type: string
value:
type: string
votes:
type: array
items:
$ref: '#/components/schemas/Vote'
Vote:
type: object
properties:
id:
type: string
userId:
type: string
date:
type: number
format: double
// Generated by swift-openapi-generator, do not modify.
@_spi(Generated) import OpenAPIRuntime
#if os(Linux)
@preconcurrency import struct Foundation.URL
@preconcurrency import struct Foundation.Data
@preconcurrency import struct Foundation.Date
#else
import struct Foundation.URL
import struct Foundation.Data
import struct Foundation.Date
#endif
/// A type that performs HTTP operations defined by the OpenAPI document.
internal protocol APIProtocol: Sendable {
/// Get room data
///
/// - Remark: HTTP `GET /rooms/{roomId}`.
/// - Remark: Generated from `#/paths//rooms/{roomId}/get`.
func get_sol_rooms_sol__lcub_roomId_rcub_(_ input: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input) async throws -> Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output
}
/// Convenience overloads for operation inputs.
extension APIProtocol {
/// Get room data
///
/// - Remark: HTTP `GET /rooms/{roomId}`.
/// - Remark: Generated from `#/paths//rooms/{roomId}/get`.
internal func get_sol_rooms_sol__lcub_roomId_rcub_(
path: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Path,
headers: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Headers = .init()
) async throws -> Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output {
try await get_sol_rooms_sol__lcub_roomId_rcub_(Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input(
path: path,
headers: headers
))
}
}
/// Server URLs defined in the OpenAPI document.
internal enum Servers {}
/// Types generated from the components section of the OpenAPI document.
internal enum Components {
/// Types generated from the `#/components/schemas` section of the OpenAPI document.
internal enum Schemas {
/// - Remark: Generated from `#/components/schemas/Room`.
internal struct Room: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Room/id`.
internal var id: Swift.String?
/// - Remark: Generated from `#/components/schemas/Room/name`.
internal var name: Swift.String?
/// - Remark: Generated from `#/components/schemas/Room/status`.
@frozen internal enum statusPayload: String, Codable, Hashable, Sendable, CaseIterable {
case _public = "public"
case _private = "private"
}
/// - Remark: Generated from `#/components/schemas/Room/status`.
internal var status: Components.Schemas.Room.statusPayload?
/// - Remark: Generated from `#/components/schemas/Room/sharableLink`.
internal var sharableLink: Swift.String?
/// - Remark: Generated from `#/components/schemas/Room/ownerId`.
internal var ownerId: Swift.String?
/// - Remark: Generated from `#/components/schemas/Room/events`.
internal var events: [Components.Schemas.Event]?
/// - Remark: Generated from `#/components/schemas/Room/usersIds`.
internal var usersIds: [Swift.String]?
/// Creates a new `Room`.
///
/// - Parameters:
/// - id:
/// - name:
/// - status:
/// - sharableLink:
/// - ownerId:
/// - events:
/// - usersIds:
internal init(
id: Swift.String? = nil,
name: Swift.String? = nil,
status: Components.Schemas.Room.statusPayload? = nil,
sharableLink: Swift.String? = nil,
ownerId: Swift.String? = nil,
events: [Components.Schemas.Event]? = nil,
usersIds: [Swift.String]? = nil
) {
self.id = id
self.name = name
self.status = status
self.sharableLink = sharableLink
self.ownerId = ownerId
self.events = events
self.usersIds = usersIds
}
internal enum CodingKeys: String, CodingKey {
case id
case name
case status
case sharableLink
case ownerId
case events
case usersIds
}
}
/// - Remark: Generated from `#/components/schemas/Event`.
internal struct Event: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Event/id`.
internal var id: Swift.String?
/// - Remark: Generated from `#/components/schemas/Event/status`.
@frozen internal enum statusPayload: String, Codable, Hashable, Sendable, CaseIterable {
case opened = "opened"
case closed = "closed"
}
/// - Remark: Generated from `#/components/schemas/Event/status`.
internal var status: Components.Schemas.Event.statusPayload?
/// - Remark: Generated from `#/components/schemas/Event/title`.
internal var title: Swift.String?
/// - Remark: Generated from `#/components/schemas/Event/ownerId`.
internal var ownerId: Swift.String?
/// - Remark: Generated from `#/components/schemas/Event/address`.
internal var address: Components.Schemas.Address?
/// - Remark: Generated from `#/components/schemas/Event/date`.
internal var date: Swift.Double?
/// - Remark: Generated from `#/components/schemas/Event/description`.
internal var description: Swift.String?
/// - Remark: Generated from `#/components/schemas/Event/questions`.
internal var questions: [Components.Schemas.Question]?
/// Creates a new `Event`.
///
/// - Parameters:
/// - id:
/// - status:
/// - title:
/// - ownerId:
/// - address:
/// - date:
/// - description:
/// - questions:
internal init(
id: Swift.String? = nil,
status: Components.Schemas.Event.statusPayload? = nil,
title: Swift.String? = nil,
ownerId: Swift.String? = nil,
address: Components.Schemas.Address? = nil,
date: Swift.Double? = nil,
description: Swift.String? = nil,
questions: [Components.Schemas.Question]? = nil
) {
self.id = id
self.status = status
self.title = title
self.ownerId = ownerId
self.address = address
self.date = date
self.description = description
self.questions = questions
}
internal enum CodingKeys: String, CodingKey {
case id
case status
case title
case ownerId
case address
case date
case description
case questions
}
}
/// - Remark: Generated from `#/components/schemas/Address`.
internal struct Address: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Address/address`.
internal var address: Swift.String?
/// - Remark: Generated from `#/components/schemas/Address/coordinate`.
internal var coordinate: Components.Schemas.Coordinate?
/// Creates a new `Address`.
///
/// - Parameters:
/// - address:
/// - coordinate:
internal init(
address: Swift.String? = nil,
coordinate: Components.Schemas.Coordinate? = nil
) {
self.address = address
self.coordinate = coordinate
}
internal enum CodingKeys: String, CodingKey {
case address
case coordinate
}
}
/// - Remark: Generated from `#/components/schemas/Coordinate`.
internal struct Coordinate: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Coordinate/latitude`.
internal var latitude: Swift.Double?
/// - Remark: Generated from `#/components/schemas/Coordinate/longitude`.
internal var longitude: Swift.Double?
/// Creates a new `Coordinate`.
///
/// - Parameters:
/// - latitude:
/// - longitude:
internal init(
latitude: Swift.Double? = nil,
longitude: Swift.Double? = nil
) {
self.latitude = latitude
self.longitude = longitude
}
internal enum CodingKeys: String, CodingKey {
case latitude
case longitude
}
}
/// - Remark: Generated from `#/components/schemas/Question`.
internal struct Question: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Question/id`.
internal var id: Swift.String?
/// - Remark: Generated from `#/components/schemas/Question/title`.
internal var title: Swift.String?
/// - Remark: Generated from `#/components/schemas/Question/type`.
@frozen internal enum _typePayload: String, Codable, Hashable, Sendable, CaseIterable {
case boolean = "boolean"
}
/// - Remark: Generated from `#/components/schemas/Question/type`.
internal var _type: Components.Schemas.Question._typePayload?
/// - Remark: Generated from `#/components/schemas/Question/answers`.
internal var answers: [Components.Schemas.Answer]?
/// Creates a new `Question`.
///
/// - Parameters:
/// - id:
/// - title:
/// - _type:
/// - answers:
internal init(
id: Swift.String? = nil,
title: Swift.String? = nil,
_type: Components.Schemas.Question._typePayload? = nil,
answers: [Components.Schemas.Answer]? = nil
) {
self.id = id
self.title = title
self._type = _type
self.answers = answers
}
internal enum CodingKeys: String, CodingKey {
case id
case title
case _type = "type"
case answers
}
}
/// - Remark: Generated from `#/components/schemas/Answer`.
internal struct Answer: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Answer/id`.
internal var id: Swift.String?
/// - Remark: Generated from `#/components/schemas/Answer/value`.
internal var value: Swift.String?
/// - Remark: Generated from `#/components/schemas/Answer/votes`.
internal var votes: [Components.Schemas.Vote]?
/// Creates a new `Answer`.
///
/// - Parameters:
/// - id:
/// - value:
/// - votes:
internal init(
id: Swift.String? = nil,
value: Swift.String? = nil,
votes: [Components.Schemas.Vote]? = nil
) {
self.id = id
self.value = value
self.votes = votes
}
internal enum CodingKeys: String, CodingKey {
case id
case value
case votes
}
}
/// - Remark: Generated from `#/components/schemas/Vote`.
internal struct Vote: Codable, Hashable, Sendable {
/// - Remark: Generated from `#/components/schemas/Vote/id`.
internal var id: Swift.String?
/// - Remark: Generated from `#/components/schemas/Vote/userId`.
internal var userId: Swift.String?
/// - Remark: Generated from `#/components/schemas/Vote/date`.
internal var date: Swift.Double?
/// Creates a new `Vote`.
///
/// - Parameters:
/// - id:
/// - userId:
/// - date:
internal init(
id: Swift.String? = nil,
userId: Swift.String? = nil,
date: Swift.Double? = nil
) {
self.id = id
self.userId = userId
self.date = date
}
internal enum CodingKeys: String, CodingKey {
case id
case userId
case date
}
}
}
/// Types generated from the `#/components/parameters` section of the OpenAPI document.
internal enum Parameters {}
/// Types generated from the `#/components/requestBodies` section of the OpenAPI document.
internal enum RequestBodies {}
/// Types generated from the `#/components/responses` section of the OpenAPI document.
internal enum Responses {}
/// Types generated from the `#/components/headers` section of the OpenAPI document.
internal enum Headers {}
}
/// API operations, with input and output types, generated from `#/paths` in the OpenAPI document.
internal enum Operations {
/// Get room data
///
/// - Remark: HTTP `GET /rooms/{roomId}`.
/// - Remark: Generated from `#/paths//rooms/{roomId}/get`.
internal enum get_sol_rooms_sol__lcub_roomId_rcub_ {
internal static let id: Swift.String = "get/rooms/{roomId}"
internal struct Input: Sendable, Hashable {
/// - Remark: Generated from `#/paths/rooms/{roomId}/GET/path`.
internal struct Path: Sendable, Hashable {
/// - Remark: Generated from `#/paths/rooms/{roomId}/GET/path/roomId`.
internal var roomId: Swift.String
/// Creates a new `Path`.
///
/// - Parameters:
/// - roomId:
internal init(roomId: Swift.String) {
self.roomId = roomId
}
}
internal var path: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Path
/// - Remark: Generated from `#/paths/rooms/{roomId}/GET/header`.
internal struct Headers: Sendable, Hashable {
internal var accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.get_sol_rooms_sol__lcub_roomId_rcub_.AcceptableContentType>]
/// Creates a new `Headers`.
///
/// - Parameters:
/// - accept:
internal init(accept: [OpenAPIRuntime.AcceptHeaderContentType<Operations.get_sol_rooms_sol__lcub_roomId_rcub_.AcceptableContentType>] = .defaultValues()) {
self.accept = accept
}
}
internal var headers: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Headers
/// Creates a new `Input`.
///
/// - Parameters:
/// - path:
/// - headers:
internal init(
path: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Path,
headers: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Input.Headers = .init()
) {
self.path = path
self.headers = headers
}
}
@frozen internal enum Output: Sendable, Hashable {
internal struct Ok: Sendable, Hashable {
/// - Remark: Generated from `#/paths/rooms/{roomId}/GET/responses/200/content`.
@frozen internal enum Body: Sendable, Hashable {
/// - Remark: Generated from `#/paths/rooms/{roomId}/GET/responses/200/content/application\/json`.
case json(Components.Schemas.Room)
/// The associated value of the enum case if `self` is `.json`.
///
/// - Throws: An error if `self` is not `.json`.
/// - SeeAlso: `.json`.
internal var json: Components.Schemas.Room {
get throws {
switch self {
case let .json(body):
return body
}
}
}
}
/// Received HTTP response body
internal var body: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output.Ok.Body
/// Creates a new `Ok`.
///
/// - Parameters:
/// - body: Received HTTP response body
internal init(body: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output.Ok.Body) {
self.body = body
}
}
/// Successful response
///
/// - Remark: Generated from `#/paths//rooms/{roomId}/get/responses/200`.
///
/// HTTP response code: `200 ok`.
case ok(Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output.Ok)
/// The associated value of the enum case if `self` is `.ok`.
///
/// - Throws: An error if `self` is not `.ok`.
/// - SeeAlso: `.ok`.
internal var ok: Operations.get_sol_rooms_sol__lcub_roomId_rcub_.Output.Ok {
get throws {
switch self {
case let .ok(response):
return response
default:
try throwUnexpectedResponseStatus(
expectedStatus: "ok",
response: self
)
}
}
}
/// Undocumented response.
///
/// 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 {
case json
case other(Swift.String)
internal init?(rawValue: Swift.String) {
switch rawValue.lowercased() {
case "application/json":
self = .json
default:
self = .other(rawValue)
}
}
internal var rawValue: Swift.String {
switch self {
case let .other(string):
return string
case .json:
return "application/json"
}
}
internal static var allCases: [Self] {
[
.json
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment