app*_*500 5 java maven-plugin openapi openapi-generator openapi-generator-maven-plugin
我想根据 Openapi 规范 3.0 yml 定义生成模型。在我的规范中,我有一个定义,用于allOf包含其他组件的字段。使用 生成模型时openapi-generator-maven-plugin。我看到以下警告allOf with multiple schemas defined. Using only the first one。
结果是仅allOf包含第一个定义的属性。虽然我希望所有字段都包含在内。https://editor.swagger.io/生成正确的架构。
为什么不是所有属性都定义在allOfinclude 中?
架构定义:
Dto:
title: Dto
type: object
properties:
created_by:
type: string
format: date-time
Foo:
title: Foo
type: object
allOf:
- $ref: '#/Dto'
properties:
fooProperty:
type: string
Bar:
title: Bar
type: object
allOf:
- $ref: '#/Foo'
properties:
barProperty:
type: string
Run Code Online (Sandbox Code Playgroud)
maven插件配置:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>myspec.yml</inputSpec>
<generatorName>spring</generatorName>
<generateApis>false</generateApis>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<serializableModel>true</serializableModel>
<documentationProvider>none</documentationProvider>
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
结果仅包含和Bar的字段,但不包含 的字段。为什么不是所有属性都定义在include 中?DtoBarFooallOf
从 v6.5.0 开始,处理方式allOf最近发生了变化,以便处理您所描述的确切问题。这些更改是由这个问题引发的,并在本 PR中进行了介绍。
然而,新功能并不是默认行为。为了尝试它,您可以使用该REFACTOR_ALLOF_WITH_PROPERTIES_ONLY标志。以下示例适用于openapi-generator-cli,但可以使用配置轻松地将其扩展到 Maven 插件openApiNormalizer。
openapi-generator generate -g <target_language> -i <api_spec_file> -o gen --openapi-normalizer REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true
Run Code Online (Sandbox Code Playgroud)