Skip to content

feat: add 3.1 oneOf+const structure as enum #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

maddocnc
Copy link

@maddocnc maddocnc commented Sep 14, 2022

Introduce new enum style

{
"EnumViaOneOfNumeric": {
    "description": "OpenApi 3.1 style numeric enum",
    "type": "integer",
    "oneOf": [
        {
            "const": 0,
            "title": "SUCCESS",
            "description": "Success"
        },
        {
            "const": 1,
            "title": "WARNING",
            "description": "Warning"
        },
        {
            "const": 3,
            "title": "ERROR",
            "description": "Error"
        }
    ]
},
"EnumViaOneOfString": {
  "description": "OpenApi 3.1 style titled enum",
  "type": "string",
  "oneOf": [
      {
          "const": "SUCCESS",
          "title": "SUCCESS",
          "description": "Success"
      },
      {
          "const": "SUCCESS",
          "title": "WARNING",
          "description": "Warning"
      },
      {
          "const": "SUCCESS",
          "title": "ERROR",
          "description": "Error"
      }
  ]
}
}

which should be:

 /**
  * OpenApi 3.1 style numeric enum
  */
 export enum EnumViaOneOfNumeric {
     /**
      * Success
      */
     SUCCESS = 0,
     /**
      * Warning
      */
     WARNING = 1,
     /**
      * Error
      */
     ERROR = 3,
 }

 /**
  * OpenApi 3.1 style titled enum
  */
 export enum EnumViaOneOfString {
     /**
      * Success
      */
     SUCCESS = 'SUCCESS',
     /**
      * Warning
      */
     WARNING = 'SUCCESS',
     /**
      * Error
      */
     ERROR = 'SUCCESS',
 }

https://stackoverflow.com/questions/66465888/how-to-define-enum-mapping-in-openapi

@ferdikoomen ferdikoomen self-assigned this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants