swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

[Java] Missing XmlSeeAlso annotation

Open neTAC23 opened this issue 3 years ago • 0 comments

Description

Using maven-codegen-plugin, trying to generate PetDTO.class, with 2 classes inheriting: Cat, Dog. Java model class after generation:

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2021-08-01T14:29:40.664+03:00[Asia/Jerusalem]")@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true )
@JsonSubTypes({
  @JsonSubTypes.Type(value = DogDTO.class, name = "DogDTO"),
  @JsonSubTypes.Type(value = CatDTO.class, name = "CatDTO"),
})
@XmlRootElement(name = "Pet")
@XmlAccessorType(XmlAccessType.FIELD)
@JacksonXmlRootElement(localName = "Pet")
public class PetDTO implements Serializable{
}
Swagger-codegen version

3.0.29-SNAPSHOT

Swagger declaration file content or url
  schemas:
    Pet:
      type: object
      required:
        - name
        - type
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
          example: doggie
        type:
          type: string
      discriminator:
        propertyName: type
      xml:
        name: Pet
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            bark:
              type: boolean
      x-discriminator-value: DogDTO
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            age:
              type: integer
      x-discriminator-value: CatDTO
Command line used for generation

Using swagger-maven-plugin:

	<plugin>
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.28-SNAPSHOT</version>
                <executions>
                    <execution>
                        <id>petStoreRestClient</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/petstore.yaml</inputSpec>
                            <language>java</language>
                            <generateModels>true</generateModels>
                            <modelPackage>com.swagger.test.petstore.dto</modelPackage>
                            <modelNameSuffix>DTO</modelNameSuffix>
                            <withXml>true</withXml>
                            <configOptions>
                                <library>resttemplate</library>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <serializationLibrary>jackson</serializationLibrary>
                                <dateLibrary>java8</dateLibrary>
                                <java8>true</java8>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Suggest a fix/enhancement

I have submitted the following PR for this issue: #937

neTAC23 avatar Aug 04 '21 14:08 neTAC23