Skip to main content

OpenAPI & Meta-API

Usage of OpenAPI in Meta API

Meta API has been created to support any APIs, even the private ones. To achieve this, we rely on Open API Specifications to have a standard and universal support.

OpenAPI Specification (OAS) is also known as Swagger, the version 2.0 of this standard.

OAS can be written in YAML or JSON

Anatomy and main parts of an OpenAPI Specification file

Here is the standard structure of an OpenAPI file:

  • openapi: The OpenAPI version
  • info: Some meta information about this API
  • servers: The list of servers
  • path: the list of paths (endpoints) declared inside the API
    • For each path, we can have multiple methods (GET, POST, PATCH, PUT, DELETE) and, for each method, the declaration of security, body schema and the response
  • components: Components allow to declare some schemas and to reuse them across the API
  • securitySchemas: Schemas to describe supported authentication on this API
  • security: A global configuration of security inside this API, referring to a securitySchemas

OpenAPI is a descriptive standard, so you can have very detailed or a broad description of your API

Example of a Swagger file

{
"openapi": "3.0.1",
"info": {
"title": "Swagger Petstore",
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"email": "apiteam@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0.0"
},
"externalDocs": {
"description": "Find out more about Swagger",
"url": "http://swagger.io"
},
"servers": [
{
"url": "https://petstore.swagger.io/v2"
}
],
"paths": {
"/pet": {
"put": {
"tags": [
"pet"
],
"summary": "Update an existing pet",
"operationId": "updatePet",
"requestBody": {
"description": "Pet object that needs to be added to the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
},
"responses": {
"400": {
"description": "Invalid ID supplied",
"content": {}
},
"404": {
"description": "Pet not found",
"content": {}
},
"405": {
"description": "Validation exception",
"content": {}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"x-codegen-request-body-name": "body"
},
"post": {
"tags": [
"pet"
],
"summary": "Add a new pet to the store",
"operationId": "addPet",
"requestBody": {
"description": "Pet object that needs to be added to the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
},
"responses": {
"405": {
"description": "Invalid input",
"content": {}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"x-codegen-request-body-name": "body"
}
}
},
"components": {
"schemas": {
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Category"
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Tag"
}
},
"Pet": {
"required": [
"name",
"photoUrls"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"category": {
"$ref": "#/components/schemas/Category"
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"xml": {
"name": "photoUrl",
"wrapped": true
},
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"xml": {
"name": "tag",
"wrapped": true
},
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
},
"xml": {
"name": "Pet"
}
}
},
"securitySchemes": {
"petstore_auth": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
},
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
}
}
}