OpenAPI V3.0 Syntax CheatSheet
OpenApi 3.0 specification in Yaml format
contents can be written in separate files, and referenced with $ref: "./schemas/User.yaml" syntax
Example:
# Version of the openapi specificaiton
openapi: 3.0.0
# General metadata about this app
info:
version: 1.0.0
title: Simple App
description: a simple app for demonstration purposes only
termsOfService: /terms-of-use
# Relative URL to external documentation
externalDocs:
url: /docs
description: Find more info here
# list of backed urls:
servers:
- url: https://example.io/v1
description: example server 1
- url: http://192.168.1.1/api/v2
description: ip server 2
- url: ws://192.168.1.1/api/v2
description: websocket
- url: wss://192.168.1.1/api/v2
description: websocket secured
- url: //192.168.1.1/api/v2
# Complex server
- url: https://{customerId}.saas-app.com:{port}/v2
variables:
customerId:
default: demo
description: Customer ID assigned by the service provider
port:
enum:
- '443'
- '8443'
default: '443'
# Authentication:
components:
securityScheme:
# Basic Authentication
BasicAuth:
type: http
scheme: basic
# Bearer Authentication
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
# Oauth2 Authentication
oauth2:
type: oauth2
flows:
authorizationCode:
authorizationUrl: /oauth/dialog
tokenUrl: /oauth/token
# Templates for "Objects"
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
# properties not in required are implicit optional
required:
- id
- name
security:
- BasicAuth: []
# The endpoints
paths:
# Basic Template
/artists-v1/{id}:
get: ... # get an object
post: ... # create an object
put: ... # update the whole object
patch: ... # update some parts of the object
delete: ... # delete the object
# Simple get method
/artists-v2:
get:
# An optional unique string to identify an operation
operationId: lockerNoteSavePath
# Tags to organize paths into components
tags:
- artists
# A quick summary
summary: Save user's locker note
# A detailed description, also supports markdown
description: >
A detailed description of the operation.
Use markdown for rich text representation,
such as **bold**, *italic*, and [links](https://swagger.io).
security:
- bearerAuth: []
parameters:
...
responses:
...
# Deprecated Operations:
/pet/findByTags:
get:
deprecated: true
# Override Global Servers
/files:
description: File upload and download operations
servers:
- url: https://files.example.com
description: Override base path for all operations with the /files path
# Parameters (Path, Query, Header, Cookie):
/artists/{noteId}:
get:
security:
- bearerAuth: []
parameters:
# Path Paramter
- name: noteId
in: path
required: true
schema:
type: integer
format: int64
# Query Parameter
- name: searchString
in: query # => https://...../artists?searchString=lll
required: true
schema:
type: integer
format: int64
# Header Parameter
- in: header
name: X-Request-ID
schema:
type: string
format: uuid
required: true
# Cookie Parameter
- in: cookie
name: csrftoken
schema:
type: string
responses:
'200':
description: Successfully returned a list of artists
content:
application/json:
schema:
type: array
items:
type: object
required:
- username
properties:
artist_name:
type: string
artist_genre:
type: string
albums_recorded:
type: integer
username:
type: string
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
message:
type: string
# Media type example
# supported media types:
# - application/json
# - application/xml
# - application/x-www-form-urlencoded
# - multipart/form-data
# - text/plain; charset=utf-8
# - text/html
# - application/pdf
# - image/png
/employees:
get:
summary: Returns a list of employees.
responses:
"200": # Response
description: OK
content: # Response body, multiple media types
application/json: # One of media types
schema:
type: object
properties:
id:
type: integer
name:
type: string
fullTime:
type: boolean
application/xml: # Another media types
schema:
type: object
properties:
id:
type: integer
name:
type: string
fullTime:
type: boolean