springdoc-openapi-uiバージョン 1.4.0 以降、Java pojo 継承を管理できなくなりました。AllOf、OneOf の概念が 1.4.0 で追加されたことは知っていますが、それを機能させる方法がわかりません。
X のリストを含む単純な pojo があります (x は抽象です)。2 つの可能な実装があります。適切な実装は、クラス X の属性で決定されます。
** コード: (クラス名は変更されています) **
両方のバージョンの CheeseDTO YAML :
CheeseDTO:
type: object
properties:
cheeseType:
type: string
discriminator:
propertyName: cheeseType
springdoc -openapi-ui 1.3.9では、yaml は次のように生成されます。
MyDTO:
type: object
properties:
cheeses:
type: array
items:
$ref: '#/components/schemas/CheeseDTO'
openapi-generator-maven-plugin 4.3.0を介して生成された DTO
private List<CheeseDTO> cheeses = null;
springdoc -openapi-ui 1.5.4 では、yaml は次のように生成されます。
MyDTO:
type: object
properties:
cheeses:
type: array
items:
oneOf:
- $ref: '#/components/schemas/SoftCheeseDTO'
- $ref: '#/components/schemas/HardCheeseDTO'
openapi-generator-maven-plugin 4.3.0を開いて生成された DTO (これは CheeseDTO ではなく MyDTOCheesesOneOf の問題です)
private List<MyDTOCheesesOneOf> cheeses = null;
Swagger 3 注釈:
@Schema(
name = "CheeseDTO",
discriminatorProperty = "cheeseType",
discriminatorMapping = {@DiscriminatorMapping(value = "Brie", schema = SoftCheeseDTO.class),
@DiscriminatorMapping(value = "Banon", schema = SoftCheeseDTO.class),
@DiscriminatorMapping(value = "Cheddar", schema = HardCheeseDTO.class)})
abstract CheeseDTO
private String cheeseType;
@Schema(allOf = {CheeseDTO.class})
SoftCheeseDTO extends CheeseDTO
@Schema(allOf = {CheeseDTO.class})
HardCheeseDTO extends CheeseDTO
OpenAPI Generator maven プラグイン
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<id>generateWebQuoteApiClient</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>/definitions/webQuoteApi.yaml</inputSpec>
<generatorName>java</generatorName>
<generateApiDocumentation>false</generateApiDocumentation>
<configOptions>
<library>jersey2</library>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<modelPackage>${client.package}.model</modelPackage>
<apiPackage>${client.package}.api</apiPackage>
<invokerPackage>${client.package}.api</invokerPackage>
<performBeanValidation>false</performBeanValidation>
<serializationLibrary>jackson</serializationLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
springdoc-openapi-ui > 1.4.0List<CheeseDTO>
でを生成する方法はあり ますか? swagger アノテーションを変更したり、Java ジェネレーターを変更したりする必要がありますか?
**ジェネレータプラグインを最新バージョンに更新しようとしましたが、同じ結果でした
助けてくれてありがとう