1

有没有办法指定哪些列出现在“参数”部分?例如,我想使用 Schema/type 而不是 Pattern。

我的配置:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>5.3.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/target/openapi.json</inputSpec>
                <generatorName>asciidoc</generatorName>
                <configOptions>
                    <useIntroduction>true</useIntroduction>
                </configOptions>
                <skipValidateSpec>true</skipValidateSpec>
            </configuration>
        </execution>
    </executions>
</plugin>

这是相关的源代码段:

 /myapi/{resourceId}:
    get:
      tags:
      - Api Operations
      summary: Get a widget
      description: Get a widget by its resource id
      operationId: findOne
      parameters:
      - name: resourceId
        in: path
        required: true
        schema:
          type: string
      - name: affiliateId
        in: header
        required: false
        schema:
          type: integer
          format: int64
          default: 256

以及相关的输出片段:

====== Header Parameters

[cols="2,3,1,1,1"]
|===
|Name| Description| Required| Default| Pattern

| affiliateId
|  
| -
| 256
| 

|===

而不是“模式”列,我希望它显示类似 Schema 的内容以及整数和/或 int64 的值。

4

1 回答 1

1

我通过编辑胡子模板解决了这个问题:

src/main/resources/asciidoc-documentation克隆 openapi-generator 项目后,我从modules ( link ):params.mustache和, 下找到以下两个文件并将其复制param.mustache到我自己的项目下/src/main/resources/openapi

然后我打开params.mustache并从“模式”到“数据类型”进行了查找和替换。

同样在param.mustache我用“{{dataType}}”替换“{{{pattern}}}”

然后在 maven pom 文件插件配置中,openapi-generator-maven-plugin我在元素下添加了以下configuration元素:

<templateDirectory>${project.basedir}/src/main/resources/openapi</templateDirectory>

运行 mvn clean compile 会产生所需的输出:

[cols="2,3,1,1,1"]
|===
|Name| Description| Required| Default| Data Type

| affiliateId
|  
| -
| 256
| Long

注意:为了获得正确的模型字段名称,我在配置元素下启用了调试:<verbose>true</verbose>然后发出命令(类似于)mvn org.openapitools:openapi-generator-maven-plugin:5.3.0:generate@my-execution-id -pl mysubmodule -X -l out.txt:; 打开 out.txt 并搜索“headerParams”或“affiliateId”,找到与数据类型对应的字段名称,在我的例子中,有“dataType”和“dataFormat”,我选择了前者。

另请注意,我不需要复制index.mustache等到model.mustache我的项目中,只需要上面提到的两个模板文件。

于 2021-12-13T20:19:50.320 回答