source: node_modules/swagger-client/es/resolver/strategies/generic/resolve.js@ e48199a

main
Last change on this file since e48199a was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import mapSpec, { plugins } from '../../../specmap/index.js';
2import normalize from './normalize.js';
3import { makeFetchJSON } from '../../utils/index.js';
4import * as optionsUtil from '../../utils/options.js';
5export default async function resolveGenericStrategy(options) {
6 const {
7 spec,
8 mode,
9 allowMetaPatches = true,
10 pathDiscriminator,
11 modelPropertyMacro,
12 parameterMacro,
13 requestInterceptor,
14 responseInterceptor,
15 skipNormalization,
16 useCircularStructures
17 } = options;
18 const retrievalURI = optionsUtil.retrievalURI(options);
19 const httpClient = optionsUtil.httpClient(options);
20 return doResolve(spec);
21 function doResolve(_spec) {
22 if (retrievalURI) {
23 plugins.refs.docCache[retrievalURI] = _spec;
24 }
25
26 // Build a json-fetcher ( ie: give it a URL and get json out )
27 plugins.refs.fetchJSON = makeFetchJSON(httpClient, {
28 requestInterceptor,
29 responseInterceptor
30 });
31 const plugs = [plugins.refs];
32 if (typeof parameterMacro === 'function') {
33 plugs.push(plugins.parameters);
34 }
35 if (typeof modelPropertyMacro === 'function') {
36 plugs.push(plugins.properties);
37 }
38 if (mode !== 'strict') {
39 plugs.push(plugins.allOf);
40 }
41
42 // mapSpec is where the hard work happens
43 return mapSpec({
44 spec: _spec,
45 context: {
46 baseDoc: retrievalURI
47 },
48 plugins: plugs,
49 allowMetaPatches,
50 // allows adding .meta patches, which include adding `$$ref`s to the spec
51 pathDiscriminator,
52 // for lazy resolution
53 parameterMacro,
54 modelPropertyMacro,
55 useCircularStructures
56 // eslint-disable-next-line camelcase
57 }).then(skipNormalization ? async a => a : normalize);
58 }
59}
Note: See TracBrowser for help on using the repository browser.