1 | import _objectSpread from "@babel/runtime-corejs2/helpers/objectSpread2";
|
2 | import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
|
3 | import pick from 'lodash/pick';
|
4 | import { eachOperation, opId } from './helpers';
|
5 |
|
6 | var nullFn = function nullFn() {
|
7 | return null;
|
8 | };
|
9 |
|
10 | var normalizeArray = function normalizeArray(arg) {
|
11 | return _Array$isArray(arg) ? arg : [arg];
|
12 | };
|
13 |
|
14 |
|
15 | export var self = {
|
16 | mapTagOperations: mapTagOperations,
|
17 | makeExecute: makeExecute
|
18 | };
|
19 |
|
20 | export function makeExecute() {
|
21 | var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
22 | return function (_ref) {
|
23 | var pathName = _ref.pathName,
|
24 | method = _ref.method,
|
25 | operationId = _ref.operationId;
|
26 | return function (parameters) {
|
27 | var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
28 | return swaggerJs.execute(_objectSpread(_objectSpread({
|
29 | spec: swaggerJs.spec
|
30 | }, pick(swaggerJs, 'requestInterceptor', 'responseInterceptor', 'userFetch')), {}, {
|
31 | pathName: pathName,
|
32 | method: method,
|
33 | parameters: parameters,
|
34 | operationId: operationId
|
35 | }, opts));
|
36 | };
|
37 | };
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export function makeApisTagOperationsOperationExecute() {
|
44 | var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
45 |
|
46 | var cb = self.makeExecute(swaggerJs);
|
47 | var tagOperations = self.mapTagOperations({
|
48 | v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
|
49 | spec: swaggerJs.spec,
|
50 | cb: cb
|
51 | });
|
52 | var apis = {};
|
53 |
|
54 | for (var tag in tagOperations) {
|
55 | apis[tag] = {
|
56 | operations: {}
|
57 | };
|
58 |
|
59 | for (var op in tagOperations[tag]) {
|
60 | apis[tag].operations[op] = {
|
61 | execute: tagOperations[tag][op]
|
62 | };
|
63 | }
|
64 | }
|
65 |
|
66 | return {
|
67 | apis: apis
|
68 | };
|
69 | }
|
70 |
|
71 | export function makeApisTagOperation() {
|
72 | var swaggerJs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
73 | var cb = self.makeExecute(swaggerJs);
|
74 | return {
|
75 | apis: self.mapTagOperations({
|
76 | v2OperationIdCompatibilityMode: swaggerJs.v2OperationIdCompatibilityMode,
|
77 | spec: swaggerJs.spec,
|
78 | cb: cb
|
79 | })
|
80 | };
|
81 | }
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | export function mapTagOperations(_ref2) {
|
93 | var spec = _ref2.spec,
|
94 | _ref2$cb = _ref2.cb,
|
95 | cb = _ref2$cb === void 0 ? nullFn : _ref2$cb,
|
96 | _ref2$defaultTag = _ref2.defaultTag,
|
97 | defaultTag = _ref2$defaultTag === void 0 ? 'default' : _ref2$defaultTag,
|
98 | v2OperationIdCompatibilityMode = _ref2.v2OperationIdCompatibilityMode;
|
99 | var operationIdCounter = {};
|
100 | var tagOperations = {};
|
101 |
|
102 | eachOperation(spec, function (_ref3) {
|
103 | var pathName = _ref3.pathName,
|
104 | method = _ref3.method,
|
105 | operation = _ref3.operation;
|
106 | var tags = operation.tags ? normalizeArray(operation.tags) : [defaultTag];
|
107 | tags.forEach(function (tag) {
|
108 | if (typeof tag !== 'string') {
|
109 | return;
|
110 | }
|
111 |
|
112 | tagOperations[tag] = tagOperations[tag] || {};
|
113 | var tagObj = tagOperations[tag];
|
114 | var id = opId(operation, pathName, method, {
|
115 | v2OperationIdCompatibilityMode: v2OperationIdCompatibilityMode
|
116 | });
|
117 | var cbResult = cb({
|
118 | spec: spec,
|
119 | pathName: pathName,
|
120 | method: method,
|
121 | operation: operation,
|
122 | operationId: id
|
123 | });
|
124 |
|
125 | if (operationIdCounter[id]) {
|
126 | operationIdCounter[id] += 1;
|
127 | tagObj["".concat(id).concat(operationIdCounter[id])] = cbResult;
|
128 | } else if (typeof tagObj[id] !== 'undefined') {
|
129 |
|
130 | var originalCounterValue = operationIdCounter[id] || 1;
|
131 | operationIdCounter[id] = originalCounterValue + 1;
|
132 |
|
133 | tagObj["".concat(id).concat(operationIdCounter[id])] = cbResult;
|
134 |
|
135 | var temp = tagObj[id];
|
136 | delete tagObj[id];
|
137 | tagObj["".concat(id).concat(originalCounterValue)] = temp;
|
138 | } else {
|
139 |
|
140 | tagObj[id] = cbResult;
|
141 | }
|
142 | });
|
143 | });
|
144 | return tagOperations;
|
145 | } |
\ | No newline at end of file |