Update swagger examples in the demo

This commit is contained in:
Kam Low 2017-04-02 14:30:24 +02:00
parent 8366d85478
commit c9318b4c8d
7 changed files with 2764 additions and 374 deletions

View File

@ -1,3 +1,3 @@
Update cheesestore with proper request/response examples
Improve range and enum output
Render remote references
- https://github.com/sourcey/spectacle/pull/41

View File

@ -94,7 +94,10 @@ var common = {
var that = this;
if (ref.$ref) {
if (ref.example) {
return ref.example;
}
else if (ref.$ref) {
ref = this.resolveSchemaReference(ref.$ref, root);
return this.formatExampleProp(ref, root);
}
@ -115,9 +118,6 @@ var common = {
else if (ref.items && ref.type == 'array') {
return [ this.formatExampleProp(ref.items, root) ];
}
else if (ref.example) {
return ref.example;
}
else if (ref.type) {
return ref.type + (ref.format ? ' (' + ref.format + ')' : '');
}

View File

@ -41,10 +41,12 @@
{{! Print examples without whitespace. }}
<div class="doc-examples">
{{#each responses}}
{{#if schema}}
<section>
<h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
{{>swagger/print-example .}}
</section>
{{/if}}
{{/each}}
</div>
</div>

View File

@ -1,6 +1,6 @@
{
"name": "spectacle-docs",
"version": "0.8.1",
"version": "0.8.2",
"description": "Generate beautiful static API documentation from OpenAPI/Swagger 2.0 specifications",
"preferGlobal": true,
"bin": {

File diff suppressed because it is too large Load Diff

117
test.yml
View File

@ -1,117 +0,0 @@
swagger: 2.0
info:
version: 1.0.0
title: Sprockets and springs API
description: >-
Covering all your needs for sprockets and springs.
contact:
name: Sprocket!
url: https://sprocketsprings.biz
email: post@sprocketsprings.biz
basePath: /api/v1
consumes:
- application/json
produces:
- application/json
paths:
/sprockets:
get:
summary: Get list of sprockets
description: >-
This method returns all your sprockets. No exceptions, even Tiny Timmy is returned.
operationId: getSprockets
responses:
200:
description: A list of sprockets
schema:
type: array
items:
$ref: '#/definitions/Sprocket'
post:
summary: Create a new sprocket
description: >-
Use this method to create a new sprocket. Make sure it is a good sprocket. Remember what that bad one did to Uncle Jim.
operationId: createSprocket
parameters:
- name: sprocket
in: body
description: The sprocket definition
required: true
schema:
$ref: '#/definitions/NewSprocket'
responses:
'200':
description: The new sprocket
schema:
$ref: '#/definitions/Sprocket'
'/sprockets/{id}':
get:
summary: Get a specific sprocket
description: >-
Use this method when you need just that one special sprocket in your life. You will get one, and only one.
operationId: getSprocket
parameters:
- name: id
in: path
description: numerical id of sprocket
required: true
type: integer
responses:
'200':
description: Details of the sprocket
schema:
$ref: '#/definitions/Sprocket'
post:
summary: Update sprocket
description: >-
This is the method to use when you down on your luck and created a sprocket with the wrong specification.
operationId: updateSprocket
parameters:
- name: id
in: path
description: numerical id of sprocket
required: true
type: integer
- name: sprocket
in: body
description: Correct definition of sprocket
required: true
schema:
$ref: '#/definitions/Sprocket'
responses:
'200':
description: The newly updated sprocket definition
schema:
$ref: '#/definitions/Sprocket'
definitions:
Sprocket:
allOf:
- $ref: '#/definitions/NewSprocket'
- type: object
required:
- id
properties:
id:
type: integer
format: int32
example: 201
NewSprocket:
type: object
required:
- name
- radius
- teeth
properties:
name:
type: string
example: My magical sprocket
radius:
type: float
example: 12.0
teeth:
type: int
example: 22
description:
type: string
example: My dearest little sprocket. How I cherish it.

View File

@ -73,11 +73,14 @@
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/Cheese1"
"$ref": "#/definitions/Cheese"
}
},
"405": {
"description": "Invalid input"
"422": {
"description": "Invalid input",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
},
"security": [
@ -116,14 +119,17 @@
}
],
"responses": {
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Cheese not found"
"description": "Cheese not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
},
"405": {
"description": "Validation exception"
"422": {
"description": "Validation exception",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
},
"security": [
@ -171,8 +177,11 @@
}
}
},
"400": {
"description": "Invalid tag value"
"404": {
"description": "Invalid tag value",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
},
"security": [
@ -215,16 +224,10 @@
"$ref": "#/definitions/Cheese"
}
},
"400": {
"description": "Invalid ID supplied",
"schema": {
"$ref": "#/definitions/Error"
}
},
"404": {
"description": "Cheese not found",
"schema": {
"$ref": "#/definitions/Error"
"$ref": "#/definitions/NotFoundError"
}
}
},
@ -273,8 +276,11 @@
}
],
"responses": {
"405": {
"description": "Invalid input"
"422": {
"description": "Cannot update cheese",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
},
"security": [
@ -314,16 +320,10 @@
}
],
"responses": {
"400": {
"description": "Invalid ID supplied",
"schema": {
"$ref": "#/definitions/Error"
}
},
"404": {
"description": "Cheese not found",
"schema": {
"$ref": "#/definitions/Error"
"$ref": "#/definitions/NotFoundError"
}
}
},
@ -378,10 +378,10 @@
}
}
},
"400": {
"404": {
"description": "Invalid status value",
"schema": {
"$ref": "#/definitions/Error"
"$ref": "#/definitions/NotFoundError"
}
}
},
@ -456,8 +456,8 @@
"tags": [
"Store"
],
"summary": "Return cheese inventories by status",
"description": "Returns a map of status codes to quantities.",
"summary": "Return cheese inventories by available status",
"description": "Returns a list of available cheeses.",
"operationId": "getInventory",
"produces": [
"application/json"
@ -467,10 +467,9 @@
"200": {
"description": "Successful operation",
"schema": {
"type": "object",
"additionalProperties": {
"type": "integer",
"format": "int32"
"type": "array",
"items": {
"$ref": "#/definitions/Cheese"
}
}
}
@ -512,8 +511,11 @@
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid Order"
"422": {
"description": "Invalid order",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
}
}
@ -524,7 +526,7 @@
"Store"
],
"summary": "Find purchase order by ID",
"description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
"description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generate exceptions.",
"operationId": "getOrderById",
"produces": [
"application/xml",
@ -549,11 +551,11 @@
"$ref": "#/definitions/Order"
}
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Order not found"
"description": "Order not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
}
},
@ -562,7 +564,7 @@
"Store"
],
"summary": "Delete purchase order by ID",
"description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors",
"description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors.",
"operationId": "deleteOrder",
"produces": [
"application/xml",
@ -580,11 +582,11 @@
}
],
"responses": {
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Order not found"
"description": "Order not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
}
}
@ -699,8 +701,11 @@
}
}
},
"400": {
"description": "Invalid username/password supplied"
"422": {
"description": "Invalid username/password supplied",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
}
}
@ -753,11 +758,11 @@
"$ref": "#/definitions/Customer"
}
},
"400": {
"description": "Invalid username supplied"
},
"404": {
"description": "Customer not found"
"description": "Customer not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
}
},
@ -795,7 +800,10 @@
"description": "Invalid customer supplied"
},
"404": {
"description": "Customer not found"
"description": "Customer not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
}
},
@ -824,7 +832,10 @@
"description": "Invalid username supplied"
},
"404": {
"description": "Customer not found"
"description": "Customer not found",
"schema": {
"$ref": "#/definitions/NotFoundError"
}
}
}
}
@ -885,7 +896,7 @@
"complete": "true",
"id": "1",
"quantity": "66",
"shipDate": "2016/10/04 00:09:21 +0000",
"shipDate": "04-10-2017 00:09:21 UTC",
"status": "available"
},
"xml": {
@ -897,10 +908,12 @@
"properties": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"example": 1
},
"name": {
"type": "string"
"type": "string",
"example": "Italian Cheese"
}
},
"xml": {
@ -912,30 +925,45 @@
"properties": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"example": 1
},
"username": {
"type": "string"
"type": "string",
"example": "gordo"
},
"firstName": {
"type": "string"
"type": "string",
"description": "Customer first name",
"example": "Alotta"
},
"lastName": {
"type": "string"
"type": "string",
"description": "Customer last name",
"example": "Cheese"
},
"email": {
"type": "string"
"type": "string",
"example": "love@cheese.com"
},
"password": {
"type": "string"
"type": "string",
"example": "secret"
},
"phone": {
"type": "string"
"type": "string",
"example": "+3344556677"
},
"customerStatus": {
"type": "integer",
"format": "int32",
"description": "Customer Status"
"type": "string",
"description": "Customer status (the heavier the better)",
"enum": [
"skinny",
"average",
"fat",
"obese"
],
"example": "obese"
}
},
"xml": {
@ -947,10 +975,12 @@
"properties": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"example": 1
},
"name": {
"type": "string"
"type": "string",
"example": "Manchego"
}
},
"xml": {
@ -965,10 +995,48 @@
"format": "int32"
},
"type": {
"type": "string"
"type": "string",
"example": "No cheese found"
},
"message": {
"type": "string"
"type": "string",
"example": "No cheese for you!"
}
}
},
"ValidationError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"example": 422
},
"type": {
"type": "string",
"example": "Validation error"
},
"message": {
"type": "string",
"example": "Your cheese is not mouldy enough"
}
}
},
"NotFoundError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"example": 404
},
"type": {
"type": "string",
"example": "Not found"
},
"message": {
"type": "string",
"example": "Your cheese has already been eaten"
}
}
},
@ -981,7 +1049,8 @@
"properties": {
"id": {
"type": "integer",
"format": "int64"
"format": "int64",
"example": 1
},
"category": {
"$ref": "#/definitions/Category"
@ -998,7 +1067,10 @@
},
"items": {
"type": "string"
}
},
"example": [
"https://wannabechef.com/gorgonzola.jpg"
]
},
"tags": {
"type": "array",
@ -1012,12 +1084,13 @@
},
"status": {
"type": "string",
"description": "cheese status in the store",
"description": "Cheese status in the store",
"enum": [
"available",
"pending",
"sold"
]
],
"example": "available"
}
},
"xml": {