Enum Names

The OpenAPI schema can be extended to include enum names for enum values. This will let Orval generate enums with correct names.

Example of OpenAPI schema

openapi: '3.1.0'
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
components:
schemas:
MyObject:
type: object
properties:
myEnum:
type: number
enum:
- 1
- 2
- 3
- 4
x-enumNames:
- One
- Two
- Three
- Four

The enum generated by Orval will as follows:

export const MyEnum {
One: 1,
Two: 2,
Three: 3,
Four: 4
} as const;

Valid Enum Name Extensions

Orval recognizes the following extensions:

  • x-enumNames
  • x-enumnames
  • x-enum-varnames
Was this page helpful?