swagger - 大摇大摆的编辑器:无法使用 $ref 添加本地引用
问题描述
我正在通过swagger创建一些 API 。
我不明白如何$ref
在同一个文件上使用引用...这是我当前的招摇文件:
openapi: 3.0.0
info:
title: test API
version: "1.0.0"
description: This is a sample API.
servers:
- url: http://api.internal.com/api
paths:
/sources/:
get:
summary: returns all sources given a page and a size
parameters:
- name: page
required: true
in: query
description: Limits the number of items on a page
schema:
type: integer
- name: size
required: true
in: query
description: Specifies a page size
schema:
type: integer
responses:
'200':
$ref: '#/definitions/myElement'
definitions:
myElement:
"data": {
"sources": [
{
"id": "fw5pQ08wMnFfbEE",
"fileName": "test.csv",
"size": 1000000,
"annotatedDate": "2018-10-01 12:00:00",
"metadataContact": "test@test.com",
"canBeIngested": true
}
],
"stats": {
"total": 4000,
"page": 1,
"size": 20
}
}
现在,问题是编辑器向我抛出了这个错误:
Errors
Schema error should NOT have additional properties
additionalProperty: definitions
Jump to line 0
在$ref的文档中,我真的找不到任何有用的东西......
我怎样才能解决这个问题?
解决方案
In OpenAPI 3.0, definitions
were replaced with components/schemas
. This means you need to use:
responses:
'200':
$ref: '#/components/schemas/myElement'
and
components:
schemas:
myElement:
...
Also, your model definition for myElement
is not valid. See this guide to learn how to describe objects, properties, etc.
推荐阅读
- facebook - 如何在 facebook messenger bot 中实现内容地理围栏?
- mysql - Sql 从 count 正好为 2 的多个表中选择值
- c - 如何将一个或多个单词添加到二维数组
- nlp - 文本分类 + NLP + 数据挖掘 + 数据科学:我应该在应用 tf-idf 之前进行停止词删除和词干提取吗?
- powershell - 电子邮件正文的powershell变量
- postgresql - 在类中使用 npgsql
- c# - Visual Studio 在开始构建之前有很多延迟,有时会再次停止
- visual-studio - 如何在 Visual Studio 扩展中检测非托管 C++ 项目
- python-3.x - 如何在多维数组上使用收集计数器?
- vim - 如何根据缓冲区中已找到的单词使 Vim 自动完成单词?