Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact purpose of tags in OpenAPI and why are they unique

By Specification:

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?.

like image 787
Sree Avatar asked Nov 28 '18 10:11

Sree


People also ask

What is the use of tags in OpenAPI?

The tag object for the OpenAPI specification is pretty basic, allowing you to add tags for an entire API contract, as well as apply them to each individual API method. Tooling, such as API documentation uses these tags to group your API resources, allowing you to break down your resources into logical bounded contexts.

What are tags good for in swagger specification?

The tags object allows you to arrange the paths (endpoints) into named groups in the Swagger UI display.

What are tags in Swagger JSON?

Swagger UI uses tags to group the displayed operations. For example, the Petstore demo has three tags - pet , store and 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.

What are tags in REST API?

Tags are words or phrases that act as keywords for categorizing, identifying, and organizing APIs. In API Gateway, you can assign tags to APIs, and their resources, methods, or operations. Tags help to logically catagorize APIs in different ways, for example, by usage, owner, consuming application, or other criteria.


1 Answers

A couple of examples:

  • Swagger UI uses tags to group the displayed operations. For example, the Petstore demo has three tags - pet, store and 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?

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
like image 172
Helen Avatar answered Oct 03 '22 01:10

Helen