Подтипы не реализуют интерфейс при создании с помощью генератора OpenAPI.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Подтипы не реализуют интерфейс при создании с помощью генератора OpenAPI.

Сообщение Anonymous »

У меня нет опыта работы с Swagger и OpenAPI Generator, и я пытаюсь создать несколько моделей с помощью Swagger и OpenAPI Generator. Как вы можете видеть на изображениях, класс AnimalRefOrValue является интерфейсом, но ни один из подтипов его не реализует. Из-за этого у меня возникли проблемы с разработкой сопоставителя, поскольку атрибут типа AnimalRefOrValue не может принимать ни один из подтипов (Cat/Dog/Animal).

Код: Выделить всё

[AnimalRefOrValue defined on swagger]
AnimalRefOrValue:
type: object
description: >
The polymorphic attributes @species, @schemaLocation & @referredType are related to the Animal
entity and not the AnimalRefOrValue class itself.
oneOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: "@species"
mapping:
Animal: '#/components/schemas/Animal'
Cat: '#/components/schemas/Cat'
Dog: '#/components/schemas/Dog'

[Cat defined on swagger]
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
description: >
A specific type of animal with unique properties.
required:
- "@species"
properties:
meowVolume:
type: string
description: Volume of the cat's meow.
furColor:
type: string
description: Color of the cat's fur.
relatedAnimals:
type: array
items:
$ref: '#/components/schemas/AnimalRefOrValue'
description: This is an array of related animals.
@species:
type: string

[AnimalRefOrValue interface]
@JsonIgnoreProperties(
value = "@species", // ignore manually set @species, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the @species to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@species", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Animal.class, name = "Animal"),
@JsonSubTypes.Type(value = Cat.class, name = "Cat"),
@JsonSubTypes.Type(value = Dog.class, name = "Dog")
})
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-01-14T16:33:35.582270100-03:00")
public interface AnimalRefOrValue {
public String getSpecies();
}

[Cat Class does not implementing the interface]

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-01-14T16:33:35.582270100-03:00")
public class Cat extends Animal {
@JsonProperty(value = "meowVolume")
@JsonPropertyDescription("Volume of the cat's meow.")
private String meowVolume;
@JsonProperty(value = "furColor")
@JsonPropertyDescription("Color of the cat's fur.")
private String furColor;
@Valid
@JsonProperty(value = "relatedAnimals")
@JsonPropertyDescription("This is an array of related animals.") private List relatedAnimals = null;
@JsonProperty(value = "@species", required = true) @JsonPropertyDescription("Species type of the animal.")
private String species;
public Cat meowVolume(String meowVolume) {
this.meowVolume = meowVolume;
return this;
}
}
Я ожидал, что подтипы реализуют интерфейс. Кто-нибудь знает, как это решить?

Подробнее здесь: https://stackoverflow.com/questions/793 ... enapi-gene
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»