OpenAPI Specification Path: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 32: Line 32:
{{External|https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathTemplating}}
{{External|https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathTemplating}}
Path templating refers to the usage of curly braces <code>{}</code> to mark a section of a URL path as replaceable using [[#Path_Parameters|path parameters]].
Path templating refers to the usage of curly braces <code>{}</code> to mark a section of a URL path as replaceable using [[#Path_Parameters|path parameters]].
=Operations=
=<span id='Operation'></span>Operations=
{{External|https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject}}
An '''operation''' represents a single HTTP operation on a [[#Path|path]].
<font size=-2>
get|put|post|delete|options|head|patch|trace:
  summary: <font color=teal>|
      A short description of the operation.</font>
  [[#operationId|operationId]]: <font color=brick>someOperationId</font>
  description:  <font color=teal>'...'</font>
  [[#Parameters|parameters]]: [...]
  [[#Responses|responses]]: [...]
  [[#Tags|tags]]: [...]
  [[#RequestBody|requestBody]]:
  callbacks:
  security:
  servers:
  deprecated:
</font>
==<tt>operationId</tt>====
A unique string, among all operations described by this API, used to identify the operation. The <code>operationId</code> value is case-sensitive. Tools and libraries may use <code>operationId</code> to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.
 
====Responses====
{{External|https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#responses-object}}
The <code>responses</code> field is required and lists all possible HTTP responses that may result from executing this operation. The element must contain at least one response code. The definition is not expected to cover all possible HTTP response codes, because they may not be known in advance. However, the definition should cover a successful operation response and any known errors. The "default" map key may be used as a default response object for all HTTP codes that are not covered individually in the definition.
<syntaxhighlight lang='yaml'>
paths:
/a:
  get:
    responses:
      200:
        [...]
      default:
        [...]
</syntaxhighlight>
====RequestBody====
{{External|https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}}
Also see: {{Internal|REST_and_Hypermedia#Request_Body|REST Request Body}}
====Tags====
Each operation can be annotated with a list of tags. Tagged operations may be handled differently by tools and libraries. Optionally, each tag can get a "description" and an "externalDocs" in the global "tags" section on the root level. The tag names here should match those used in operations. The tag order in the global tags section also controls the default sorting in the UI. It is possible to use a tag at operation level even if it is not specified on the root level.
<syntaxhighlight lang='yaml'>
tags:
  - name: tag-a
    description: Something that would shed light on tag-a semantics
    externalDocs:
      url: https://example.com/my-docs/tag-a.html
paths:
  /a:
    get:
      tags:
        - tag-a
        - other-tag
</syntaxhighlight>
 
=Parameters=
=Parameters=
A unique parameter is defined by a combination of a name and a location.
A unique parameter is defined by a combination of a name and a location.

Revision as of 17:31, 26 January 2024

Internal

Overview

The top level paths keyword introduce a map of paths, keyed by their path value:

[...]
paths:
 /a:
    summary:
    description: 
    get: [...]
    put: [...]
    post: [...]
    delete: [...]
    options: [...]
    head: [...]
    patch: [...]
    trace: [...]
    parameters: [...]
    servers:
 /b:
   [...]
 /c:
   [...]
[...]

Path

Each path name must start with a forward slash "/". The path is appended to the expanded URL from the server object url field in order to construct the full URL. Path templating is allowed. Each path accepts zero or more of the available operations (get, put, post, delete, options, head, patch, trace) and parameters, which is a list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at operation level but cannot be removed there.

Path Templating

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathTemplating

Path templating refers to the usage of curly braces {} to mark a section of a URL path as replaceable using path parameters.

Operations

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject

An operation represents a single HTTP operation on a path.

get|put|post|delete|options|head|patch|trace:
  summary: |
     A short description of the operation.
  operationId: someOperationId
  description:  '...'
  parameters: [...]
  responses: [...]
  tags: [...]
  requestBody:
  callbacks:
  security:
  servers:
  deprecated:

operationId==

A unique string, among all operations described by this API, used to identify the operation. The operationId value is case-sensitive. Tools and libraries may use operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.

Responses

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#responses-object

The responses field is required and lists all possible HTTP responses that may result from executing this operation. The element must contain at least one response code. The definition is not expected to cover all possible HTTP response codes, because they may not be known in advance. However, the definition should cover a successful operation response and any known errors. The "default" map key may be used as a default response object for all HTTP codes that are not covered individually in the definition.

paths:
 /a:
   get:
     responses:
       200:
         [...]
       default:
         [...]

RequestBody

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object

Also see:

REST Request Body

Tags

Each operation can be annotated with a list of tags. Tagged operations may be handled differently by tools and libraries. Optionally, each tag can get a "description" and an "externalDocs" in the global "tags" section on the root level. The tag names here should match those used in operations. The tag order in the global tags section also controls the default sorting in the UI. It is possible to use a tag at operation level even if it is not specified on the root level.

tags:
  - name: tag-a
    description: Something that would shed light on tag-a semantics
    externalDocs:
      url: https://example.com/my-docs/tag-a.html
paths:
  /a:
    get:
      tags:
        - tag-a
        - other-tag

Parameters

A unique parameter is defined by a combination of a name and a location.