Open API Specifications as in Swagger UI - bounswe/bounswe2024group11 GitHub Wiki

Introduction

The OpenAPI Specification (OAS) offers a standardized interface for HTTP APIs, enabling easy discovery and understanding of service capabilities without needing source code or extensive documentation.

With OAS, developers can generate documentation, servers, clients, and testing tools in different programming languages, simplifying API development and enhancing interoperability.

Definitions

OpenAPI Document

A self-contained or composite resource which defines or describes an API or elements of an API.

The OpenAPI document MUST contain at least one paths field, a components field or a webhooks field. An OpenAPI document uses and conforms to the OpenAPI Specification.

Path Templating

Path templating involves using template expressions, enclosed within curly braces ({}), within a URL path to indicate replaceable sections using path parameters.

Each template expression in the path must align with a path parameter included in the Path Item or its Operations. However, if the Path Item is empty due to constraints like ACL, matching path parameters are not obligatory.

The values for these path parameters must not include unescaped characters specified by RFC3986, such as forward slashes (/), question marks (?), or hashes (#).

Media Types

Media type definitions are spread across several resources. The media type definitions should be in compliance with RFC6838.

Some examples of possible media type definitions:

  text/plain; charset=utf-8
  application/json
  application/vnd.github+json
  application/vnd.github.v3+json
  application/vnd.github.v3.raw+json
  application/vnd.github.v3.text+json
  application/vnd.github.v3.html+json
  application/vnd.github.v3.full+json
  application/vnd.github.v3.diff
  application/vnd.github.v3.patch

Specification

Format

An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object. For example, an array value which is a field:

{
   "field": [ 1, 2, 3 ]
}

Warning! All field names in the specification are case sensitive.

The schema exposes two types of fields: Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for the field name.

It is recommended that the root OpenAPI document be named: openapi.json or openapi.yaml.

Data Types

type format Comments
integer int32 signed 32 bits
integer int64 signed 64 bits (long)
number float
number double
string password A hint to UIs to obscure input.

OpenAPI Object

This is the root object of the OpenAPI document.

Field Name Type Description
openapi string Required. This string must be the version number of the OpenAPI Specification that the OpenAPI document uses. The openapi field should be used by tooling to interpret the OpenAPI document. This is not related to the API info.version string.
info Info Object Required. Provides metadata about the API. The metadata may be used by tooling as required.
jsonSchemaDialect string The default value for the $schema keyword within Schema Objects contained within this OAS document. This must be in the form of a URI.
servers Server Object An array of Server Objects, which provide connectivity information to a target server. If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of /.
paths Paths Object The available paths and operations for the API.
webhooks Map[string, Path Item Object Reference ObjectThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the callbacks feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses.
components Components Object An element to hold various schemas for the document.
security Security Requirement Object A declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement ({}) can be included in the array.
tags Tag Object A list of tags used by the document 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.
external docs External Documentation Object Additional external documentation.