@scalar/openapi-parser 0.10.13 → 0.10.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgradeFromTwoToThree.d.ts","sourceRoot":"","sources":["../../src/utils/upgradeFromTwoToThree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"upgradeFromTwoToThree.d.ts","sourceRoot":"","sources":["../../src/utils/upgradeFromTwoToThree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CA+PzE"}
|
|
@@ -44,6 +44,13 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
44
44
|
return schema;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
specification = traverse(specification, (schema) => {
|
|
48
|
+
if (schema.type === 'file') {
|
|
49
|
+
schema.type = 'string';
|
|
50
|
+
schema.format = 'binary';
|
|
51
|
+
}
|
|
52
|
+
return schema;
|
|
53
|
+
});
|
|
47
54
|
// Paths
|
|
48
55
|
if (typeof specification.paths === 'object') {
|
|
49
56
|
for (const path in specification.paths) {
|
|
@@ -109,12 +116,21 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
109
116
|
// Remove formData parameters from the parameters array
|
|
110
117
|
operationItem.parameters = operationItem.parameters.filter((parameter) => parameter.in !== 'formData');
|
|
111
118
|
}
|
|
119
|
+
operationItem.parameters = operationItem.parameters.map((parameter) => transformParameterObject(parameter));
|
|
112
120
|
}
|
|
113
121
|
// Responses
|
|
114
122
|
if (operationItem.responses) {
|
|
115
123
|
for (const response in operationItem.responses) {
|
|
116
124
|
if (Object.hasOwn(operationItem.responses, response)) {
|
|
117
125
|
const responseItem = operationItem.responses[response];
|
|
126
|
+
if (responseItem.headers) {
|
|
127
|
+
responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {
|
|
128
|
+
return {
|
|
129
|
+
[name]: transformParameterObject(header),
|
|
130
|
+
...acc,
|
|
131
|
+
};
|
|
132
|
+
}, {});
|
|
133
|
+
}
|
|
118
134
|
if (responseItem.schema) {
|
|
119
135
|
const produces = specification.produces ?? operationItem.produces ?? ['application/json'];
|
|
120
136
|
if (typeof responseItem.content !== 'object') {
|
|
@@ -162,6 +178,14 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
162
178
|
},
|
|
163
179
|
});
|
|
164
180
|
}
|
|
181
|
+
else if ('type' in securityScheme && securityScheme.type === 'basic') {
|
|
182
|
+
Object.assign(specification.components.securitySchemes, {
|
|
183
|
+
[key]: {
|
|
184
|
+
type: 'http',
|
|
185
|
+
scheme: 'basic',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
165
189
|
else {
|
|
166
190
|
Object.assign(specification.components.securitySchemes, {
|
|
167
191
|
[key]: securityScheme,
|
|
@@ -173,5 +197,39 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
173
197
|
}
|
|
174
198
|
return specification;
|
|
175
199
|
}
|
|
200
|
+
function transformItemsObject(obj) {
|
|
201
|
+
const schemaProperties = [
|
|
202
|
+
'type',
|
|
203
|
+
'format',
|
|
204
|
+
'items',
|
|
205
|
+
'maximum',
|
|
206
|
+
'exclusiveMaximum',
|
|
207
|
+
'minimum',
|
|
208
|
+
'exclusiveMinimum',
|
|
209
|
+
'maxLength',
|
|
210
|
+
'minLength',
|
|
211
|
+
'pattern',
|
|
212
|
+
'maxItems',
|
|
213
|
+
'minItems',
|
|
214
|
+
'uniqueItems',
|
|
215
|
+
'enum',
|
|
216
|
+
'multipleOf',
|
|
217
|
+
];
|
|
218
|
+
return schemaProperties.reduce((acc, property) => {
|
|
219
|
+
if (Object.hasOwn(obj, property)) {
|
|
220
|
+
acc[property] = obj[property];
|
|
221
|
+
delete obj[property];
|
|
222
|
+
}
|
|
223
|
+
return acc;
|
|
224
|
+
}, {});
|
|
225
|
+
}
|
|
226
|
+
function transformParameterObject(parameter) {
|
|
227
|
+
delete parameter.collectionFormat;
|
|
228
|
+
delete parameter.default;
|
|
229
|
+
return {
|
|
230
|
+
schema: transformItemsObject(parameter),
|
|
231
|
+
...parameter,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
176
234
|
|
|
177
235
|
export { upgradeFromTwoToThree };
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"parser",
|
|
18
18
|
"typescript"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.10.
|
|
20
|
+
"version": "0.10.14",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"just-diff": "^6.0.2",
|
|
66
66
|
"tinybench": "^2.8.0",
|
|
67
67
|
"@scalar/build-tooling": "0.1.17",
|
|
68
|
-
"@scalar/types": "0.1.
|
|
68
|
+
"@scalar/types": "0.1.6",
|
|
69
69
|
"@scalar/openapi-types": "0.2.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|