Skip to content

Modify generated enum keys #2116

@dlohvinov

Description

@dlohvinov

Hi!

Is there a way to somehow modify generated enum keys except doing it in openapi schema?

I want to convert enum keys from snake_case to camelCase. Original enum values are snake_case, so I need to convert only keys.

I have an openapi v3 schema, it looks like this:

#...
components:
    schemas:
        someSchemaName:
              enum:
                  - enable_2fa
                  - export_settings
              // #...
#...

And generated enum looks like this:

export const someSchemaName = {
	enable_2fa: 'enable_2fa',
	export_settings: 'export_settings', // but i want exportSettings: 'export_settings'
} as const;

I see that I can set enum names manually orval docs in openapi file, but openapi file is generated too, so editing it is not an option.

It looks like getEnumNames doesn't support any enum keys modification configs, but maybe there is a workaround for this?.. 🤔

Btw I'm struggling to configure a flow to convert snake_case'd openapi source file to camelCase'd generated files, and it feels like pain. I use openapi-format as a workaround to change casings, but it still feels so complicated to work with it.
Maybe there are some easier ways to convert casings in orval?...

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions