diff --git a/.gitignore b/.gitignore index e5a67f2..789f7df 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,7 @@ node_modules coverage .eslintcache +/package-lock.json + # Ignore build output dist diff --git a/.travis.yml b/.travis.yml index cf18a56..a3fb086 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ sudo: false language: node_js node_js: - - '4' - - '6' - - '7' + - '8' cache: directories: - node_modules diff --git a/package.json b/package.json index d3eb06d..2afbdfc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [ diff --git a/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap b/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap index 4dfc5fe..e73a8de 100644 --- a/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap +++ b/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap @@ -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 @@ -23,7 +25,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 @@ -31,7 +33,7 @@ pet response - (array) - (object) A pet - - name (string) The pet\'s name + - name (string) The pet's name - tag (string) (optional) - id (int64) @@ -49,7 +51,7 @@ unexpected error \`\`\`json { - \"foo\": \"bar\" + \\"foo\\": \\"bar\\" } \`\`\` @@ -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) @@ -94,7 +96,7 @@ unexpected error \`\`\`json { - \"foo\": \"bar\" + \\"foo\\": \\"bar\\" } \`\`\` @@ -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) @@ -133,7 +135,7 @@ unexpected error \`\`\`json { - \"foo\": \"bar\" + \\"foo\\": \\"bar\\" } \`\`\` @@ -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 @@ -171,7 +173,7 @@ unexpected error \`\`\`json { - \"foo\": \"bar\" + \\"foo\\": \\"bar\\" } \`\`\` " diff --git a/src/__tests__/__snapshots__/md-table.test.js.snap b/src/__tests__/__snapshots__/md-table.test.js.snap index 1324ff6..911dc65 100644 --- a/src/__tests__/__snapshots__/md-table.test.js.snap +++ b/src/__tests__/__snapshots__/md-table.test.js.snap @@ -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 | |---|---|-------------| diff --git a/src/__tests__/__snapshots__/path-generator.test.js.snap b/src/__tests__/__snapshots__/path-generator.test.js.snap index 92f81a2..404aa50 100644 --- a/src/__tests__/__snapshots__/path-generator.test.js.snap +++ b/src/__tests__/__snapshots__/path-generator.test.js.snap @@ -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} @@ -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 @@ -41,7 +43,7 @@ https://example.com/more-info |------|------|-------|----------| | path | id | int64 | true | -#### Response: 204 +#### Response: 204 No Content pet deleted @@ -74,7 +76,7 @@ Creates a new pet - (object) - name (string) -#### Response: 201 +#### Response: 201 Created pet response diff --git a/src/__tests__/__snapshots__/prepare-spec.test.js.snap b/src/__tests__/__snapshots__/prepare-spec.test.js.snap index 9d012b6..c07148b 100644 --- a/src/__tests__/__snapshots__/prepare-spec.test.js.snap +++ b/src/__tests__/__snapshots__/prepare-spec.test.js.snap @@ -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", @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/src/__tests__/__snapshots__/resolve-api-spec.test.js.snap b/src/__tests__/__snapshots__/resolve-api-spec.test.js.snap index c152b9e..1be0369 100644 --- a/src/__tests__/__snapshots__/resolve-api-spec.test.js.snap +++ b/src/__tests__/__snapshots__/resolve-api-spec.test.js.snap @@ -1,3 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + exports[`resolveApiSpec should resolve the spec 1`] = ` Object { "basePath": "/api", @@ -80,7 +82,7 @@ Object { "type": "integer", }, "name": Object { - "description": "The pet\'s name", + "description": "The pet's name", "type": "string", }, "tag": Object { @@ -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 { @@ -155,7 +157,7 @@ Object { "type": "integer", }, "name": Object { - "description": "The pet\'s name", + "description": "The pet's name", "type": "string", }, "tag": Object { @@ -255,7 +257,7 @@ Object { "type": "integer", }, "name": Object { - "description": "The pet\'s name", + "description": "The pet's name", "type": "string", }, "tag": Object { diff --git a/src/__tests__/__snapshots__/schema-generator.test.js.snap b/src/__tests__/__snapshots__/schema-generator.test.js.snap index 967beda..128c140 100644 --- a/src/__tests__/__snapshots__/schema-generator.test.js.snap +++ b/src/__tests__/__snapshots__/schema-generator.test.js.snap @@ -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\`)" diff --git a/src/__tests__/__snapshots__/toc-generator.test.js.snap b/src/__tests__/__snapshots__/toc-generator.test.js.snap index 3b1aaee..2a351d3 100644 --- a/src/__tests__/__snapshots__/toc-generator.test.js.snap +++ b/src/__tests__/__snapshots__/toc-generator.test.js.snap @@ -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) diff --git a/src/generators/path-generator.js b/src/generators/path-generator.js index d131995..d727e92 100644 --- a/src/generators/path-generator.js +++ b/src/generators/path-generator.js @@ -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 => { @@ -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, @@ -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; } diff --git a/test-fixtures/fixtures/api/api.md b/test-fixtures/fixtures/api/api.md index 8a57748..1691d3d 100644 --- a/test-fixtures/fixtures/api/api.md +++ b/test-fixtures/fixtures/api/api.md @@ -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 @@ -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 @@ -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 @@ -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