跳至內容

使用標籤分組操作

您可以將 tags 清單指派給每個 API 操作。帶有標籤的操作可能會被工具和程式庫以不同方式處理。例如,Swagger UI 使用 tags 來分組顯示的操作。

1
paths:
2
/pet/findByStatus:
3
get:
4
summary: Finds pets by Status
5
tags:
6
- pets
7
...
8
/pet:
9
post:
10
summary: Adds a new pet to the store
11
tags:
12
- pets
13
...
14
/store/inventory:
15
get:
16
summary: Returns pet inventories
17
tags:
18
- store
19
...

Swagger UI 中的標籤 (選擇性)您可以使用根層級的全域 tags 區段,為每個標籤指定 descriptionexternalDocs。此處的標籤名稱應與操作中使用的名稱相符。

1
tags:
2
- name: pets
3
description: Everything about your Pets
4
externalDocs:
5
url: http://docs.my-api.com/pet-operations.htm
6
- name: store
7
description: Access to Petstore orders
8
externalDocs:
9
url: http://docs.my-api.com/store-orders.htm

全域標籤區段中的標籤順序也會控制 Swagger UI 中的預設排序。請注意,即使標籤未在根層級定義,也可以在操作中使用標籤。

OpenAPI tags in Swagger UI

找不到您要找的內容?詢問社群
發現錯誤?讓我們知道