Skip to content

x-enum-varnames removes any underscores in the provided enum names #1906

Closed

Description

@jackspirou
          Great feature! In my testing, this removes any underscores in the provided enum names -- I assume this is a bug?

Originally posted by @saulhoward in #880 (comment)

Activity

  1. added theissue type on Apr 21, 2025
  2. github-actions commented on Apr 21, 2025

    @github-actions

    Thanks for the report!
    To help maintainers (or other users) help with triaging and fixing of the issue more easily, we need a Minimal Reproduction test case.
    Please follow the instructions, and then share a URL to the repository.
    We will not accept .zip files as reproductions, sorry!

  3. mromaszewicz commented on Nov 21, 2026

    @mromaszewicz
    Member

    As of #2683 there is an opt-in setting that emits the names in x-enum-varnames (and x-enumNames) exactly as you wrote them, instead of running them through the name normalizer.

    Add this to your configuration:

    output-options:
      naming:
        explicit-names: verbatim

    For example, with this schema:

    components:
      schemas:
        Status:
          type: integer
          enum: [1, 2]
          x-enum-varnames:
            - Enum_Test_1
            - Enum_Test_2

    the generated code is now:

    const (
    	Enum_Test_1 Status = 1
    	Enum_Test_2 Status = 2
    )

    With verbatim, each name has to be a valid Go identifier, and it is used as is: it is not capitalized, not renamed if it collides with another name, and not prefixed with the type name. The setting also applies to x-go-name on properties and parameters.

    If you only want the underscores kept, and still want the names normalized otherwise, output-options.naming.enum-values.keep-underscores: true does that, for enum values as well as for x-enum-varnames.

    The option is opt-in, so nothing changes unless you set it. It will be released in v2.9.0. Until then you need to use the main branch, for example:

    go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@main --config=config.yaml spec.yaml

    The other naming options are described in the README under Adjusting how names are normalized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:enumsbugreproduction:needed

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions