Skip to content

Commit

Permalink
Merge pull request #178 from Springworks/print-status-code-description
Browse files Browse the repository at this point in the history
Print status code name
  • Loading branch information
Kristofer Sommestad authored Sep 18, 2017
2 parents 77b2d31 + 3ca8ad2 commit b17a73c
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ node_modules
coverage
.eslintcache

/package-lock.json

# Ignore build output
dist
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
sudo: false
language: node_js
node_js:
- '4'
- '6'
- '7'
- '8'
cache:
directories:
- node_modules
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-eslint": "^7.1.1",
"babel-jest": "^20.0.3",
"babel-eslint": "^8.0.0",
"babel-jest": "^21.0.2",
"babel-polyfill": "^6.22.0",
"babel-preset-es2015-node4": "^2.1.1",
"eslint": "^4.3.0",
Expand All @@ -32,8 +32,8 @@
"eslint-plugin-mocha": "^4.8.0",
"eslint-plugin-springworks": "^2.0.1",
"fixture-loader": "^1.0.1",
"jest": "^18.1.0",
"semantic-release": "^6.3.2"
"jest": "^21.1.0",
"semantic-release": "^8.0.0"
},
"babel": {
"presets": [
Expand Down
26 changes: 14 additions & 12 deletions src/__tests__/__snapshots__/convert-to-markdown.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`convertToMarkdown with a valid, parsed Swagger spec providing a response_example_provider function, to generate examples for each response should return contents of a valid .md file 1`] = `
"# Swagger Petstore, version 1.0.0
Expand All @@ -23,15 +25,15 @@ Returns all pets from the system that the user has access to
| query | limit | int32 | false | maximum number of results to return | \`0 < int32 <= 200\` | \`20\` | |
| query | offset | int32 | false | results offset | \`0 <= int32\` | | |
#### Response: 200
#### Response: 200 OK
pet response
**Schema**
- (array)
- (object) A pet
- name (string) The pet\'s name
- name (string) The pet's name
- tag (string) (optional)
- id (int64)
Expand All @@ -49,7 +51,7 @@ unexpected error
\`\`\`json
{
\"foo\": \"bar\"
\\"foo\\": \\"bar\\"
}
\`\`\`
Expand All @@ -66,17 +68,17 @@ Creates a new pet in the store. Duplicates are allowed
**Request Body**
- (object) A pet
- name (string) The pet\'s name
- name (string) The pet's name
- tag (string) (optional)
#### Response: 200
#### Response: 200 OK
pet response
**Schema**
- (object) A pet
- name (string) The pet\'s name
- name (string) The pet's name
- tag (string) (optional)
- id (int64)
Expand All @@ -94,7 +96,7 @@ unexpected error
\`\`\`json
{
\"foo\": \"bar\"
\\"foo\\": \\"bar\\"
}
\`\`\`
Expand All @@ -108,14 +110,14 @@ Returns a user based on a single ID, if the user does not have access to the pet
|------|------|-------|----------|--------------------|
| path | id | int64 | true | ID of pet to fetch |
#### Response: 200
#### Response: 200 OK
pet response
**Schema**
- (object) A pet
- name (string) The pet\'s name
- name (string) The pet's name
- tag (string) (optional)
- id (int64)
Expand All @@ -133,7 +135,7 @@ unexpected error
\`\`\`json
{
\"foo\": \"bar\"
\\"foo\\": \\"bar\\"
}
\`\`\`
Expand All @@ -149,7 +151,7 @@ deletes a single pet based on the ID supplied
|------|------|-------|----------|---------------------|
| path | id | int64 | true | ID of pet to delete |
#### Response: 204
#### Response: 204 No Content
pet deleted
Expand All @@ -171,7 +173,7 @@ unexpected error
\`\`\`json
{
\"foo\": \"bar\"
\\"foo\\": \\"bar\\"
}
\`\`\`
"
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/md-table.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createTable alignment should align to a wide header 1`] = `
"| a | b | wide_header |
|---|---|-------------|
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/__snapshots__/path-generator.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generatePath with an API spec having mixed properties; some defined, some omitted should render markdown and omit unspecified data, e.g. descriptions, schemas 1`] = `
"### GET /pets/{id}
Expand All @@ -9,7 +11,7 @@ Returns a user based on a single ID, if the user does not have access to the pet
|------|------|-------|----------|--------------------|
| path | id | int64 | true | ID of pet to fetch |
#### Response: 200
#### Response: 200 OK
pet response
Expand Down Expand Up @@ -41,7 +43,7 @@ https://example.com/more-info
|------|------|-------|----------|
| path | id | int64 | true |
#### Response: 204
#### Response: 204 No Content
pet deleted
Expand Down Expand Up @@ -74,7 +76,7 @@ Creates a new pet
- (object)
- name (string)
#### Response: 201
#### Response: 201 Created
pet response
Expand Down
14 changes: 8 additions & 6 deletions src/__tests__/__snapshots__/prepare-spec.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`prepareSpec with a valid Swagger spec should inline all $ref references 1`] = `
Object {
"basePath": "/api",
Expand Down Expand Up @@ -25,7 +27,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand All @@ -43,7 +45,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down Expand Up @@ -145,7 +147,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down Expand Up @@ -209,7 +211,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand All @@ -232,7 +234,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down Expand Up @@ -344,7 +346,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/__snapshots__/resolve-api-spec.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`resolveApiSpec should resolve the spec 1`] = `
Object {
"basePath": "/api",
Expand Down Expand Up @@ -80,7 +82,7 @@ Object {
"type": "integer",
},
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down Expand Up @@ -130,7 +132,7 @@ Object {
"description": "A pet",
"properties": Object {
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand All @@ -155,7 +157,7 @@ Object {
"type": "integer",
},
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down Expand Up @@ -255,7 +257,7 @@ Object {
"type": "integer",
},
"name": Object {
"description": "The pet\'s name",
"description": "The pet's name",
"type": "string",
},
"tag": Object {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/schema-generator.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createSchemaList with a array schema of $refs should return a list with the properties 1`] = `
"- (array)
- ($ref: \`#/definitions/Pet\`)"
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/toc-generator.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generateTableOfContents should return the TOC section 1`] = `
"- [Endpoints](#endpoints)
- [GET /pets](#get-pets)
Expand Down
21 changes: 12 additions & 9 deletions src/generators/path-generator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/**
* Generates markdown for a specific Swagger path,
* including all of its methods.
*/

import schema_generator from './schema-generator';
import { STATUS_CODES } from 'http';
import createParametersTable from './request-parameters-table';
import schema_generator from './schema-generator';

function generateMethods(path_key, path, response_example_provider) {
return Object.keys(path).map(method => {
Expand Down Expand Up @@ -38,11 +34,11 @@ function generateBodySchema(params) {
}

function generateResponses(responses) {
return Object.keys(responses).map(response_key => {
const response = responses[response_key];
return Object.keys(responses).map(status_code => {
const response = responses[status_code];
const schema = generateResponseSchema(response);
return [
`#### Response: ${response_key}`,
`#### Response: ${formatStatusCode(status_code)}`,
response.description,
'**Schema**',
schema,
Expand All @@ -68,6 +64,13 @@ function generateExampleResponse(path_key, method, response_example_provider) {
].join('\n\n');
}

