OpenAPITools / OpenAPITools/openapi-generator

[BUG] List<Enum> response generates invalid Elm code

Open
#22,530 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master latest stable 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

When an endpoint returns an array of enum values the generate Elm code is incomplete and invalid.

Running the generator on the example file, the following is generated:


module Api.Request.SomethingController exposing
    ( somethingControllerGet
    )

import Api
import Api.Data exposing (..)
import Dict
import Http
import Json.Decode
import Json.Encode


somethingControllerGet : Api.Request (List String)
somethingControllerGet =
    Api.request
        "GET"
        "/api/something"
        []
        []
        []
        Nothing
        (Json.Decode.list somethingControllerResponseDecoder)

Multiple issues here:

  • The generated function return a List String. This should be a List Enum where Enum is the type specified in the spec.
  • There is no Api.Data generated.
  • The somethingControllerResponseDecoder does not exist.

The generator should either fail, fall back to String properly, or should generate the correct code. The generator should not produce code that will not compile in any case.

openapi-generator version

7.17.0

OpenAPI declaration file content or url

https://gist.github.com/bjornpijnacker/c66e6447404f91f0baa7f785aceba4ae

Generation Details

openapi-generator generate -i openapi.json -g elm -o output

Steps to reproduce

N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the documented openapi-generator command with the linked OpenAPI declaration and the elm generator. Inspect the generated Api.Request module and Api.Data output, then verify that the List response has a valid type and decoder and that the generated Elm code compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
elm, java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.