rest - OpenAPI 中标签的确切用途以及它们为何独一无二

标签 rest swagger openapi

按规范:

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

规范使用的带有附加元数据的标签列表。标签的顺序可以被解析工具用来反射(reflect)它们的顺序。并非操作对象使用的所有标记都必须声明。未声明的标签可以随机组织或基于工具的逻辑。列表中的每个标签名称必须是唯一的。

这些标签在解析器中是如何使用的,你能提供一些例子吗?
还有为什么需要是独一无二的?

最佳答案

几个例子:

  • Swagger UI 使用标签来 group显示的操作。例如,Petstore demo有三个标签 - pet , storeuser .
  • Swagger Codegen使用标签 groups 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
    

    关于rest - OpenAPI 中标签的确切用途以及它们为何独一无二,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53517210/

    相关文章:

    java - Jersey:异步请求后立即响应

    mysql - Hibernate数据库连接错误

    java - Swagger 忽略引用模式的模式属性

    c# - 将 ISchemaFilter 示例转换为 Swashbuckle 5.0

    java - Jersey 2 分段上传客户端

    android - 改造 1.6 : Call RestService with different (TCP)-Ports

    visual-studio - 通过 Connected Services 创建 openapi 客户端后生成错误

    java - swagger.yaml::如何生成具有 "Long"数据类型和 "Timestamp"数据类型的属性?

    gradle - 从我依赖的库中获取openapi规范

    python - FastAPI - 未填充 ENUM 类型模型