From 7849f7f6b7517275f2b283085ac8174f83dc055d Mon Sep 17 00:00:00 2001 From: Anya Stasiuk Date: Wed, 7 Aug 2019 10:46:44 +0300 Subject: [PATCH 1/3] fix: revert expanding default server variables --- src/components/Endpoint/Endpoint.tsx | 9 +++---- src/utils/__tests__/openapi.test.ts | 38 +++------------------------- src/utils/openapi.ts | 7 ----- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/components/Endpoint/Endpoint.tsx b/src/components/Endpoint/Endpoint.tsx index 4fd937c0..21bffa52 100644 --- a/src/components/Endpoint/Endpoint.tsx +++ b/src/components/Endpoint/Endpoint.tsx @@ -5,7 +5,7 @@ import { Markdown } from '../Markdown/Markdown'; import { OptionsContext } from '../OptionsProvider'; import { SelectOnClick } from '../SelectOnClick/SelectOnClick'; -import { expandDefaultServerVariables, getBasePath } from '../../utils'; +import { getBasePath } from '../../utils'; import { EndpointInfo, HttpVerb, @@ -61,16 +61,15 @@ export class Endpoint extends React.Component { {operation.servers.map(server => { - const normalizedUrl = expandDefaultServerVariables(server.url, server.variables); return ( - + {hideHostname || options.hideHostname - ? getBasePath(normalizedUrl) - : normalizedUrl} + ? getBasePath(server.url) + : server.url} {operation.path} diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 54a0bac4..5d2d91dd 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -13,7 +13,6 @@ import { import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services'; import { OpenAPIParameter, OpenAPIParameterLocation, OpenAPIParameterStyle } from '../../types'; -import { expandDefaultServerVariables } from '../openapi'; describe('Utils', () => { describe('openapi getStatusCode', () => { @@ -294,39 +293,6 @@ describe('Utils', () => { ]); expect(res).toEqual([{ url: 'https://base.com/sandbox/test', description: 'test' }]); }); - - it('should expand variables', () => { - const servers = normalizeServers('', [ - { - url: 'http://{host}{basePath}', - variables: { - host: { - default: '127.0.0.1', - }, - basePath: { - default: '/path/to/endpoint', - }, - }, - }, - { - url: 'http://127.0.0.2:{port}', - variables: {}, - }, - { - url: 'http://127.0.0.3', - }, - ]); - - expect(expandDefaultServerVariables(servers[0].url, servers[0].variables)).toEqual( - 'http://127.0.0.1/path/to/endpoint', - ); - expect(expandDefaultServerVariables(servers[1].url, servers[1].variables)).toEqual( - 'http://127.0.0.2:{port}', - ); - expect(expandDefaultServerVariables(servers[2].url, servers[2].variables)).toEqual( - 'http://127.0.0.3', - ); - }); }); describe('openapi humanizeConstraints', () => { @@ -550,7 +516,9 @@ describe('Utils', () => { locationTestGroup.cases.forEach(valueTypeTestGroup => { describe(valueTypeTestGroup.description, () => { valueTypeTestGroup.cases.forEach(testCase => { - it(`should serialize correctly when style is ${testCase.style} and explode is ${testCase.explode}`, () => { + it(`should serialize correctly when style is ${testCase.style} and explode is ${ + testCase.explode + }`, () => { const parameter: OpenAPIParameter = { name: locationTestGroup.name, in: locationTestGroup.location, diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index aa346a38..04a16b6b 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -487,13 +487,6 @@ export function mergeSimilarMediaTypes(types: Dict): Dict (variables[name] && variables[name].default) || match, - ); -} - export function normalizeServers( specUrl: string | undefined, servers: OpenAPIServer[], From 58cb20d4b253471515886f3901f864080aa88212 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 7 Aug 2019 12:02:25 +0300 Subject: [PATCH 2/3] fix: fix escaping JSON string values fixes #999 --- src/utils/jsonToHtml.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/jsonToHtml.ts b/src/utils/jsonToHtml.ts index bbdc638e..59edc47c 100644 --- a/src/utils/jsonToHtml.ts +++ b/src/utils/jsonToHtml.ts @@ -20,8 +20,8 @@ function htmlEncode(t) { : ''; } -function escapeForStringLiteral(str: string) { - return str.replace(/([\\"])/g, '\\$1'); +function stringifyStringLiteral(str: string) { + return JSON.stringify(str).slice(1, -1); } function decorateWithSpan(value, className) { @@ -56,11 +56,11 @@ function valueToHTML(value, maxExpandLevel: number) { '' + - htmlEncode(escapeForStringLiteral(value)) + + htmlEncode(stringifyStringLiteral(value)) + '' + decorateWithSpan('"', 'token string'); } else { - output += decorateWithSpan('"' + escapeForStringLiteral(value) + '"', 'token string'); + output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string'); } } else if (valueType === 'boolean') { output += decorateWithSpan(value, 'token boolean'); From 121bf640faf7afae4090e7db435138483536f5c4 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 7 Aug 2019 12:33:55 +0300 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20Release=202.0.0-rc.14=20?= =?UTF-8?q?=F0=9F=94=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42c7f4d0..a3c424a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# [2.0.0-rc.14](https://github.com/Redocly/redoc/compare/v2.0.0-rc.13...v2.0.0-rc.14) (2019-08-07) + + +### Bug Fixes + +* fix escaping JSON string values ([58cb20d](https://github.com/Redocly/redoc/commit/58cb20d)), closes [#999](https://github.com/Redocly/redoc/issues/999) +* revert expanding default server variables ([7849f7f](https://github.com/Redocly/redoc/commit/7849f7f)) + + + # [2.0.0-rc.13](https://github.com/Redocly/redoc/compare/v2.0.0-rc.12...v2.0.0-rc.13) (2019-08-01) diff --git a/package.json b/package.json index f435bfed..5b199dcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redoc", - "version": "2.0.0-rc.13", + "version": "2.0.0-rc.14", "description": "ReDoc", "repository": { "type": "git",