Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #652
Closed
Open
Issue created Jul 26, 2018 by Administrator@rootContributor

[SWIFT4] Default values for ENUMs are using strings instead of the enum

Created by: grEvenX

Description

OpenAPI 3.0.0 has support for strings in enum format. The Swift4 generator maps these into enum in the Swift code which works fine. However if you provide a default value in the OpenAPI document, the values for the properties of enum types are set as strings instead of the enum which again causes the compiler to fail.

openapi-generator version

3.1.2

OpenAPI declaration file content or url

https://gist.github.com/grEvenX/76d508f2933456894492c38410b1ac49

Command line used for generation

docker run --rm -v $(pwd)/generated:/out openapitools/openapi-generator-cli:latest generate -i https://gist.githubusercontent.com/grEvenX/76d508f2933456894492c38410b1ac49/raw/6e3a93cc3bc219815769a21fdcad84628ab0af59/example.yaml -g swift4 -o /out/swift4

Steps to reproduce
  1. Run the following docker command to generate a Swift4 client with the example YAML using enums and default values
  2. Inspect the output of generated/swift4/OpenAPIClient/Classes/OpenAPIs/Models/NewPet.swift
Suggest a fix/enhancement

The generated model contains the line:

public enum Animal: String, Codable {
  case dog = "dog"
  case cat = "cat"
}
public var animal: Animal? = "cat"

The correct value that should be assigned to animal in this case is:

public var animal: Animal? = .cat
Assignee
Assign to
Time tracking