From 4385347e9906dffebe64b62e835098c80437b63b Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Wed, 15 Apr 2020 15:35:47 -0700 Subject: [PATCH] fix: issues preventing people from upgrading off our legacy explorer (#602) * chore: updating deps in the lockfile * fix: always attempt to uppercase language names * fix: stop double-nesting json response examples * fix: bug where legacy responses that weren't set up are ignored * chore(deps): upgrading @readme/api-explorer to 3.1.9 * fix: always try to render an operations path * docs: Update packages/api-explorer/src/lib/upgrade-legacy-responses.js Co-Authored-By: Rafe Goldberg Co-authored-by: Rafe Goldberg --- .../lib/upgrade-legacy-responses.test.js | 4 ++ packages/api-explorer/package-lock.json | 52 +++++++++---------- packages/api-explorer/src/PathUrl.jsx | 19 +++---- packages/api-explorer/src/ResponseExample.jsx | 2 +- .../src/lib/generate-code-snippet.js | 2 +- .../src/lib/upgrade-legacy-responses.js | 5 ++ packages/markdown-magic/package-lock.json | 30 ----------- packages/oas-to-har/package-lock.json | 6 +-- packages/oas-to-har/package.json | 2 +- 9 files changed, 49 insertions(+), 73 deletions(-) diff --git a/packages/api-explorer/__tests__/lib/upgrade-legacy-responses.test.js b/packages/api-explorer/__tests__/lib/upgrade-legacy-responses.test.js index d1f349d9b..13054afd6 100644 --- a/packages/api-explorer/__tests__/lib/upgrade-legacy-responses.test.js +++ b/packages/api-explorer/__tests__/lib/upgrade-legacy-responses.test.js @@ -5,6 +5,10 @@ function encodeJsonExample(json) { } describe('upgradeLegacyResponses', () => { + it('should not return anything for an legacy response that hasnt been fully configured', () => { + expect(upgradeLegacyResponses([{ language: 'text', code: '' }])).toStrictEqual([]); + }); + it('should return codes array for a legacy response shape', () => { const encodedExample = { meta: { diff --git a/packages/api-explorer/package-lock.json b/packages/api-explorer/package-lock.json index 0dfc04f58..815b21943 100644 --- a/packages/api-explorer/package-lock.json +++ b/packages/api-explorer/package-lock.json @@ -1349,18 +1349,18 @@ } }, "@readme/http-status-codes": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/@readme/http-status-codes/-/http-status-codes-6.2.0.tgz", - "integrity": "sha512-yNkRO1ijrSFBRq/13zfJsVeRd1z7dtiRM/fbmXa2PgVIzoM3eAHarWL1uvwnA6EWuqjTQvKiyeVabPJExrk8Iw==" + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/@readme/http-status-codes/-/http-status-codes-6.3.5.tgz", + "integrity": "sha512-sCNi/OEJHvWgXbVM4rR6AkQCVrdphGjK/WqkRD3Es2Gj7DkqCH+IgGE0ukTcJHKogzQ40vV401slXU3gIlHJtA==" }, "@readme/markdown": { - "version": "6.3.4", - "resolved": "https://registry.npmjs.org/@readme/markdown/-/markdown-6.3.4.tgz", - "integrity": "sha512-HrIYsld+sgMHxVP1s2wiWH3tmoo0DoL4xwyORK9pdlp25TXkuRAzBxXyUw9Xf9ZgHkVYhyXtaezLggy5ImazOA==", + "version": "6.3.7", + "resolved": "https://registry.npmjs.org/@readme/markdown/-/markdown-6.3.7.tgz", + "integrity": "sha512-6DNKJ+CSd0DXKqTnvOlL4DTCZcs5U41skU4BHO/wB3vsUeLviAvMqrv4tc0zPLrpWEYtaz8tnIezCki09w9PNg==", "requires": { "@readme/emojis": "^1.0.0", - "@readme/syntax-highlighter": "^6.3.4", - "@readme/variable": "^6.2.0", + "@readme/syntax-highlighter": "^6.3.5", + "@readme/variable": "^6.3.5", "hast-util-sanitize": "^1.2.0", "prop-types": "^15.7.2", "react": "^16.4.2", @@ -1379,13 +1379,13 @@ } }, "@readme/markdown-magic": { - "version": "6.3.4", - "resolved": "https://registry.npmjs.org/@readme/markdown-magic/-/markdown-magic-6.3.4.tgz", - "integrity": "sha512-uhyTB/zE9Km2zNqpr6vuD3dl5TBYKyt+CUOSbAzO+05FuPKlfPv9HSsKHf+KQjJnIsD5UzBe/Ew31etW/ZSkNQ==", + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/@readme/markdown-magic/-/markdown-magic-6.3.5.tgz", + "integrity": "sha512-MWbtJLZ53RjYaCH5B15gCYL3xC+8wCkMafKFQONHqjrNZFOIagFrvsJCGVnkR7EUpN8vH62e3/qwnLJMvOOMVA==", "requires": { "@readme/emojis": "^1.0.0", - "@readme/syntax-highlighter": "^6.3.4", - "@readme/variable": "^6.2.0", + "@readme/syntax-highlighter": "^6.3.5", + "@readme/variable": "^6.3.5", "hast-util-sanitize": "^1.2.0", "prop-types": "^15.7.2", "react": "^16.4.2", @@ -1456,9 +1456,9 @@ "integrity": "sha512-x3gLEKhzUnrJjCM6hls2V/QT7u1knrIYhtnXZJ9Ln9NBYU3TKHdW7Cd8vZcoVH0e/w3O/BoCgyHOyb559oVaHQ==" }, "@readme/oas-to-har": { - "version": "6.3.3", - "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-6.3.3.tgz", - "integrity": "sha512-JCA6sxeMFgBHfJewHCA2WC/rfAwekDeUTir6qLhemSgS+Eazqb2evNarvkZyGJWaNvjO4NsCypDuVK1S8xBiIw==", + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-6.3.5.tgz", + "integrity": "sha512-13UDgpeUUajdrVbwJJMCpVXSinT+L1NOYlYV9rXC6CyBv1cOZkCjVtn3mWh2GsYK0eRRMZJqNtgqcfYn3Wjl3Q==", "requires": { "@readme/oas-extensions": "^6.0.5", "@readme/oas-tooling": "^3.1.8", @@ -1466,9 +1466,9 @@ } }, "@readme/oas-tooling": { - "version": "3.1.8", - "resolved": "https://registry.npmjs.org/@readme/oas-tooling/-/oas-tooling-3.1.8.tgz", - "integrity": "sha512-kWrpRdUD5mjwC333IhHqSIwcWtARe+FPtL0dv667g2K3nvWgqZpJZaHoN2zyNDvK/9JhsnzegEB6bRes87aFTw==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/@readme/oas-tooling/-/oas-tooling-3.1.9.tgz", + "integrity": "sha512-LaxTKjrH6Y1yjt4Gg9rAQpPiC8Doj95qCZ+ssGk5Gv69nUuRFVClkq9+GLrgSyXj+OTUuMne/yvklOitY21kkQ==", "requires": { "jsonpointer": "^4.0.1", "path-to-regexp": "^6.1.0" @@ -1504,19 +1504,19 @@ } }, "@readme/syntax-highlighter": { - "version": "6.3.4", - "resolved": "https://registry.npmjs.org/@readme/syntax-highlighter/-/syntax-highlighter-6.3.4.tgz", - "integrity": "sha512-9itpTPJl+IlM9b6MjFG1H580ekDaLDEwI5dLE9vKVKDRggsOITIEAc8RoHDvRoXOODtwAv0524MfTdmrPsRI3w==", + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/@readme/syntax-highlighter/-/syntax-highlighter-6.3.5.tgz", + "integrity": "sha512-gWinH5XPDlWynCfCiHFxnDCGFerzuUuAOJxtLZLFzrO4cWvi9RmEPRu4awuxk4k51hM5kI6ErNw7geB++iOQsQ==", "requires": { - "@readme/variable": "^6.2.0", + "@readme/variable": "^6.3.5", "codemirror": "^5.48.2", "react": "^16.4.2" } }, "@readme/variable": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/@readme/variable/-/variable-6.2.0.tgz", - "integrity": "sha512-T709f68x+04Re+ubMHkQc+K3DoKazeLSswWUNIwSOp/v2ONXU8v8mccMGU5bqhRx+KeLz6xRgpfLxDHK9ZUR4g==", + "version": "6.3.5", + "resolved": "https://registry.npmjs.org/@readme/variable/-/variable-6.3.5.tgz", + "integrity": "sha512-2sWQ739GRbRg5a9nCYluhXNivZY0evCR8NilKl8wou5WHhrUgFoMCrO4YuzoqwBCxnbUlEMIM8NvoP6K+3qGug==", "requires": { "classnames": "^2.2.6", "prop-types": "^15.7.2", diff --git a/packages/api-explorer/src/PathUrl.jsx b/packages/api-explorer/src/PathUrl.jsx index b5dfb8f77..409882f59 100644 --- a/packages/api-explorer/src/PathUrl.jsx +++ b/packages/api-explorer/src/PathUrl.jsx @@ -81,17 +81,14 @@ function PathUrl({ )} {operation.method} - - {oas.servers && oas.servers.length > 0 && ( - - {oas.url()} - {splitPath(operation.path).map(part => ( - - {part.value} - - ))} - - )} + + {oas.url()} + {splitPath(operation.path).map(part => ( + + {part.value} + + ))} + diff --git a/packages/api-explorer/src/ResponseExample.jsx b/packages/api-explorer/src/ResponseExample.jsx index 14fba1b0e..155a88d68 100644 --- a/packages/api-explorer/src/ResponseExample.jsx +++ b/packages/api-explorer/src/ResponseExample.jsx @@ -246,7 +246,7 @@ class ResponseExample extends React.Component { )} {isJson && !example.multipleExamples ? ( -
{transformExampleIntoReactJson(example)}
+ transformExampleIntoReactJson(example) ) : ( // json + multiple examples is already handled in `showExamples`. diff --git a/packages/api-explorer/src/lib/generate-code-snippet.js b/packages/api-explorer/src/lib/generate-code-snippet.js index eeb7b5434..35c1b91a0 100644 --- a/packages/api-explorer/src/lib/generate-code-snippet.js +++ b/packages/api-explorer/src/lib/generate-code-snippet.js @@ -88,4 +88,4 @@ module.exports = (oas, operation, values, auth, lang) => { }; }; -module.exports.getLangName = lang => (supportedLanguages[lang] ? uppercase(lang) : lang); +module.exports.getLangName = lang => uppercase(lang); diff --git a/packages/api-explorer/src/lib/upgrade-legacy-responses.js b/packages/api-explorer/src/lib/upgrade-legacy-responses.js index c94fcba7b..aef5c64dd 100644 --- a/packages/api-explorer/src/lib/upgrade-legacy-responses.js +++ b/packages/api-explorer/src/lib/upgrade-legacy-responses.js @@ -13,6 +13,11 @@ module.exports = responses => { const codes = {}; responses.forEach(response => { + // If there's no status set, then the legacy response wasn't fully configured so we should ignore it. + if (!('status' in response)) { + return; + } + if (typeof codes[response.status] === 'undefined') { codes[response.status] = { languages: {}, diff --git a/packages/markdown-magic/package-lock.json b/packages/markdown-magic/package-lock.json index 021639ee3..90386627b 100644 --- a/packages/markdown-magic/package-lock.json +++ b/packages/markdown-magic/package-lock.json @@ -1033,26 +1033,6 @@ "eslint-plugin-unicorn": "^17.0.1" } }, - "@readme/syntax-highlighter": { - "version": "6.3.4", - "resolved": "https://registry.npmjs.org/@readme/syntax-highlighter/-/syntax-highlighter-6.3.4.tgz", - "integrity": "sha512-9itpTPJl+IlM9b6MjFG1H580ekDaLDEwI5dLE9vKVKDRggsOITIEAc8RoHDvRoXOODtwAv0524MfTdmrPsRI3w==", - "requires": { - "@readme/variable": "^6.2.0", - "codemirror": "^5.48.2", - "react": "^16.4.2" - } - }, - "@readme/variable": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/@readme/variable/-/variable-6.2.0.tgz", - "integrity": "sha512-T709f68x+04Re+ubMHkQc+K3DoKazeLSswWUNIwSOp/v2ONXU8v8mccMGU5bqhRx+KeLz6xRgpfLxDHK9ZUR4g==", - "requires": { - "classnames": "^2.2.6", - "prop-types": "^15.7.2", - "react": "^16.4.2" - } - }, "@sinonjs/commons": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.2.tgz", @@ -1862,11 +1842,6 @@ } } }, - "classnames": { - "version": "2.2.6", - "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz", - "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==" - }, "clean-regexp": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz", @@ -1908,11 +1883,6 @@ "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "dev": true }, - "codemirror": { - "version": "5.52.2", - "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.52.2.tgz", - "integrity": "sha512-WCGCixNUck2HGvY8/ZNI1jYfxPG5cRHv0VjmWuNzbtCLz8qYA5d+je4QhSSCtCaagyeOwMi/HmmPTjBgiTm2lQ==" - }, "collapse-white-space": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-1.0.4.tgz", diff --git a/packages/oas-to-har/package-lock.json b/packages/oas-to-har/package-lock.json index 5a43dbf66..d694bb1d7 100644 --- a/packages/oas-to-har/package-lock.json +++ b/packages/oas-to-har/package-lock.json @@ -1018,9 +1018,9 @@ "integrity": "sha512-x3gLEKhzUnrJjCM6hls2V/QT7u1knrIYhtnXZJ9Ln9NBYU3TKHdW7Cd8vZcoVH0e/w3O/BoCgyHOyb559oVaHQ==" }, "@readme/oas-tooling": { - "version": "3.1.8", - "resolved": "https://registry.npmjs.org/@readme/oas-tooling/-/oas-tooling-3.1.8.tgz", - "integrity": "sha512-kWrpRdUD5mjwC333IhHqSIwcWtARe+FPtL0dv667g2K3nvWgqZpJZaHoN2zyNDvK/9JhsnzegEB6bRes87aFTw==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/@readme/oas-tooling/-/oas-tooling-3.1.9.tgz", + "integrity": "sha512-LaxTKjrH6Y1yjt4Gg9rAQpPiC8Doj95qCZ+ssGk5Gv69nUuRFVClkq9+GLrgSyXj+OTUuMne/yvklOitY21kkQ==", "requires": { "jsonpointer": "^4.0.1", "path-to-regexp": "^6.1.0" diff --git a/packages/oas-to-har/package.json b/packages/oas-to-har/package.json index 4f4aa4216..be8da872f 100644 --- a/packages/oas-to-har/package.json +++ b/packages/oas-to-har/package.json @@ -5,7 +5,7 @@ "main": "src/index.js", "dependencies": { "@readme/oas-extensions": "^6.0.5", - "@readme/oas-tooling": "^3.1.8", + "@readme/oas-tooling": "^3.1.9", "querystring": "^0.2.0" }, "scripts": {