Skip to content

Commit

Permalink
fix: revert expanding default server variables
Browse files Browse the repository at this point in the history
  • Loading branch information
stasiukanya authored and RomanHotsiy committed Aug 7, 2019
1 parent 3e18093 commit 7849f7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 47 deletions.
9 changes: 4 additions & 5 deletions src/components/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,16 +61,15 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
</EndpointInfo>
<ServersOverlay expanded={expanded}>
{operation.servers.map(server => {
const normalizedUrl = expandDefaultServerVariables(server.url, server.variables);
return (
<ServerItem key={normalizedUrl}>
<ServerItem key={server.url}>
<Markdown source={server.description || ''} compact={true} />
<SelectOnClick>
<ServerUrl>
<span>
{hideHostname || options.hideHostname
? getBasePath(normalizedUrl)
: normalizedUrl}
? getBasePath(server.url)
: server.url}
</span>
{operation.path}
</ServerUrl>
Expand Down
38 changes: 3 additions & 35 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/utils/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,6 @@ export function mergeSimilarMediaTypes(types: Dict<OpenAPIMediaType>): Dict<Open
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(
specUrl: string | undefined,
servers: OpenAPIServer[],
Expand Down

1 comment on commit 7849f7f

@antherkiv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change has been needed? I don't understand, expand default values was ok

Please sign in to comment.