我在node.js应用程序中设置swagger时遇到了问题。我使用swagger-jsdoc
和swagger-ui-express
创建文档。以下是版本
“swagger-jsdoc”:“3.5.0”,“swagger-ui-express”:“4.1.3”
下面是我传递给swagger-jsdoc的代码。
openapi: 3.0.0
info:
description: test
version: 3.0.0
title: U-CRM api documentation
termsOfService: http://swagger.io/terms/
servers:
- url: 'https://localhost:5000'
description: Local server
tags:
- name: U-CRM
description: CRM for university
components:
parameters:
$ref: 'components/parameters/index.yml'
schemas:
$ref: 'components/schemas/index.yml'
paths:
$ref: '#/paths/index.yml'
字符串
毕竟,我得到一个错误
无法读取未定义的属性“parameters "
事实上,当我仔细阅读swagger文档时,这对我来说很惊讶。可能是什么问题?
1条答案
按热度按时间1l5u6lss1#
OpenAPI不支持
$ref
everywhere。$ref
只能在OpenAPI Specification明确声明字段的值可以是“引用对象”的特定位置使用。例如,
$ref
不允许直接在paths
、components/parameters
和components/schemas
下使用-您只能引用 * 单个 * 路径、参数和模式。你的例子的正确版本是:
字符串
如果你想在任意的地方使用
$ref
,你必须使用一个可以解析任意$refs的解析器/工具来预处理你的定义;这将给予你一个有效的OpenAPI文件,可以与OpenAPI兼容的工具一起使用。这样的预处理工具之一是json-refs,你可以在这里找到一个预处理的例子。