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
  • #11932
Closed
Open
Issue created Mar 21, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [Spring] [Java] Invalid code generated for schemas with oneOf object attributes

Created by: wagnerrobsan

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master 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 generating a spring or java code with a spec that contains an attribute with oneOf, the code generator creates a code with a bug

Spec: https://gist.github.com/wagnerrobsan/88d81d113d4add401667e64ab814e3aa

Creates the following java code:

public Fruit putBodyItem(String key,  bodyItem) {
    if (this.body == null) {
      this.body = ;
    }
    this.body.put(key, bodyItem);
    return this;
  }
openapi-generator version

latest version, build from master

OpenAPI declaration file content or url

Providing minimal reproducing example (YAML):

Spec: https://gist.github.com/wagnerrobsan/88d81d113d4add401667e64ab814e3aa

Generation Details

see Steps to reproduce for more details

Steps to reproduce

git clone https://github.com/openapitools/openapi-generator cd openapi-generator mvn clean package java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ -i https://gist.githubusercontent.com/wagnerrobsan/88d81d113d4add401667e64ab814e3aa/raw/ab969d651c60e76be6b44ba69950c77b9992c108/openapi-oneOfbug.yaml \ -g spring \ -o /outputFolder/oneOfBugApiClient

Related issues/PRs

Related to

  • https://github.com/OpenAPITools/openapi-generator/pull/11650
  • https://github.com/OpenAPITools/openapi-generator/issues/5381
Suggest a fix

The code generator should skip in the mustache file the putBodyItem method creation. see file JavaSpring/pojo.mustache

Assignee
Assign to
Time tracking