fix: empty servers behaviour per OAS spec

fixes #1151
This commit is contained in:
Roman Hotsiy 2020-01-10 15:54:14 +02:00
parent a260c8414c
commit ed1db0c902
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -14,7 +14,7 @@ import {
Referenced, Referenced,
} from '../types'; } from '../types';
import { IS_BROWSER } from './dom'; import { IS_BROWSER } from './dom';
import { isNumeric, removeQueryString, resolveUrl, stripTrailingSlash } from './helpers'; import { isNumeric, removeQueryString, resolveUrl } from './helpers';
function isWildcardStatusCode(statusCode: string | number): statusCode is string { function isWildcardStatusCode(statusCode: string | number): statusCode is string {
return typeof statusCode === 'string' && /\dxx/i.test(statusCode); return typeof statusCode === 'string' && /\dxx/i.test(statusCode);
@ -530,9 +530,10 @@ export function normalizeServers(
const baseUrl = specUrl === undefined ? removeQueryString(getHref()) : dirname(specUrl); const baseUrl = specUrl === undefined ? removeQueryString(getHref()) : dirname(specUrl);
if (servers.length === 0) { if (servers.length === 0) {
return [ // Behaviour defined in OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#openapi-object
servers = [
{ {
url: stripTrailingSlash(baseUrl), url: '/',
}, },
]; ];
} }