Springdoc-openapi: JsonSubTypes disappeared in api-spec.json / generated code in 1.2.31

Created on 26 Mar 2020  路  4Comments  路  Source: springdoc/springdoc-openapi

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    2.2.5
  • What modules and versions of springdoc-openapi are you using?
    1.2.30 worked fine, from 1.2.31 and upwards, it is broken
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    Interface implementations disappeared from the api-spec completely, such as this one:
"ConstantAllocation":{
            "required":[
               "type"
            ],
            "type":"object",
            "discriminator":{
               "propertyName":"type"
            },
            "allOf":[
               {
                  "$ref":"#/components/schemas/TradingStrategy"
               },
               {
                  "type":"object",
                  "properties":{
                     "assetIdToWeightPercent":{
                        "type":"object",
                        "additionalProperties":{
                           "type":"string"
                        }
                     },
                     "assetIdToAssetTemplate":{
                        "type":"object",
                        "additionalProperties":{
                           "$ref":"#/components/schemas/AssetTemplate"
                        }
                     },
                     "type":{
                        "type":"string"
                     }
                  }
               }
            ]
         }
  • Provide with a sample code or Test that reproduces the problem

TradingStrategy.java:

@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.PROPERTY,
        property = "type")
@JsonSubTypes({
        @JsonSubTypes.Type(value = ConstantAllocation.class, name = "ConstantAllocation"),
        @JsonSubTypes.Type(value = GradientAllocation.class, name = "OtherAllocation")
})
public interface TradingStrategy {
}

ConstantAllocation.java:

@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.PROPERTY,
        property = "type")
public class ConstantAllocation implements TradingStrategy {
...business-logic goes here...
}

Expected behavior
Currently, I am using springdoc-openapi both for the UI, and for the api-spec.json which it generates.
From the api-spec, I'm generating Python client code with Openapi Generator (4.3.2), so the research as able to interact with the REST interface of the Java backend.
Up until 1.2.30, the JsonSubTypes got generated into the api-spec, and therefore, got generated into the python client, but from 1.2.31, these subtypes are omitted from the api-spec.

The reason why JsonTypeInfo is present in the subclass as well, is that without it, openapi-generator did not correctly generated the "type" field of the subclass, hence the subclass missed the typeinfo, resulting in an error.

Most helpful comment

@danielbecs,

You can use the following property (v1.3.0) :because, your JsonSubTypes might be not referenced directly in your REST APIs:

springdoc.remove-broken-reference-definitions=false

More details are available in the documentation:

All 4 comments

Hi @danielbecs,

Can you please test with v1.3.0 ?

Hi,

Sadly, the issue persists with v1.3.0 as well.

Thank you.
We will have a look at tit.

@danielbecs,

You can use the following property (v1.3.0) :because, your JsonSubTypes might be not referenced directly in your REST APIs:

springdoc.remove-broken-reference-definitions=false

More details are available in the documentation:

Was this page helpful?
0 / 5 - 0 ratings