Skip to content

Instantly share code, notes, and snippets.

@marbemac
Created October 18, 2016 16:26
Show Gist options
  • Save marbemac/42a72be56fc7dd7df6cfc6074cfe6b69 to your computer and use it in GitHub Desktop.
Save marbemac/42a72be56fc7dd7df6cfc6074cfe6b69 to your computer and use it in GitHub Desktop.
todo yaml
---
swagger: '2.0'
info:
version: '1.0'
title: To-do Demo
description: |-
## Welcome
This is a place to put general notes and extra information, for internal use.
To 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:
afterScript: |-
function (ctx, request, response) {
// Store the latest fetched todo id in variables
// for easy use.
if (response.statusCode.get() == 200) {
var body = response.body.get();
SL.variables.lastTodoId = body.id;
}
}
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:
afterScript:
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:
afterScript:
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) {
// Your javascript code here.
// Code completion enabled.
// You have access to a global "SL" object.wef
}
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:
afterScript:
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:
afterScript:
public: true
mock:
enabled: true
dynamic:
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) {
// Your javascript code here.
// Code completion enabled.
// You have access to a global "SL" object.
}
afterScript: |-
function (ctx, request, response) {
// Your javascript code here.
// Code completion enabled.
// You have access to a global "SL" object.
}
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:
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:
- name: Models
description:
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:
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).
It 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.
### Referencing
See the List Todos endpoint for an example of creating a response body from an array of models (the Todo Full model in this case).
### Inheritance
Check out the Todo Full model to see inheritance.
### Mocking
Check 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:
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: |-
{
"name": "my todo's name",
"completed": false
}
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:
afterScript:
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:
afterScript:
capture: {}
request:
method: put
url: "/todos/{todoId}?apikey=123"
headers: []
queryString:
- name: apikey
value: '123'
postData:
mimeType: application/json
params: []
text: |-
{
"name": "my todo's new name",
"completed": false
}
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:
afterScript:
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:
afterScript:
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