mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 22:54:51 +03:00
Merge branch 'master' of https://github.com/raha1923/redoc
This commit is contained in:
commit
1b3e0ced7b
10
CHANGELOG.md
10
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)
|
# [2.0.0-rc.13](https://github.com/Redocly/redoc/compare/v2.0.0-rc.12...v2.0.0-rc.13) (2019-08-01)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "redoc",
|
"name": "redoc",
|
||||||
"version": "2.0.0-rc.13",
|
"version": "2.0.0-rc.14",
|
||||||
"description": "ReDoc",
|
"description": "ReDoc",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Markdown } from '../Markdown/Markdown';
|
||||||
import { OptionsContext } from '../OptionsProvider';
|
import { OptionsContext } from '../OptionsProvider';
|
||||||
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
||||||
|
|
||||||
import { expandDefaultServerVariables, getBasePath } from '../../utils';
|
import { getBasePath } from '../../utils';
|
||||||
import {
|
import {
|
||||||
EndpointInfo,
|
EndpointInfo,
|
||||||
HttpVerb,
|
HttpVerb,
|
||||||
|
@ -61,16 +61,15 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
|
||||||
</EndpointInfo>
|
</EndpointInfo>
|
||||||
<ServersOverlay expanded={expanded}>
|
<ServersOverlay expanded={expanded}>
|
||||||
{operation.servers.map(server => {
|
{operation.servers.map(server => {
|
||||||
const normalizedUrl = expandDefaultServerVariables(server.url, server.variables);
|
|
||||||
return (
|
return (
|
||||||
<ServerItem key={normalizedUrl}>
|
<ServerItem key={server.url}>
|
||||||
<Markdown source={server.description || ''} compact={true} />
|
<Markdown source={server.description || ''} compact={true} />
|
||||||
<SelectOnClick>
|
<SelectOnClick>
|
||||||
<ServerUrl>
|
<ServerUrl>
|
||||||
<span>
|
<span>
|
||||||
{hideHostname || options.hideHostname
|
{hideHostname || options.hideHostname
|
||||||
? getBasePath(normalizedUrl)
|
? getBasePath(server.url)
|
||||||
: normalizedUrl}
|
: server.url}
|
||||||
</span>
|
</span>
|
||||||
{operation.path}
|
{operation.path}
|
||||||
</ServerUrl>
|
</ServerUrl>
|
||||||
|
|
|
@ -13,7 +13,6 @@ import {
|
||||||
|
|
||||||
import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
|
import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
|
||||||
import { OpenAPIParameter, OpenAPIParameterLocation, OpenAPIParameterStyle } from '../../types';
|
import { OpenAPIParameter, OpenAPIParameterLocation, OpenAPIParameterStyle } from '../../types';
|
||||||
import { expandDefaultServerVariables } from '../openapi';
|
|
||||||
|
|
||||||
describe('Utils', () => {
|
describe('Utils', () => {
|
||||||
describe('openapi getStatusCode', () => {
|
describe('openapi getStatusCode', () => {
|
||||||
|
@ -294,39 +293,6 @@ describe('Utils', () => {
|
||||||
]);
|
]);
|
||||||
expect(res).toEqual([{ url: 'https://base.com/sandbox/test', description: 'test' }]);
|
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', () => {
|
describe('openapi humanizeConstraints', () => {
|
||||||
|
@ -550,7 +516,9 @@ describe('Utils', () => {
|
||||||
locationTestGroup.cases.forEach(valueTypeTestGroup => {
|
locationTestGroup.cases.forEach(valueTypeTestGroup => {
|
||||||
describe(valueTypeTestGroup.description, () => {
|
describe(valueTypeTestGroup.description, () => {
|
||||||
valueTypeTestGroup.cases.forEach(testCase => {
|
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 = {
|
const parameter: OpenAPIParameter = {
|
||||||
name: locationTestGroup.name,
|
name: locationTestGroup.name,
|
||||||
in: locationTestGroup.location,
|
in: locationTestGroup.location,
|
||||||
|
|
|
@ -20,8 +20,8 @@ function htmlEncode(t) {
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeForStringLiteral(str: string) {
|
function stringifyStringLiteral(str: string) {
|
||||||
return str.replace(/([\\"])/g, '\\$1');
|
return JSON.stringify(str).slice(1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function decorateWithSpan(value, className) {
|
function decorateWithSpan(value, className) {
|
||||||
|
@ -56,11 +56,11 @@ function valueToHTML(value, maxExpandLevel: number) {
|
||||||
'<a href="' +
|
'<a href="' +
|
||||||
value +
|
value +
|
||||||
'">' +
|
'">' +
|
||||||
htmlEncode(escapeForStringLiteral(value)) +
|
htmlEncode(stringifyStringLiteral(value)) +
|
||||||
'</a>' +
|
'</a>' +
|
||||||
decorateWithSpan('"', 'token string');
|
decorateWithSpan('"', 'token string');
|
||||||
} else {
|
} else {
|
||||||
output += decorateWithSpan('"' + escapeForStringLiteral(value) + '"', 'token string');
|
output += decorateWithSpan('"' + stringifyStringLiteral(value) + '"', 'token string');
|
||||||
}
|
}
|
||||||
} else if (valueType === 'boolean') {
|
} else if (valueType === 'boolean') {
|
||||||
output += decorateWithSpan(value, 'token boolean');
|
output += decorateWithSpan(value, 'token boolean');
|
||||||
|
|
|
@ -487,13 +487,6 @@ export function mergeSimilarMediaTypes(types: Dict<OpenAPIMediaType>): Dict<Open
|
||||||
return mergedTypes;
|
return mergedTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function expandDefaultServerVariables(url: string, variables: object = {}) {
|
|
||||||
return url.replace(
|
|
||||||
/(?:{)(\w+)(?:})/g,
|
|
||||||
(match, name) => (variables[name] && variables[name].default) || match,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeServers(
|
export function normalizeServers(
|
||||||
specUrl: string | undefined,
|
specUrl: string | undefined,
|
||||||
servers: OpenAPIServer[],
|
servers: OpenAPIServer[],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user