loopback4-openapi规范中的错误映射

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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'中的items数组对同一模式'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

答案
这是一个已知的错误,其中包含“标题”将导致无效的架构生成。

一种解决方法是从GetModelSchemaRef中删除“ title”键:

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

PR with the fix已被合并,并且此修复程序将很快发布。

以上是关于loopback4-openapi规范中的错误映射的主要内容,如果未能解决你的问题,请参考以下文章

Java的基本类型

boolean 属性的定义规范

Mybatis——动态代理的执行方式及规范

Mybatis——动态代理的执行方式及规范

Mybatis——动态代理的执行方式及规范

解析序列/映射节点时出现无效的 yaml 节点错误