loopback4 - openapi 规范中的错误关系映射

loopback4 - Wrong relation mapping in openapi spec

我正在为环回 4 中关系的 openapi 规范映射而苦苦挣扎。

有两个实体:Plan 和 PlanItem 与 "Plan hasMany PlanItems" 相关 在我的端点规范中,我已经声明包含这样的关系:

  @authenticate('jwt')
  @get('/{id}', {
    responses: {
      '200': {
        description: 'Plan for given id, including items',
        content: {
          'application/json': {
            schema: getModelSchemaRef(Plan, {
              title: "PlanWithRelations",
              exclude: ['ownerId'],
              includeRelations: true
            })
          },
        },
      },
    },
  })
  async findOne(
    @param.path.string('id') id: string,
  ): Promise<Plan | null> {
    return this.plansService.findOne(id);
  }

openapi.json 中的结果组件部分如下所示:

{
  "openapi": "3.0.0",
  "info": {
    "title": "ngbm-api - NGBM API v1.0",
    "version": "1.0.0",
    "contact": {

    }
  },
  // ...
  "components": {
    "schemas": {
      // ...
      "PlanWithRelations": {
        "title": "PlanWithRelations",
        "description": "(Schema options: { title: 'PlanWithRelations', exclude: [ 'ownerId' ], includeRelations: true })",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlanWithRelations"
            }
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": false
      },
    }
  }
}

如您所见,'PlanWithRelations' 中的项目数组有一个指向相同模式 'PlanWithRelations' 而不是 'PlanItem'

的 $ref

有人可以提示我如何解决这个问题吗? 如果您需要更多信息,请随时给我提示。

这是我的 loopback --version 输出:

@loopback/cli version: 2.2.1

@loopback/* dependencies:
  - @loopback/authentication: ^4.1.1
  - @loopback/boot: ^2.0.2
  - @loopback/build: ^5.0.0
  - @loopback/context: ^3.2.0
  - @loopback/core: ^2.2.0
  - @loopback/metadata: ^2.0.2
  - @loopback/openapi-spec-builder: ^2.0.2
  - @loopback/openapi-v3: ^3.1.1
  - @loopback/repository-json-schema: ^2.0.2
  - @loopback/repository: ^2.0.2
  - @loopback/rest: ^3.1.0
  - @loopback/testlab: ^2.0.2
  - @loopback/docs: ^3.2.1
  - @loopback/example-hello-world: ^2.0.2
  - @loopback/example-log-extension: ^2.0.2
  - @loopback/example-rpc-server: ^2.0.2
  - @loopback/example-todo: ^3.0.2
  - @loopback/example-soap-calculator: ^2.0.2
  - @loopback/service-proxy: ^2.0.2
  - @loopback/http-caching-proxy: ^2.0.2
  - @loopback/http-server: ^2.0.2
  - @loopback/example-todo-list: ^3.0.2
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^2.0.2
  - @loopback/eslint-config: ^6.0.2
  - @loopback/example-express-composition: ^2.0.2
  - @loopback/example-greeter-extension: ^2.0.2
  - @loopback/booter-lb3app: ^2.0.2
  - @loopback/example-lb3-application: ^2.0.2
  - @loopback/example-greeting-app: ^2.0.2
  - @loopback/example-context: ^2.0.2
  - @loopback/repository-tests: ^0.11.2
  - @loopback/extension-health: ^0.3.2
  - @loopback/authorization: ^0.5.2
  - @loopback/rest-crud: ^0.7.2
  - @loopback/security: ^0.2.2
  - @loopback/authentication-passport: ^2.0.2
  - @loopback/example-metrics-prometheus: ^0.2.2
  - @loopback/extension-metrics: ^0.2.2
  - @loopback/model-api-builder: ^2.0.2
  - @loopback/extension-logging: ^0.2.2
  - @loopback/example-access-control-migration: ^1.1.2
  - @loopback/example-file-transfer: ^1.1.2
  - @loopback/example-rest-crud: ^1.1.1
  - @loopback/apiconnect: ^0.1.1
  - @loopback/example-validation-app: ^1.1.1
  - @loopback/cron: ^0.1.0

包含 "title" 会导致生成无效架构的已知错误。

解决方法是从 getModelSchemaRef 中删除 "title" 键:

schema: getModelSchemaRef(Plan, {
  exclude: ['ownerId'],
  includeRelations: true
})

PR with the fix 已合并,修复将很快发布。