Skip to content

Instantly share code, notes, and snippets.

@biggates
Last active February 2, 2023 23:33
Show Gist options
  • Save biggates/4955d608379a8b1b3224e815c7dd0dc9 to your computer and use it in GitHub Desktop.
Save biggates/4955d608379a8b1b3224e815c7dd0dc9 to your computer and use it in GitHub Desktop.
Example of OpenAPI Specification v3.0.0, containing multiple examples of requestBody
{
"openapi": "3.0.2",
"info": {
"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.",
"version": "1.0.0",
"title": "Swagger Petstore",
"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"
}
},
"servers": [{
"url": "http://petstore.swagger.io/v2"
}],
"tags": [{
"name": "pet",
"description": "Everything about your Pets",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
}],
"paths": {
"/pet/findByStatus/MultipleExamples": {
"get": {
"tags": ["pet"],
"summary": "Finds Pets by status",
"description": "Multiple status values can be provided with comma separated strings",
"operationId": "findPetsByStatus",
"produces": ["application/xml", "application/json"],
"parameters": [{
"name": "status",
"in": "query",
"description": "Status values that need to be considered for filter",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": ["available", "pending", "sold"],
"default": "available"
}
},
"style": "form",
"explode": true,
"examples": {
"Available": {
"summary": "Available",
"description": "Showing status of `available`, using `value` property",
"value": "available"
},
"Sold": {
"summary": "Sold",
"description": "Showing status of `sold`, using `externalValue` property",
"externalValue": "http://example.com/examples/dog.json"
}
}
}],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"examples": {
"No Content": {
"summary": "Example response showing no pets are matched",
"description": "An example response, using `value` property",
"value": []
},
"Example 1": {
"summary": "Example response showing a regular response",
"description": "Two pets are returned in this example.",
"value": [{
"id": 1,
"category": {
"id": 1,
"name": "cat"
},
"name": "fluffy",
"photoUrls": [
"http://example.com/path/to/cat/1.jpg",
"http://example.com/path/to/cat/2.jpg"
],
"tags": [{
"id": 1,
"name": "cat"
}],
"status": "available"
}, {
"id": 2,
"category": {
"id": 2,
"name": "dog"
},
"name": "puppy",
"photoUrls": [
"http://example.com/path/to/dog/1.jpg"
],
"tags": [{
"id": 2,
"name": "dog"
}],
"status": "available"
}]
}
}
}
}
},
"400": {
"description": "Invalid status value"
}
},
"security": [{
"petstore_auth": ["write:pets", "read:pets"]
}]
}
},
"/pet/findByStatus/singleExample": {
"get": {
"tags": ["pet"],
"summary": "Finds Pets by status",
"description": "Multiple status values can be provided with comma separated strings",
"operationId": "findPetsByStatus",
"produces": ["application/xml", "application/json"],
"parameters": [{
"name": "status",
"in": "query",
"description": "Status values that need to be considered for filter",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": ["available", "pending", "sold"],
"default": "available"
}
},
"style": "form",
"explode": true,
"example": {
"summary": "Available",
"description": "Showing status of `available`, using `value` property",
"value": "available"
}
}],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"example": {
"summary": "Example response showing a regular response",
"description": "Two pets are returned in this example.",
"value": [{
"id": 1,
"category": {
"id": 1,
"name": "cat"
},
"name": "fluffy",
"photoUrls": [
"http://example.com/path/to/cat/1.jpg",
"http://example.com/path/to/cat/2.jpg"
],
"tags": [{
"id": 1,
"name": "cat"
}],
"status": "available"
}, {
"id": 2,
"category": {
"id": 2,
"name": "dog"
},
"name": "puppy",
"photoUrls": [
"http://example.com/path/to/dog/1.jpg"
],
"tags": [{
"id": 2,
"name": "dog"
}],
"status": "available"
}]
}
}
}
},
"400": {
"description": "Invalid status value"
}
},
"security": [{
"petstore_auth": ["write:pets", "read:pets"]
}]
}
},
"/pet": {
"post": {
"tags": ["pet"],
"summary": "Add a new pet to the store",
"description": "",
"operationId": "addPet",
"requestBody": {
"description": "Pet object that needs to be added to the store",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
},
"examples": {
"Cat": {
"summary": "An example of cat",
"description": "An example of cat, using `value` property",
"value": {
"id": 1,
"category": {
"id": 1,
"name": "cat"
},
"name": "fluffy",
"photoUrls": [
"http://example.com/path/to/cat/1.jpg",
"http://example.com/path/to/cat/2.jpg"
],
"tags": [{
"id": 1,
"name": "cat"
}],
"status": "available"
}
},
"Cat2": {
"summary": "An example of cat",
"description": "An example of cat, using `value` property, which value is an array",
"value": [{
"id": 1,
"category": {
"id": 1,
"name": "cat"
},
"name": "fluffy",
"photoUrls": [
"http://example.com/path/to/cat/1.jpg",
"http://example.com/path/to/cat/2.jpg"
],
"tags": [{
"id": 1,
"name": "cat"
}],
"status": "available"
}]
},
"Dog": {
"summary": "An example of dog",
"description": "An example of dog, using `externalValue` property",
"externalValue": "http://example.com/examples/dog.json"
}
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
},
"examples": {
"Cat": {
"summary": "An example of cat",
"description": "An example of cat, using `value` property",
"value": "<xml></xml>"
},
"Dog": {
"summary": "An example of dog",
"description": "An example of dog, using `externalValue` property",
"externalValue": "http://example.com/examples/dog.xml"
}
}
}
}
},
"responses": {
"405": {
"description": "Invalid input"
}
}
}
}
},
"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": {
"type": "object",
"required": ["name", "photoUrls"],
"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"
}
}
}
},
"externalDocs": {
"description": "Find out more about Swagger",
"url": "http://swagger.io"
}
}
@y0n3r
Copy link

y0n3r commented Jul 5, 2022

@ekeyser Thank you! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment