nk_*_*elb 13 swagger-2.0 openapi
definitionsSwagger 2.0中的全局部分和部分有什么区别components?
我遇到了一个 Swagger 定义 YAML 文件,该文件标记为swagger: '2.0'. 它有一个名为definitions下面的部分parameters。这类似于
https://swagger.io/docs/specification/2-0/basic-struct/
的“输入和输出模型”部分中描述的内容。
此外,在文件的更下方,它还包含下面的部分components。这与https://swagger.io/docs/specification/components/schemas中描述的类似,
这看起来像 OAS3。
但是,这个特定的 YAML 文件具有两个部分。我不确定是否definitions适用于 Swagger 2.0 和components是否schemas适用于 OAS 3.0。是这样吗?
和 可以definitions在components同一类型的 YAML 文件中使用吗swagger: '2.0'?或者我们应该坚持使用definitionsor 吗components?
# definitions section looks like this
definitions:
User:
properties:
id:
type: integer
name:
type: string
# Both properties are required
required:
- id
- name
# components section looks like this
components:
schemas:
Address:
type: object
properties:
line1:
type: string
city:
type: string
Run Code Online (Sandbox Code Playgroud)
Hel*_*len 15
我不确定是否
definitions适用于 Swagger 2.0 和components是否schemas适用于 OAS 3.0。是这样吗?
对,就是这样。
该definitions部分用于 OpenAPI 2.0 文件 ( swagger: '2.0')。
该components部分用于 OpenAPI 3.x ( openapi: 3.x.x)。
和 可以
definitions在components同一类型的 YAML 文件中使用吗swagger: '2.0'?或者我们应该坚持使用definitionsor 吗components?
不可以,您不能在同一个文件中混合使用 2.0 和 3.x 语法。如果您的文件是,swagger: '2.0'则必须使用 2.0 语法。如果是,则openapi: 3.0.0必须使用 3.0 语法。
| 归档时间: |
|
| 查看次数: |
3808 次 |
| 最近记录: |