swagger-api / swagger-api/swagger-codegen

[Spring] Bug incorrect response entity object when generating oneOf

Open
#10,575 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Incorrect response entity object when generating oneOf.
Codegen generated an model interface, called OneOfinlineResponse200.
3 other classes extended OneOfinlineResponse200,
including InlineResponse200, Token, Error

However, Codegen generated an api interface, called AuthenticationApi
Inside this class, there is a function , ResponseEntity<InlineResponse200>login

When implementing AuthenticationApi interface, I can only response InlineResponse200, but not Token or Error...

Swagger-codegen version

3.0.23

Swagger declaration file content or url
paths:
  /authentication:
    post:
      summary: Authenticate an user
      operationId: login
      requestBody:
        description: Authenticate an user
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
        required: true
      responses:
        200:
          description: 'AAB'
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Error'
                  - $ref: '#/components/schemas/Token'
components:
  schemas:
    Error:
      type: object
      required:
        - message
        - code
      properties:
        message:
          type: string
        code:
          type: string
    User:
      type: object
      properties:
        userName:
          type: string
        userPassword:
          type: string
          format: password
    Token:
      type: object
      properties:
        token:
          type: string
Command line used for generation
<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.23</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>
                   xxxxxx/openapi.yml
                </inputSpec>
                <language>spring</language>
                <apiPackage>xxxx</apiPackage>
                <modelPackage>xxxxx</modelPackage>
                <supportingFilesToGenerate>
                    ApiUtil.java
                </supportingFilesToGenerate>
                <configOptions>
                    <sourceFolder>src/main/java/</sourceFolder>
                    <delegatePattern>true</delegatePattern>
                    <interfaceOnly>true</interfaceOnly>
                    <java8>true</java8>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce

mvn clean compile

Related issues/PRs

Not found

Suggest a fix/enhancement

Should the function change from ResponseEntity<InlineResponse200> to ResponseEntity<OneOfinlineResponse200>

Or

InlineReponses200 class should have Token and User two variable?

Or

Just I don't know how to implement?

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 generation invoked by the swagger-codegen Maven plugin and reproduce the issue using the supplied OpenAPI schema and configuration. Inspect the generated AuthenticationApi, InlineResponse200, and OneOfinlineResponse200 types; done means the generated response type can represent the Error and Token alternatives and the generated project compiles with mvn clean compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.