OpenAPI中标签的确切用途以及它们为何唯一 [英] Exact purpose of tags in OpenAPI and why are they unique

查看:137
本文介绍了OpenAPI中标签的确切用途以及它们为何唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按规范:

https://github.com/OAI /OpenAPI-Specification/blob/master/versions/3.0.2.md

规范与其他元数据一起使用的标签的列表.标签的顺序可以被解析工具用来反映它们的顺序.并非必须声明操作对象使用的所有标签.未声明的标签可以是随机组织的,也可以根据工具的逻辑来组织.列表中的每个标签名称必须唯一.

A list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the Operation Object must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.

这些标记在解析器中如何使用,您能否提供一些示例? 还有为什么需要唯一?

How are these tags used in parsers, can you provide some examples? And also why need to be unique?.

推荐答案

两个示例:

  • Swagger UI使用标签对 group 显示的操作.例如,宠物店演示具有三个标签-petstoreuser.

  • Swagger UI uses tags to group the displayed operations. For example, the Petstore demo has three tags - pet, store and user.

Swagger Codegen 使用标签来

例如,将在StoreApi类文件中生成带有"store" tags的端点.

For example, an endpoint with the "store" tags will be generated in the StoreApi class file.


还有为什么需要唯一?

And also why need to be unique?

在不能使用相同名称的两个标签的意义上,标签名称必须唯一.

Tag names must be unique in the sense that you cannot have two tags with the same name.

# 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

这篇关于OpenAPI中标签的确切用途以及它们为何唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