-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(resolver): refactor code to allow using strategy pattern
Refs #2744
- Loading branch information
Showing
7 changed files
with
67 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// eslint-disable-next-line camelcase | ||
import resolveOpenAPI2_30Strategy from './strategies/openapi-2--3-0.js'; | ||
import { makeFetchJSON } from './utils/index.js'; | ||
import * as optionsUtil from './utils/options.js'; | ||
|
||
const resolve = async (options) => { | ||
const { spec, requestInterceptor, responseInterceptor } = options; | ||
|
||
const retrievalURI = optionsUtil.retrievalURI(options); | ||
const httpClient = optionsUtil.httpClient(options); | ||
const retrievedSpec = | ||
spec || | ||
(await makeFetchJSON(httpClient, { requestInterceptor, responseInterceptor })(retrievalURI)); | ||
|
||
return resolveOpenAPI2_30Strategy({ ...options, spec: retrievedSpec }); | ||
}; | ||
|
||
export default resolve; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from '../../constants.js'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function makeFetchJSON(http, opts = {}) { | ||
const { requestInterceptor, responseInterceptor } = opts; | ||
// Set credentials with 'http.withCredentials' value | ||
const credentials = http.withCredentials ? 'include' : 'same-origin'; | ||
return (docPath) => | ||
http({ | ||
url: docPath, | ||
loadSpec: true, | ||
requestInterceptor, | ||
responseInterceptor, | ||
headers: { | ||
Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS, | ||
}, | ||
credentials, | ||
}).then((res) => res.body); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Http from '../../http/index.js'; | ||
|
||
export const retrievalURI = (options) => { | ||
const { baseDoc, url } = options; | ||
|
||
// @TODO Swagger-UI uses baseDoc instead of url, this is to allow both | ||
// need to fix and pick one. | ||
return baseDoc || url; | ||
}; | ||
|
||
export const httpClient = (options) => { | ||
const { fetch, http } = options; | ||
|
||
// @TODO fetch should be removed, and http used instead | ||
// provide a default fetch implementation | ||
return fetch || http || Http; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters