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



im在环回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"的$ref,而不是对"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与修复程序已合并,修复程序将很快发布。

相关内容

  • 没有找到相关文章

最新更新