0

additionalPropertes在我的 OpenAPI 定义中使用来引用地图对象。我的 OAS 部分如下所示:

Configuration:
  title: Configuration Info
  type: object
  additionalProperties:
    type: string
  description: The config parameters.
  example:
    configName: header
    configValue: Context
    configId: "12"

使用openapi-generator4.3.1 版的 maven codegen 插件生成代码并具有以下配置时,不会为模型生成模型类Configuration

           <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>api.yaml</inputSpec>
                            <language>jaxrs-cxf-cdi</language>
                            <configOptions>
                                <apiPackage>${api-package}</apiPackage>
                                <modelPackage>${model-package}</modelPackage>
                                <sourceFolder>src/gen/java</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

我们如何为additionalPropertiesOAS 中的对象生成模型类?

4

1 回答 1

0

将配置设置generateAliasAsModel为 true 将为 OAS 中定义的地图生成模型类。正确的配置如下:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>api.yaml</inputSpec>
                            <language>jaxrs-cxf-cdi</language>
                            <configOptions>
                                <apiPackage>${api-package}</apiPackage>
                                <modelPackage>${model-package}</modelPackage>
                                <sourceFolder>src/gen/java</sourceFolder>
                            </configOptions>
                            <generateAliasAsModel>true</generateAliasAsModel>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
于 2020-11-08T08:57:22.860 回答