Skip to content

Commit

Permalink
fix: create spec compliant default OpenAPI.servers fields if omitted (#…
Browse files Browse the repository at this point in the history
…3220)

This change is specific to OpenAPI 3.x.y definitions.

Refs #3143
  • Loading branch information
char0n authored Nov 2, 2023
1 parent fff622f commit becdf3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/execute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function oas3BaseUrl({ spec, pathName, method, server, contextUrl, serverVariabl
[selectedServerObj] = servers;
}

if (selectedServerUrl.indexOf('{') > -1) {
if (selectedServerUrl.includes('{')) {
// do variable substitution
const varNames = getVariableTemplateNames(selectedServerUrl);
varNames.forEach((vari) => {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ Swagger.prototype.applyDefaults = function applyDefaults() {
if (!spec.basePath) {
spec.basePath = '/';
}
} else if (isOpenAPI3(spec) && isHttpUrl(specUrl)) {
if (!spec.servers) {
spec.servers = [{ url: specUrl }];
} else if (isOpenAPI3(spec)) {
if (!spec.servers || (Array.isArray(spec.servers) && spec.servers.length === 0)) {
spec.servers = [{ url: '/' }];
}
}
};
Expand Down

0 comments on commit becdf3c

Please sign in to comment.