function formatStatusCode(status_code) {
if (STATUS_CODES.hasOwnProperty(status_code)) {
return `${status_code} ${STATUS_CODES[status_code]}`;
}
return status_code;
}

function deprecationWarning(spec) {
return spec.deprecated ? '> :warning: **deprecated**' : null;
}
Expand Down
8 changes: 4 additions & 4 deletions test-fixtures/fixtures/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Returns all pets from the system that the user has access to
| query | limit | int32 | false | maximum number of results to return | `0 < int32 <= 200` | `20` | |
| query | offset | int32 | false | results offset | `0 <= int32` | | |

#### Response: 200
#### Response: 200 OK

pet response

Expand Down Expand Up @@ -60,7 +60,7 @@ Creates a new pet in the store. Duplicates are allowed
- name (string) The pet's name
- tag (string) (optional)

#### Response: 200
#### Response: 200 OK

pet response

Expand Down Expand Up @@ -91,7 +91,7 @@ Returns a user based on a single ID, if the user does not have access to the pet
|------|------|-------|----------|--------------------|
| path | id | int64 | true | ID of pet to fetch |

#### Response: 200
#### Response: 200 OK

pet response

Expand Down Expand Up @@ -124,7 +124,7 @@ deletes a single pet based on the ID supplied
|------|------|-------|----------|---------------------|
| path | id | int64 | true | ID of pet to delete |

#### Response: 204
#### Response: 204 No Content

pet deleted

Expand Down

0 comments on commit b17a73c

Please sign in to comment.