swagger-api / swagger-api/swagger-codegen

oneOf not able to generate java class

Open
#11,743 1 comment 0 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

openapi-generator for java is not able to generate class for oneOf field

/Users/....../CustomClass.java:[23,41] cannot find symbol
[ERROR] symbol: class OneOfstringinteger

CustomClass.java class is created with the field

public static final String SERIALIZED_NAME_FIELD_VALUE = "fieldValue";
@SerializedName(SERIALIZED_NAME_FIELD_VALUE)
private OneOfstringinteger fieldValue = null;

But OneOfstringinteger is not getting created.

Swagger-codegen version
org.openapitools openapi-generator-maven-plugin 4.1.1
Swagger declaration file content or url
fieldValue:
    oneOf:
      - type: string
      - type: integer
Command line used for generation

mvn clean install takes care of it

Steps to reproduce

trying to build the project by maven command

Related issues/PRs
Suggest a fix/enhancement

open-api generator for java is not able to generate a class for oneOf type for primitive objects (string, integer, number etc).

tried with objects also but same error came:

fieldValue:
    oneOf:
      - $ref: '#/definitions/StringValue'
      - $ref: '#/definitions/NumberValue'

definitions:
  StringValue:
    type: object
    properties:
      name:
        type: string

  NumberValue:
    type: object
    properties:
      name:
        type: number
cannot find symbol
[ERROR]   symbol:   class OneOfStringValueNumberValue

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 OpenAPI schema's oneOf definitions and the generated CustomClass.java, then run the reported mvn clean install command to reproduce the missing OneOfstringinteger or OneOfStringValueNumberValue class. Done means the required Java classes are generated for primitive and referenced oneOf members and the Maven build no longer reports cannot find symbol.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, devtools
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.