1 | "use strict";
|
---|
2 |
|
---|
3 | var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
---|
4 | var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
---|
5 | exports.__esModule = true;
|
---|
6 | exports.default = resolveGenericStrategy;
|
---|
7 | var _index = _interopRequireWildcard(require("../../../specmap/index.js"));
|
---|
8 | var _normalize = _interopRequireDefault(require("./normalize.js"));
|
---|
9 | var _index2 = require("../../utils/index.js");
|
---|
10 | var optionsUtil = _interopRequireWildcard(require("../../utils/options.js"));
|
---|
11 | async function resolveGenericStrategy(options) {
|
---|
12 | const {
|
---|
13 | spec,
|
---|
14 | mode,
|
---|
15 | allowMetaPatches = true,
|
---|
16 | pathDiscriminator,
|
---|
17 | modelPropertyMacro,
|
---|
18 | parameterMacro,
|
---|
19 | requestInterceptor,
|
---|
20 | responseInterceptor,
|
---|
21 | skipNormalization,
|
---|
22 | useCircularStructures
|
---|
23 | } = options;
|
---|
24 | const retrievalURI = optionsUtil.retrievalURI(options);
|
---|
25 | const httpClient = optionsUtil.httpClient(options);
|
---|
26 | return doResolve(spec);
|
---|
27 | function doResolve(_spec) {
|
---|
28 | if (retrievalURI) {
|
---|
29 | _index.plugins.refs.docCache[retrievalURI] = _spec;
|
---|
30 | }
|
---|
31 |
|
---|
32 | // Build a json-fetcher ( ie: give it a URL and get json out )
|
---|
33 | _index.plugins.refs.fetchJSON = (0, _index2.makeFetchJSON)(httpClient, {
|
---|
34 | requestInterceptor,
|
---|
35 | responseInterceptor
|
---|
36 | });
|
---|
37 | const plugs = [_index.plugins.refs];
|
---|
38 | if (typeof parameterMacro === 'function') {
|
---|
39 | plugs.push(_index.plugins.parameters);
|
---|
40 | }
|
---|
41 | if (typeof modelPropertyMacro === 'function') {
|
---|
42 | plugs.push(_index.plugins.properties);
|
---|
43 | }
|
---|
44 | if (mode !== 'strict') {
|
---|
45 | plugs.push(_index.plugins.allOf);
|
---|
46 | }
|
---|
47 |
|
---|
48 | // mapSpec is where the hard work happens
|
---|
49 | return (0, _index.default)({
|
---|
50 | spec: _spec,
|
---|
51 | context: {
|
---|
52 | baseDoc: retrievalURI
|
---|
53 | },
|
---|
54 | plugins: plugs,
|
---|
55 | allowMetaPatches,
|
---|
56 | // allows adding .meta patches, which include adding `$$ref`s to the spec
|
---|
57 | pathDiscriminator,
|
---|
58 | // for lazy resolution
|
---|
59 | parameterMacro,
|
---|
60 | modelPropertyMacro,
|
---|
61 | useCircularStructures
|
---|
62 | // eslint-disable-next-line camelcase
|
---|
63 | }).then(skipNormalization ? async a => a : _normalize.default);
|
---|
64 | }
|
---|
65 | } |
---|