Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4059
Closed
Open
Issue created Oct 04, 2019 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG][ALL GENERATORS] enums with x-enum-varnames do not respect enumPropertyNaming

Created by: lemoinem

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue? YES
  • Have you validated the input using an OpenAPI validator (example)? YES
  • What's the version of OpenAPI Generator used? 4.1.2
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

If an API is relying on x-enum-varnames to provide enums' names, enumPropertyNaming is not applied.

This is because the DefaultGenerator does not use toEnumVarName to process x-enum-varnames extensions.

openapi-generator version

4.1.2 (still present in master)

OpenAPI declaration file content or url
openapi: 3.0.1
info:
    title: 'ping test'
    version: '1.0'
servers:
    - url: 'http://localhost:9999/'
paths:
    /ping:
        get:
            operationId: pingGet
            responses: {'201': {description: OK}}
components:
    schemas:
        WeatherType: null
            type: integer
            format: int32
            enum:
                - 42
                - 18
                - 56
            x-enum-varnames:
                - Sunny
                - Cloudy
                - Rainy
Command line used for generation

generate -i api.yaml -g kotlin -o output -p enumPropertyNaming=UPPERCASE

Steps to reproduce

Generate, open WeatherType.kt

Expected output:

enum class WeatherType(val rawValue: kotlin.Int) {
    SUNNY(42),
    CLOUDY(18),
    RAINY(56);
}

Actual output:

enum class WeatherType(val rawValue: kotlin.Int) {
    Sunny(42),
    Cloudy(18),
    Rainy(56);
}
Related issues/PRs

None

Suggest a fix

When processing x-enum-varnames in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L4346-L4361 We should make sure to call toEnumVarName to correctly generate the name. Another solution could be to delay to call to toEnumVarName until after x-enum-varnames has been processed in postProcessModelsEnum (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L372-L378)

Assignee
Assign to
Time tracking