Skip to content

Merging oneOf with many compatible enums of a single value #567

Closed as not planned
@benjaminleonard

Description

@benjaminleonard

Question

I'm no expert in Swift nor OpenAPI, so forgive any sizeable gaps in my understanding.

I'm working with a schema that has a group of oneOf enums. It's structured like that to allow annotations directly on the enum (OAI/OpenAPI-Specification#348 (comment)).

Unfortunately the current implementation of swift-openapi-generator generates somewhat verbose and less intuitive usage types for these.

Input:

"InstanceState": {
  "oneOf": [
    {
      "description": "The instance is being created.",
      "type": "string",
      "enum": [
        "creating"
      ]
    },
  ]
}

Output:

@frozen internal enum InstanceState: Codable, Hashable, Sendable {
    /// The instance is being created.
    ///
    /// - Remark: Generated from `#/components/schemas/InstanceState/case1`.
    @frozen internal enum Case1Payload: String, Codable, Hashable, Sendable, CaseIterable {
        case creating = "creating"
    }

Which means I end up needing to write something like: run_state: .case1(.created) or run_state: .case9(.failed).

Is this something that the generator can handle? Or should I be using it differently?

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/supportAdopter support requests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions