swagger-api / swagger-api/swagger-codegen-generators

[Java] Missing XmlSeeAlso annotation

Open
#938 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

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

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 maven-codegen-plugin Java model-generation entry point and reproduce the Pet, Dog, and Cat schema example with XML enabled. Compare the generated PetDTO annotations with the requested XmlSeeAlso behavior and review PR #937; done means the generated model includes the needed annotation without breaking the existing discriminator annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.