Describe the bug
To Reproduce
Steps to reproduce the behavior:
"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"
}
}
}
]
}
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.
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:
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:
More details are available in the documentation: