Skip to content

Commit

Permalink
refactor(resolver): use constant HTTPS baseURI in non-browser env
Browse files Browse the repository at this point in the history
This change is specific to OpenAPI 3.1.0 resolution
strategy.

Refs #2754
  • Loading branch information
char0n committed Jan 11, 2023
1 parent 35aa9f9 commit 09a6919
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
31 changes: 15 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/resolver/strategies/openapi-3-1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable camelcase */
import { toValue } from '@swagger-api/apidom-core';
import { OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';
import { dereferenceApiDOM } from '@swagger-api/apidom-reference/configuration/empty';
import { dereferenceApiDOM, url } from '@swagger-api/apidom-reference/configuration/empty';
import BinaryParser from '@swagger-api/apidom-reference/parse/parsers/binary';
import OpenApi3_1ResolveStrategy from '@swagger-api/apidom-reference/resolve/strategies/openapi-3-1';

Expand All @@ -25,11 +25,17 @@ const resolveOpenAPI31Strategy = async (options) => {
useCircularStructures = false,
skipNormalization = false,
} = options;
const defaultRetrievalURL = 'https://smartbear.com/';
const baseURI = optionsUtil.retrievalURI(options) ?? url.cwd();
const openApiElement = OpenApi3_1Element.refract(spec);
const dereferenced = await dereferenceApiDOM(openApiElement, {
resolve: {
baseURI: optionsUtil.retrievalURI(options) || defaultRetrievalURL,
/**
* swagger-client only supports resolving HTTP(S) URLs or spec objects.
* If runtime env is detected as non-browser one,
* and baseURI was not provided as part of resolver options,
* then below baseURI check will make sure that constant HTTPS URL is used as baseURI.
*/
baseURI: url.isHttpUrl(baseURI) ? baseURI : 'https://smartbear.com/',
resolvers: [
HttpResolverSwaggerClient({
timeout: timeout || 10000,
Expand Down

0 comments on commit 09a6919

Please sign in to comment.