OpenAPITools / OpenAPITools/openapi-generator

@JsonSubTypes not in the generated java code from openapi 3.0.1 definition file

Open
#2,764 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi,

I generated the api definition file (openapi "3.0.1") from jaxrs code with maven plugin:

                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>2.0.8</version>

I used the following maven plugin for generating java class from the above api definition file.

    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.0.0-beta3</version>

There are a couple of issues. To illustrate the issues. The following is a section of the definition file (generated from swagger-maven-plugin ):

 "openapi" : "3.0.1",
  "components":{
   "schemas":{
      "Message" : {
        "type" : "object",
        "properties" : {
          "msgId" : {
            "type" : "string"
          },
          "timestamp" : {
            "type" : "string",
            "format" : "date-time"
          },
        "discriminator" : {
          "propertyName" : "type",
          "mapping" : {
            "text" : "#/components/schemas/TextMessage",
            "file" : "#/components/schemas/FileMessage"
          }
        }
      }
...

}

The following are some issues:
(1) There was not @JsonSubTypes in the generated java file
(2) The OffsetDateTime is from org.threeten.bp.OffsetDateTime instead of java.time.OffsetDateTime
(3) It import ApiModel and ApiModelProperty (openApi v2.0)
(4) it annotates fields with com.google.gson.annotations.SerializedName, and not
@JsonProperty

Is there special configuration that allow the generated code very close to the original code?

Thanks

Wayne

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 3.0.1 definition and the openapi-generator-maven-plugin 4.0.0-beta3 configuration described in the issue. Investigate how the Java generator handles discriminators, date-time types, and annotation libraries. Done means determining whether configuration or generator changes are needed for the four reported outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.