8000 Open enum support · Issue #374 · cjbooms/fabrikt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Open enum support #374
Open
Open
@nsprod

Description

@nsprod

Hey 👋

I'm using an OpenAPI specification that makes use of anyOf to implement the "open enum pattern".

This is what I'm doing:

openapi: 3.0.0
info:
paths:
components:
  schemas:
    SomeObj:
      type: object
      properties:
        open_enum:
          $ref: '#/components/schemas/OpenEnum'
        close_enum:
          $ref: '#/components/schemas/CloseEnum'
    OpenEnum:
      anyOf:
        - type: string
          enum:
            - foo
            - bar
            - baz
        - type: string

    CloseEnum:
      type: string
      enum:
        - foo
        - bar
        - baz

Generated model:

@Serializable
public data class SomeObj(
  @SerialName("open_enum")
  public val openEnum: String? = null,
  @SerialName("close_enum")
  public val closeEnum: CloseEnum? = null,
)

When using kotlinx as serialization library the OpenEnum model is not generated and the property using this schema is of type String. Does fabrikt (+ kotlinx) have support for anyOf?

This pattern is very interesting to force the client (mobile app for eg) to handle unknown cases. It allows more flexibility for the server to add new cases without breaking the API contract or having to version each new addition to the enum

Example taken from the Swift OpenAPI generator documentation: https://swiftpackageindex.com/apple/swift-openapi-generator/1.7.0/documentation/swift-openapi-generator/useful-openapi-patterns#Open-enums-and-oneOfs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0