0

我有 openapi 合同:

openapi: 3.0.1
info:
  version: 1.0.0

paths:
  /getInteractions:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: scheme/interactionsRq.json
        required: true
      responses:
        "200":
          content:
            application/json:
                schema:
                  $ref: scheme/mainRs.json

在这个结构中:

-resources
--GetInteractionController.yaml
--scheme
----interactionsRq.json
----interactionsRs.json
----mainRs.json

在 mainRs.json 中,我对另一个 json 有一些参考,如下所示:

  "resultApi": {
  "title": "result",
  "type": "object",
  "properties": {
    "interactionList": {
      "type": "array",
      "minItems": 0,
      "maxItems": 100,
      "items": {
        "$ref": "interactionsRs.json#/definitions/interactionApi"
      }
    }
  }

当我尝试用 openapi-generator-maven-plugin 打包它时:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>5.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/GetInteractionController.yaml</inputSpec>
                <generatorName>spring</generatorName>
                <apiPackage>some.api.package</apiPackage>
                <modelPackage>some.dto.package</modelPackage>
                <supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
                <configOptions>
                    <delegatePattern>true</delegatePattern>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

我收到警告并生成错误:

[WARNING] Failed to get the schema name: ./scheme/interactionsRs.json#/definitions/interactionApi

openapi 可以像我一样使用 refs 生成代码吗?或者我需要重构 json 模式并删除这个 refs?也许将它连接到一个文件或类似的东西中

4

1 回答 1

1

现在我明白了,这是我的 JSON 方案的问题,但不是 openapi-generator 的问题。

在 JSON 方案中,我使用了 jsonschema2pojo 功能“customDateTimePattern”:“yyyy-MM-dd'T'HH:mm:ssZ”,它给了我一个错误。当我删除它时,一切都变得很好

于 2022-01-14T08:40:34.640 回答