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
  • #2585
Closed
Open
Issue created Apr 03, 2019 by Administrator@rootContributor

[Elm] [REQ] Enum parameters in urls

Created by: andys8

Is your feature request related to a problem? Please describe.

Enums are supported by swagger and the openapi generator. If there is a string enum as part of a body it will be serialized and de-serialized as expected. When the enum is a query param, it will be handled as a string. The elm request data is typed to string and the user has to manually convert the union type / custom type to a string and can potentially introduce errors.

Describe the solution you'd like

If there is a path param of type enum string, the generated code should implement the serialization to string.

Example

Rest endpoint

E.g. /users?status=WAITING

    @GetMapping
    public List<UserResponse> getAll(
            @RequestParam(value = "status", required = false) @Nullable final Status status
    ) { }

Open Api Spec.

status is "enum": ["IDLE", "OPEN", "IN_PROGRESS", "WAITING", "DONE"].

    "/users": {
      "get": {
        "tags": ["user-controller"],
        "summary": "getAll",
        "operationId": "getAll",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "status",
            "required": false,
            "type": "string",
            "enum": ["IDLE", "OPEN", "IN_PROGRESS", "WAITING", "DONE"]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "type": "array",
              "items": { "$ref": "#/definitions/User" }
            }
          },
          "401": { "description": "Unauthorized" },
          "403": { "description": "Forbidden" },
          "404": { "description": "Not Found" }
        },
        "deprecated": false
      }
    }

Generated elm request code

getAll :
    { onSend : Result Http.Error (List User) -> msg
    , basePath : String
    , status : Maybe String
    }
    -> Cmd msg
getAll params =
    Http.request
        { method = "GET"
        , headers = []
        , url =
            Url.crossOrigin params.basePath
                [ "users" ]
                (List.filterMap identity [ Maybe.map (Url.string "status") params.status ])
        , body = Http.emptyBody
        , expect = Http.expectJson params.onSend (Decode.list User.decoder)
        , timeout = Just 30000
        , tracker = Nothing
        }

@eriktim

Assignee
Assign to
Time tracking