Closed
Description
Hello, I'm new to using openapi-generator. Like the title says, I ran the command below to generate a Swift Client:
openapi-generator generate -i openapi.yaml -g swift5 -o Generated/
All the models generated only contain type AnyCodable? even though I explicitly defined them in my yaml file. Is there a way to configure this so that only specified types are used? I used version 3.0.3 before this and it worked fine. However, now I need to implement an interceptor for refresh token logic using taskCompletionShouldRetry.
Generated Model:
public struct ErrorResponseBody: Codable, JSONEncodable, Hashable {
public var errorCode: AnyCodable? // <-- TODO: Want errorCode and detail to both be type String.
public var detail: AnyCodable?
public init(errorCode: AnyCodable?, detail: AnyCodable? = nil) {
self.errorCode = errorCode
self.detail = detail
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case errorCode = "error_code"
case detail
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(errorCode, forKey: .errorCode)
try container.encodeIfPresent(detail, forKey: .detail)
}
}
Yaml file:
openapi: '3.1.0'
info:
title: TestAPI
version: 0.1.0
paths:
"/session":
post:
tags:
- chat
summary: Start Session
description: Start a new chat session. A new session id is returned.
operationId: start_session
parameters:
- name: request-id
in: header
required: true
schema:
type: string
title: Request-Id
- name: access_token
in: header
required: true
schema:
type: string
title: Access Token
responses:
'200':
description: Successful Response
content:
application/json:
schema:
"$ref": "#/components/schemas/ChatResponseBody-Output"
'400':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Bad Request
'401':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Unauthorized
'404':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Not Found
'422':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Unprocessable Entity
'500':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Internal Server Error
'503':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Service Unavailable
'504':
content:
application/json:
schema:
"$ref": "#/components/schemas/ErrorResponseBody"
description: Gateway Timeout
components:
schemas:
ChatResponseBody-Output:
properties:
role:
"$ref": "#/components/schemas/ChatRole"
user_id:
type: string
title: User Id
message_id:
type: string
title: Message Id
session_id:
type: string
title: Session Id
message:
type: string
title: Message
timestamp:
type: string
title: Timestamp
payload:
type: object
title: Payload
type: object
required:
- role
- user_id
- message_id
- session_id
- message
- timestamp
title: ChatResponseBody
ErrorResponseBody:
properties:
error_code:
type: string
title: Error Code
detail:
type: string
title: Detail
type: object
required:
- error_code
title: ErrorResponseBody
ChatRole:
type: string
enum:
- assistant
- user
title: ChatRole
Thank you.
cc: @4brunu