openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

feat: add 3.1 oneOf+const structure as enum

Open maddocnc opened this issue 2 years ago • 0 comments

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

maddocnc avatar Sep 14 '22 17:09 maddocnc