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
  • #7996
Closed
Open
Issue created Nov 22, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Elm] specifying x-enum-varnames causes malformed output

Created by: r-k-b

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Context: Server sends & expects int values for enum types, we want to use enum names in the Elm code.

Adding x-enum-varnames seems to be the recommended approach, but that leads to malformed Elm code being output.

E.g., in src/Api/Data.elm:

Expected:

intFromYesNoNa : YesNoNa -> Int
intFromYesNoNa model =
    case model of
        YesNoNaUnknown ->
            0

        YesNoNaYes ->
            1

        YesNoNaNo ->
            2

        YesNoNaNa ->
            999

Actual:

intFromYesNoNa : YesNoNa -> Int
intFromYesNoNa model =
    case model of
        YesNoNaUnknown ->
            Unknown

        YesNoNaYes ->
            Yes

        YesNoNaNo ->
            No

        YesNoNaNa ->
            Na
openapi-generator version

5.0.0-SNAPSHOT, from nixpkgs (commit f75c8753d80959f6bf63237748e799849c74179f). Doesn't seem like a regression.

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {"title": "Hippo API", "version": "v1"},
  "paths": {"/foo": {"get": {"tags": [], "summary": "x", "responses": {"200": {"description": "Success", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/YesNoNa"}}}}}}}},
  "components": {
    "schemas": {
      "YesNoNa": {
        "enum": [0, 1, 2, 999],
        "x-enum-varnames": ["Unknown", "Yes", "No", "Na"],
        "x-enum-descriptions": ["Unknown", "Yes", "No", "N/A"],
        "type": "integer"
      }
    }
  }
}
Generation Details
$ openapi-generator-cli generate -i ./enumnames.json -g elm
Steps to reproduce
  1. Generate as above
  2. elm make src/Api/Data.elm

or, using the latest master:

$ docker pull openapitools/openapi-generator-cli:latest
$ docker run -v /home/rkb/projects/namedenums/:/host -it openapitools/openapi-generator-cli:latest generate -i /host/enumnames.json -g elm -o /host/dckr
$ elm make dckr/src/Api/Data.elm
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/5794

Suggest a fix

Looks like #917 added enum names support to the Java generator, with an updateEnumVarsWithExtensions() method

Assignee
Assign to
Time tracking