swagger-api / swagger-api/swagger-codegen

oneOf in generated spring server return empty JSON

Open
#11,305 0 comments 1 reaction 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

Q&A (please complete the following information)
  • OS: RHEL 7 (docker)
  • Browser: yandex broser
  • Version: latest container (swagger ui)
  • Method of installation: docker
  • Swagger/OpenAPI version: 3.0.2
Content & configuration

Example Swagger/OpenAPI definition:

Path is:
  /choiceTest:
    post:
      operationId: "ChoiceTest"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/typicalRequest"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/checkChoice"

ComponentSchema is:
    checkChoice:
      type: "object"
      oneOf:
      - properties:
          integerValue:
            format: "int32"
            type: "integer"
      - properties:
          longValue:
            format: "int64"
            type: "integer"
      - properties:
          stringValue:
            type: "string"
      - properties:
          doubleValue:
            format: "double"
            type: "number"
Describe the bug you're encountering

if you define oneOF and generate a server. Then even if the value taken from the swagger ui is inserted correctly, an empty json will be returned

To reproduce...

Use swagger ui.

Steps to reproduce the behavior:

  1. Define any type with one of.
  2. Generate a spring server.
  3. In controller define correct value
Expected behavior

Json with a valid value in response. (Actually it return {})

Screenshots

image

image

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 by reproducing the issue with the supplied OpenAPI 3.0.2 schema in Swagger UI and a generated Spring server. Inspect how the generated oneOf response is serialized, then compare it with a response using a non-oneOf schema; done means the valid selected value is returned as JSON instead of {}.

Written by the indexing model from the issue text.

Assessment

Tech stack
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.