Skip to content

Instantly share code, notes, and snippets.

@marbemac
Last active June 28, 2017 17:54
Show Gist options
  • Save marbemac/85de56344ba86d769a6aeab66dcf7de8 to your computer and use it in GitHub Desktop.
Save marbemac/85de56344ba86d769a6aeab66dcf7de8 to your computer and use it in GitHub Desktop.
Stoplight To-do Demo Swagger
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "To-do Demo",
"description": "## Welcome\n\nThis is a place to put general notes and extra information, for internal use.\n\nTo get started designing/documenting this API, select a version on the left."
},
"host": "todos.stoplight.io",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"securityDefinitions": {
"apikey": {
"name": "apikey",
"type": "apiKey",
"in": "query"
}
},
"paths": {
"/todos/{todoId}": {
"parameters": [
{
"name": "todoId",
"in": "path",
"required": true,
"type": "string"
}
],
"get": {
"operationId": "GET_todo",
"summary": "Get Todo",
"tags": [
"Todos"
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/todo-full"
}
},
"401": {
"$ref": "#/responses/trait:standardErrors:401"
},
"404": {
"$ref": "#/responses/trait:standardErrors:404"
}
},
"x-stoplight": {
"id": "GET_todo",
"beforeScript": null,
"afterScript": "function (ctx, request, response) {\n // Store the latest fetched todo id in variables\n // for easy use.\n if (response.statusCode.get() == 200) {\n var body = response.body.get();\n SL.variables.lastTodoId = body.id;\n }\n}",
"public": true,
"mock": {
"enabled": false,
"dynamic": false,
"statusCode": 200
}
}
},
"put": {
"operationId": "PUT_todos",
"summary": "Update Todo",
"tags": [
"Todos"
],
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/todo-partial",
"example": {
"name": "my todo's new name",
"completed": false
}
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/todo-full"
}
},
"401": {
"$ref": "#/responses/trait:standardErrors:401"
},
"403": {
"description": "",
"schema": {
"type": "object"
}
},
"404": {
"$ref": "#/responses/trait:standardErrors:404"
}
},
"security": [
{
"apikey": []
}
],
"x-stoplight": {
"id": "PUT_todos",
"beforeScript": null,
"afterScript": null,
"public": true,
"mock": {
"enabled": false,
"dynamic": false,
"statusCode": 200
}
}
},
"delete": {
"operationId": "DELETE_todo",
"summary": "Delete Todo",
"tags": [
"Todos"
],
"responses": {
"204": {
"description": "",
"schema": {
"type": "object",
"properties": {}
}
},
"401": {
"$ref": "#/responses/trait:standardErrors:401"
},
"404": {
"$ref": "#/responses/trait:standardErrors:404"
}
},
"security": [
{
"apikey": []
}
],
"x-stoplight": {
"id": "DELETE_todo",
"beforeScript": null,
"afterScript": null,
"public": true,
"mock": {
"enabled": false,
"dynamic": false,
"statusCode": 200
}
}
}
},
"/todos": {
"post": {
"operationId": "POST_todos",
"summary": "Create Todo",
"tags": [
"Todos"
],
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/todo-partial",
"example": {
"name": "my todo's name",
"completed": false
}
}
}
],
"responses": {
"201": {
"description": "",
"schema": {
"$ref": "#/definitions/todo-full"
}
},
"401": {
"$ref": "#/responses/trait:standardErrors:401"
},
"403": {
"description": "",
"schema": {
"type": "object",
"properties": {}
}
},
"404": {
"$ref": "#/responses/trait:standardErrors:404"
}
},
"security": [
{
"apikey": []
}
],
"x-stoplight": {
"id": "POST_todos",
"beforeScript": "function (ctx, request) {\n // Your javascript code here.\n // Code completion enabled.\n // You have access to a global \"SL\" object.wef\n}",
"afterScript": "function (ctx, request, response) {\n // If we successfully created a todo, store \n // it's id as a variable for later use.\n if (response.statusCode.get() == 200) {\n var body = response.body.get();\n SL.variables.lastTodoId = body.id;\n }\n \n request.url.query.get('p')\n}",
"public": true,
"mock": {
"statusCode": 200,
"enabled": false,
"dynamic": false
}
}
},
"get": {
"operationId": "GET_todos",
"summary": "List Todos",
"tags": [
"Todos"
],
"parameters": [
{
"$ref": "#/parameters/trait:paged:limit"
},
{
"$ref": "#/parameters/trait:paged:skip"
}
],
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/todo-full"
}
}
},
"401": {
"$ref": "#/responses/trait:standardErrors:401"
},
"404": {
"$ref": "#/responses/trait:standardErrors:404"
}
},
"x-stoplight": {
"id": "GET_todos",
"beforeScript": null,
"afterScript": null,
"public": true,
"mock": {
"enabled": false,
"dynamic": false,
"statusCode": 200
}
}
}
},
"/mocked": {
"get": {
"operationId": "GET_mocked",
"summary": "Mock Example",
"tags": [
"Misc"
],
"description": "This is an example of a mocked endpoint. \n\nThis endpoint does not actually exist in the api - try visiting [http://todos.stoplight.io/mocked](http://todos.stoplight.io). You will see the default response (same as you get when you visit the root \"/\" url).\n\nWe have defined a 200 response below, with an example, and then explicitly turned on mocking for this endpoint via the dropdown in the right sidebar.\n\nWith this enabled, if you visit {your prism instance host}/mocked, you'll see the mocked example. You can find the mock server host for this API by clicking the \"Design Dashboard\" button at the top of this screen. You can also try sending a test request by clicking \"send test request\" button in the right sidebar.",
"responses": {
"200": {
"description": "",
"schema": {
"type": "object",
"properties": {
"this": {
"type": "string"
},
"mocked": {
"type": "boolean"
}
}
}
}
},
"x-stoplight": {
"id": "GET_mocked",
"beforeScript": null,
"afterScript": null,
"public": true,
"mock": {
"enabled": true,
"dynamic": null,
"statusCode": 200
}
}
}
}
},
"parameters": {
"trait:paged:limit": {
"name": "limit",
"in": "query",
"description": "This is how it works.",
"required": false,
"type": "integer",
"maximum": 100
},
"trait:paged:skip": {
"name": "skip",
"in": "query",
"required": false,
"type": "string"
}
},
"responses": {
"trait:standardErrors:401": {
"description": "",
"schema": {
"type": "object"
}
},
"trait:standardErrors:404": {
"description": "",
"schema": {
"type": "object",
"properties": {
"status": {
"type": "string"
},
"error": {
"type": "string"
}
},
"required": [
"status",
"error"
]
}
},
"trait:standardErrors:403": {
"description": "",
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
]
}
},
"trait:standardErrors:500": {
"description": "",
"schema": {
"type": "object"
}
}
},
"definitions": {
"todo-partial": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"completed": {
"type": [
"boolean",
"null"
]
}
},
"required": [
"name"
],
"x-stoplight": {
"id": "todo-partial",
"name": "Todo Partial",
"public": true
}
},
"todo-full": {
"allOf": [
{
"$ref": "#/definitions/todo-partial"
},
{
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"completed_at": {
"type": [
"string",
"null"
],
"format": "date-time"
},
"created_at": {
"type": "string",
"format": "date-time"
},
"updated_at": {
"type": "string",
"format": "date-time"
}
},
"required": [
"id"
]
}
],
"x-stoplight": {
"id": "todo-full",
"name": "Todo Full",
"public": true
}
}
},
"x-stoplight": {
"beforeScript": "function(ctx, request) {\n // Your javascript code here.\n // Code completion enabled.\n // You have access to a global \"SL\" object.\n}",
"afterScript": "function (ctx, request, response) {\n // Your javascript code here.\n // Code completion enabled.\n // You have access to a global \"SL\" object.\n}",
"version": {
"groups": {
"docs": [
{
"name": "Getting Started",
"divider": false,
"items": [
{
"_id": "introduction-SkXxEP6WQ3BtB5hGE",
"type": "docTextSections"
},
{
"_id": "authentication-Gr5fdxLAkBxm8xQBt",
"type": "docTextSections"
}
]
},
{
"name": "API Reference",
"divider": true,
"items": []
},
{
"description": null,
"divider": false,
"items": [
{
"_id": "GET_todo",
"type": "endpoints"
},
{
"_id": "POST_todos",
"type": "endpoints"
},
{
"_id": "PUT_todos",
"type": "endpoints"
},
{
"_id": "DELETE_todo",
"type": "endpoints"
},
{
"type": "endpoints",
"_id": "GET_todos"
}
],
"name": "Todos"
},
{
"divider": false,
"items": [
{
"_id": "GET_mocked",
"type": "endpoints"
}
],
"name": "Misc",
"description": null
},
{
"name": "Models",
"description": null,
"divider": false,
"items": [
{
"type": "schemas",
"_id": "todo-full"
},
{
"_id": "todo-partial",
"type": "schemas"
}
]
},
{
"divider": false,
"items": [
{
"_id": "paged",
"type": "traits"
},
{
"type": "traits",
"_id": "standardErrors"
}
],
"name": "Traits",
"description": null
}
],
"tests": []
}
},
"functions": {},
"textSections": {
"introduction-SkXxEP6WQ3BtB5hGE": {
"id": "introduction-SkXxEP6WQ3BtB5hGE",
"name": "Introduction",
"content": "This is a real API, that lives at [http://todos.stoplight.io](http://todos.stoplight.io).\n\nIt demonstrates several aspects of the StopLight design module, including model $referencing, model inheritance, traits, mocking, and testing. Feel free to explore the resources in this API to see how everything is put together.\n\n### Referencing\n\nSee the List Todos endpoint for an example of creating a response body from an array of models (the Todo Full model in this case).\n\n### Inheritance\n\nCheck out the Todo Full model to see inheritance.\n\n### Mocking\n\nCheck out the Mock Example endpoint to see mocking in action.",
"public": true
},
"authentication-Gr5fdxLAkBxm8xQBt": {
"id": "authentication-Gr5fdxLAkBxm8xQBt",
"name": "Authentication",
"content": "Authentication is very simple. Just add a query string parameter, \"apikey\", with the value \"123\", to requests that require authentication.",
"public": true
}
},
"mock": {
"enabled": false,
"dynamic": false
}
},
"x-tests": {
"mSwzWicXnGEJJjiyx": {
"id": "mSwzWicXnGEJJjiyx",
"name": "Todo Crud",
"initialVariables": {},
"steps": [
{
"id": "cj36qaBWqY3zznhnC",
"name": "Create Todo",
"beforeScript": null,
"afterScript": "function (ctx, request, response) {\n // Your javascript code here.\n // Code completion enabled.\n // You have access to a global \"SL\" object.\n \n var body = response.body.get();\n assert()\n}",
"capture": {
"body": [
{
"name": "todoId",
"value": "id"
}
]
},
"request": {
"method": "post",
"url": "/todos?apikey=123",
"headers": [],
"queryString": [
{
"name": "apikey",
"value": "123"
}
],
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\n \"name\": \"my todo's name\",\n \"completed\": false\n}"
},
"authentication": {
"authType": "basic",
"params": [
{
"name": "foo",
"value": "bar"
}
]
},
"valid": 2,
"transformed": false,
"pathParams": [],
"cookies": [],
"headersSize": -1,
"bodySize": -1
},
"assertions": [
{
"op": "eq",
"location": "response.code",
"expected": 201
},
{
"op": "validate.pass",
"match": 201,
"location": "response.body"
}
]
},
{
"id": "SSd64GudiP8xaHSBr",
"name": "Get Todo",
"beforeScript": null,
"afterScript": null,
"capture": {},
"request": {
"method": "get",
"url": "/todos/{todoId}",
"headers": [],
"queryString": [],
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{}"
},
"authentication": {},
"valid": 2,
"transformed": false,
"pathParams": [],
"cookies": [],
"headersSize": -1,
"bodySize": -1
},
"assertions": [
{
"op": "eq",
"location": "response.code",
"expected": 200
},
{
"op": "validate.pass",
"match": 200,
"location": "response.body"
}
]
},
{
"id": "LhReD6bXS8D66wAMq",
"name": "Update Todo",
"beforeScript": null,
"afterScript": null,
"capture": {},
"request": {
"method": "put",
"url": "/todos/{todoId}?apikey=123",
"headers": [],
"queryString": [
{
"name": "apikey",
"value": "123"
}
],
"postData": {
"mimeType": "application/json",
"params": [],
"text": "{\n \"name\": \"my todo's new name\",\n \"completed\": false\n}"
},
"authentication": {},
"valid": 2,
"transformed": false,
"pathParams": [],
"cookies": [],
"headersSize": -1,
"bodySize": -1
},
"assertions": [
{
"op": "eq",
"location": "response.code",
"expected": 200
},
{
"op": "validate.pass",
"match": 200,
"location": "response.body"
}
]
},
{
"id": "452aELkny8J5Kw2sz",
"name": "Delete Todo",
"beforeScript": null,
"afterScript": null,
"capture": {},
"request": {
"method": "delete",
"url": "/todos/{todoId}?apikey=123",
"headers": [],
"queryString": [
{
"name": "apikey",
"value": "123"
}
],
"postData": {},
"authentication": {},
"valid": 2,
"transformed": false,
"pathParams": [],
"cookies": [],
"headersSize": -1,
"bodySize": -1
},
"assertions": [
{
"op": "eq",
"location": "response.code",
"expected": 204
},
{
"op": "validate.pass",
"match": 204,
"location": "response.body"
}
]
},
{
"id": "uz6vDZGLToZKQz54s",
"name": "Get Non",
"beforeScript": null,
"afterScript": null,
"capture": {
"body": []
},
"request": {
"method": "get",
"url": "/todos/{todoId}",
"headers": [],
"queryString": [],
"postData": {},
"authentication": {},
"valid": 2,
"transformed": false,
"pathParams": [],
"cookies": [],
"headersSize": -1,
"bodySize": -1
},
"assertions": [
{
"op": "eq",
"location": "response.code",
"expected": 404
}
]
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment