From a3bfb06cf992e9bb4b8d7687592f39d93492e5ac Mon Sep 17 00:00:00 2001 From: David Brockman Smoliansky Date: Mon, 18 Sep 2017 14:13:26 +0200 Subject: [PATCH 1/4] chore: ignore package-lock.json --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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 From f13eee6f64c88c99133659334fbd8c122254e09d Mon Sep 17 00:00:00 2001 From: David Brockman Smoliansky Date: Mon, 18 Sep 2017 14:14:27 +0200 Subject: [PATCH 2/4] chore: test on node 8 on travis --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 From cbad2b03560b125d2bb1b4d56776abe89ccc05c5 Mon Sep 17 00:00:00 2001 From: David Brockman Smoliansky Date: Mon, 18 Sep 2017 14:20:46 +0200 Subject: [PATCH 3/4] feat: print the status code name for each response BREAKING CHANGE: This changes the returned markdown. --- .../convert-to-markdown.test.js.snap | 8 +++---- .../__snapshots__/path-generator.test.js.snap | 6 +++--- src/generators/path-generator.js | 21 +++++++++++-------- test-fixtures/fixtures/api/api.md | 8 +++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap b/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap index 4dfc5fe..ac707a6 100644 --- a/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap +++ b/src/__tests__/__snapshots__/convert-to-markdown.test.js.snap @@ -23,7 +23,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 @@ -69,7 +69,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 @@ -108,7 +108,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 @@ -149,7 +149,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 diff --git a/src/__tests__/__snapshots__/path-generator.test.js.snap b/src/__tests__/__snapshots__/path-generator.test.js.snap index 92f81a2..fabb256 100644 --- a/src/__tests__/__snapshots__/path-generator.test.js.snap +++ b/src/__tests__/__snapshots__/path-generator.test.js.snap @@ -9,7 +9,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 +41,7 @@ https://example.com/more-info |------|------|-------|----------| | path | id | int64 | true | -#### Response: 204 +#### Response: 204 No Content pet deleted @@ -74,7 +74,7 @@ Creates a new pet - (object) - name (string) -#### Response: 201 +#### Response: 201 Created pet response 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 From 3ca8ad294fb19ac7537d6b284f7bf938c61d7238 Mon Sep 17 00:00:00 2001 From: David Brockman Smoliansky Date: Mon, 18 Sep 2017 14:23:10 +0200 Subject: [PATCH 4/4] chore: update devDependencies --- package.json | 8 ++++---- .../convert-to-markdown.test.js.snap | 18 ++++++++++-------- .../__snapshots__/md-table.test.js.snap | 2 ++ .../__snapshots__/path-generator.test.js.snap | 2 ++ .../__snapshots__/prepare-spec.test.js.snap | 14 ++++++++------ .../resolve-api-spec.test.js.snap | 10 ++++++---- .../schema-generator.test.js.snap | 2 ++ .../__snapshots__/toc-generator.test.js.snap | 2 ++ 8 files changed, 36 insertions(+), 22 deletions(-) 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 ac707a6..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 @@ -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,7 +68,7 @@ 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 OK @@ -76,7 +78,7 @@ 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\\" } \`\`\` @@ -115,7 +117,7 @@ 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\\" } \`\`\` @@ -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 fabb256..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} 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)