[BUG][JAVA][SPRING] missing JsonValue import if allOf used as inline-scheme composition
Created by: souwa
Description
When using allOf as a composition inline-scheme without inheritance/discriminator the import import com.fasterxml.jackson.annotation.JsonValue
for the Enum method @JsonValue public String getValue()
is not added to the imports of the generated class.
This happens when the inline model doesn't have enums, but the parent does.
Also, the syntax that was used is the only workaround that prevents the generation of the redundant additional ParentTitle+AllOf class (see Java generation of 'extra' class with allOf Workaraound):
Address:
type: object
properties:
locationType:
type: string
enum:
- VILLAGE
- SMALL_TOWN
- BIG_CITY
allOf:
- $ref: '#/components/schemas/BasicAddress'
BasicAddress:
type: object
properties:
street:
type: string
housenumber:
type: string
zip:
type: string
city:
type: string
country:
type: string
The result includes the following imports from Jackson,
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
but not the JsonValue-Import: although the method is generated
@JsonValue
public String getValue() {
return value;
}
openapi-generator version
openapi-generator v. 5.3.1 ( for java spring)
Related issues/PRs
If the generation of the additional unnecessary ParentTitle+AllOf class is fixed then I believe that will fix this problem as well. Opt-in solution to remove unnecessary model for inline schema composition
Suggest a fix
For the solution, this method postProcessModelProperty (SpringCodegen) might probably be adapted at the point where Jackson imports are added and the model will be checked if it is or has enums or not.