Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] allOf discriminator property not declared #617

Closed
rrockx-trifork opened this issue Mar 2, 2020 · 2 comments
Closed

[Java] allOf discriminator property not declared #617

rrockx-trifork opened this issue Mar 2, 2020 · 2 comments
Milestone

Comments

@rrockx-trifork
Copy link
Contributor

When I use the following schema (see also: allOf example):

openapi: 3.0.0
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
              discriminator:
                propertyName: pet_type
      responses:
        '200':
          description: Updated
components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    Dog:     # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:     # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer

to generate Java client code with the following command:

java -jar swagger-codegen-cli.jar generate -l java -i codegen/openapi.yaml -o allof-example

the classes Pet and Body contains invalid code:

public class Pet {
  @SerializedName("pet_type")
  private String petType = null;

  public Pet() {
    this.pet_type = this.getClass().getSimpleName();
  }
  public Pet petType(String petType) {
    this.petType = petType;
    return this;
  }

The property pet_type is not declared, resulting in compilation errors:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/ramon/temp/java-oas2-oneof2/src/main/java/io/swagger/client/model/Body.java:[25,9] cannot find symbol
  symbol: variable pet_type
[ERROR] /home/ramon/temp/java-oas2-oneof2/src/main/java/io/swagger/client/model/Pet.java:[35,9] cannot find symbol
  symbol: variable pet_type

I used the latest version of the code generation client (3.0.18).

Maybe this is related to #291, #296 ?

@HugoMario
Copy link
Contributor

fixed with #620. So, closing now. In case is still present please let me know and i'll work back on it asap.

@HugoMario HugoMario added this to the v3.0.19 milestone Apr 2, 2020
@sanjothmr
Copy link

Same issue exists in swagger-codegen-cli-3.0.25, but works with older version swagger-codegen-cli-3.0.19
When can I expect a fix for latest version of codegen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants