swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

oneOf not able to generate java class #11743

Open sumedha0203 opened 2 years ago

sumedha0203 commented 2 years ago
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
hrehman-sphereon commented 2 years ago

I am facing a similar issue https://stackoverflow.com/questions/72043299/swagger-openapi-code-gen-oneof-how-to-generate-correct-class-file

https://community.smartbear.com/t5/AlertSite-Feature-Requests/Retrieve-AlertSite-Usage-Statistics-via-API/idi-p/197405