OpenAPITools / OpenAPITools/openapi-generator

[BUG] [sprind-cloud] Multiple response bodies generates invalid code

Open
#8,700 1 comment 1 reaction 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

Description

If multiple response bodies are specified, the producer annotation is filled incorrectly and a spring boot application cannot be started.

openapi-generator version

4.3.1 and 5.0.1

OpenAPI declaration file content or url
  /foo:
    post:
      operationId: createFoo
      ...
      responses:
        '200':
          description: "Return"
          content:
                    text/plain:
                      schema:
                        type: string
                    text/html:
                      schema:
                        type: string

Generated java code

@RequestMapping(produces = "text/plain,text/html")
public ResponseEntity<Void> createFoo(...) {...}
Generation Details

Maven plugin

      <configuration>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
                                <library>spring-cloud</library>
                                <java8>true</java8>
                                <dateLibrary>java8</dateLibrary>
                                <useOptional>true</useOptional>
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <useBeanValidation>true</useBeanValidation>
                            </configOptions>
Steps to reproduce

Use multiple response bodies:

Expected code is not a comma separated String. Spring needs a proper list of producers

@RequestMapping(produces = {"text/plain","text/html"})
public ResponseEntity<Void> createFoo(...) {...}

see https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html#produces--

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

Start with the Spring generator's handling of response media types and reproduce the issue using the provided OpenAPI YAML and Maven spring-cloud configuration. Done means generated Java uses valid array syntax for multiple produces values and the resulting Spring Boot application starts successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.