swagger-api / swagger-api/swagger-codegen
[Swift] Empty Struct Generated Which Should be a Typealias
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
swagger-codegen does not create a correct Swift representation for a simple Model (from a schema definition) which would be ideally generated as a Swift typealias.
Swagger-codegen version
This is the current version used in website: 3.0.10 (current tag)
openapi: 3.0.0
Swagger declaration file content or url
The following yaml snippet (openapi: 3.0.0) shows how the model is defined in section components/schemas:
components:
schemas:
Id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
description: A unique identifier.
This is basically a type String which has a special format (UUID).
Command line used for generation
The code generator has been invoked from the Export feature from the website app.swaggerhub.com:
Export -> Client SDK -> swift4
Expected
Swift:
typealias Id = String
Actual
//
// Id.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import Foundation
/** An ID uniquely identifying the object. */
public struct Id: Codable {
}
As you can see, this is an empty struct and can not be used in any way.
Steps to reproduce
Well, this would require to setup a basic swagger spec and include the schema in the components section, then generate the code.
Related issues/PRs
Almost the same issue, just differently generated code containing no usable properties, and this was "swagger 2.0":
https://github.com/swagger-api/swagger-codegen/issues/6946
Suggest a fix/enhancement
My preferred representation in Swift:
typealias Id = String
Hint: a quick check for the language Kotlin showed that there is no issue like this as in Swift. For Kotlin, actually a typealias will be generated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the OpenAPI 3.0 schema with the website's Export → Client SDK → swift4 entry point, then trace the Swift generator output for the Id model. Done means the generated Swift representation is a usable typealias to String rather than an empty struct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100