OpenAPI 中标签的确切用途以及它们为何独一无二
Exact purpose of tags in OpenAPI and why are they unique
按规格:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
规范使用的带有附加元数据的标签列表。标签的顺序可用于通过解析工具反映它们的顺序。并非操作对象使用的所有标签都必须声明。未声明的标签可以随机组织或根据工具的逻辑组织。列表中的每个标签名称必须是唯一的。
这些标签在解析器中是如何使用的,你能提供一些例子吗?
还有为什么需要独一无二?
举几个例子:
Swagger UI 使用标签 group the displayed operations. For example, the Petstore demo 有三个标签 - pet
、store
和 user
.
Swagger Codegen uses tags to group endpoints into the same API class file:
For example, an endpoint with the "store" tags
will be generated in the StoreApi
class file.
And also why need to be unique?
标签名称必须是唯一的,因为您不能有两个名称相同的标签。
# Correct
openapi: 3.0.2
tags:
- name: pet # <--- unique tag name
description: Operations to manage the pets
- name: store # <--- unique tag name
descriptions: Access to Petstore orders
# Wrong
openapi: 3.0.2
tags:
- name: pet
- name: pet
按规格:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
规范使用的带有附加元数据的标签列表。标签的顺序可用于通过解析工具反映它们的顺序。并非操作对象使用的所有标签都必须声明。未声明的标签可以随机组织或根据工具的逻辑组织。列表中的每个标签名称必须是唯一的。
这些标签在解析器中是如何使用的,你能提供一些例子吗? 还有为什么需要独一无二?
举几个例子:
Swagger UI 使用标签 group the displayed operations. For example, the Petstore demo 有三个标签 -
pet
、store
和user
.Swagger Codegen uses tags to group endpoints into the same API class file:
For example, an endpoint with the "store"
tags
will be generated in theStoreApi
class file.
And also why need to be unique?
标签名称必须是唯一的,因为您不能有两个名称相同的标签。
# Correct
openapi: 3.0.2
tags:
- name: pet # <--- unique tag name
description: Operations to manage the pets
- name: store # <--- unique tag name
descriptions: Access to Petstore orders
# Wrong
openapi: 3.0.2
tags:
- name: pet
- name: pet