@scalar/oas-utils 0.2.84 → 0.2.85
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 +8 -0
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +12 -5
- package/dist/helpers/httpMethods.d.ts +3 -1
- package/dist/helpers/httpMethods.d.ts.map +1 -1
- package/dist/helpers/httpMethods.js +5 -1
- package/dist/helpers/index.js +1 -1
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +69 -68
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.85
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3b4a788: feat: sets form request examples defaulting
|
|
8
|
+
- 4c5be96: feat: adds isHttpMethod to helpers
|
|
9
|
+
- 4c5be96: fix: sorts method based on path in import spec
|
|
10
|
+
|
|
3
11
|
## 0.2.84
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAczC,CAAA;AAUF,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEvC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAOjE,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB;IAC/B,qCAAqC;;;;QA3CrC;;;;WAIG;;QAEH,0EAA0E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8C1E,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;;;;;;;;;;;;;EA8D9D;AAKD,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;EA8C1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,cAAc,CA2GhB"}
|
|
@@ -325,12 +325,19 @@ function createExampleFromRequest(request, name, server) {
|
|
|
325
325
|
body.activeBody = 'binary';
|
|
326
326
|
body.binary = undefined;
|
|
327
327
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
*/
|
|
331
|
-
if (requestBody?.body?.mimeType === 'application/x-www-form-urlencoded') {
|
|
328
|
+
if (requestBody?.body?.mimeType === 'application/x-www-form-urlencoded' ||
|
|
329
|
+
requestBody?.body?.mimeType === 'multipart/form-data') {
|
|
332
330
|
body.activeBody = 'formData';
|
|
333
|
-
body.formData =
|
|
331
|
+
body.formData = {
|
|
332
|
+
encoding: requestBody.body.mimeType === 'application/x-www-form-urlencoded'
|
|
333
|
+
? 'urlencoded'
|
|
334
|
+
: 'form-data',
|
|
335
|
+
value: (requestBody.body.params || []).map((param) => ({
|
|
336
|
+
key: param.name,
|
|
337
|
+
value: param.value || '',
|
|
338
|
+
enabled: true,
|
|
339
|
+
})),
|
|
340
|
+
};
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
const serverVariables = server ? getServerVariableExamples(server) : {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RequestMethod } from '../entities/spec/requests.js';
|
|
2
2
|
/**
|
|
3
3
|
* HTTP methods in a specific order
|
|
4
4
|
* Do not change the order
|
|
@@ -23,5 +23,7 @@ export declare const getHttpMethodInfo: (methodName: string) => {
|
|
|
23
23
|
color: string;
|
|
24
24
|
backgroundColor: string;
|
|
25
25
|
};
|
|
26
|
+
/** Type guard which takes in a string and returns true if it is in fact an HTTPMethod */
|
|
27
|
+
export declare const isHttpMethod: (method: string) => method is RequestMethod;
|
|
26
28
|
export {};
|
|
27
29
|
//# sourceMappingURL=httpMethods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpMethods.d.ts","sourceRoot":"","sources":["../../src/helpers/httpMethods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"httpMethods.d.ts","sourceRoot":"","sources":["../../src/helpers/httpMethods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,0BAA0B,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE;KAC3B,CAAC,IAAI,aAAa,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,KAAK,EAAE,MAAM,CAAA;QACb,eAAe,EAAE,MAAM,CAAA;KACxB;CA+CO,CAAA;AAEV,yCAAyC;AACzC,QAAA,MAAM,YAAY,6CAA8C,CAAA;AAChE,KAAK,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/C,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,WACpB,aAAa,KACpB,MAAM,IAAI,UAAyD,CAAA;AAEtE;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM;WAhEzC,MAAM;WACN,MAAM;qBACI,MAAM;CAuE1B,CAAA;AAED,yFAAyF;AACzF,eAAO,MAAM,YAAY,WAAY,MAAM,KAAG,MAAM,IAAI,aACN,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { requestMethods } from '../entities/spec/requests.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* HTTP methods in a specific order
|
|
3
5
|
* Do not change the order
|
|
@@ -64,5 +66,7 @@ const getHttpMethodInfo = (methodName) => {
|
|
|
64
66
|
backgroundColor: 'bg-c-2',
|
|
65
67
|
});
|
|
66
68
|
};
|
|
69
|
+
/** Type guard which takes in a string and returns true if it is in fact an HTTPMethod */
|
|
70
|
+
const isHttpMethod = (method) => requestMethods.includes(method);
|
|
67
71
|
|
|
68
|
-
export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo };
|
|
72
|
+
export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo, isHttpMethod };
|
package/dist/helpers/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { createHash } from './createHash.js';
|
|
|
3
3
|
export { fetchSpecFromUrl } from './fetchSpecFromUrl.js';
|
|
4
4
|
export { fetchWithProxyFallback } from './fetchWithProxyFallback.js';
|
|
5
5
|
export { findVariables } from './findVariables.js';
|
|
6
|
-
export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo } from './httpMethods.js';
|
|
6
|
+
export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo, isHttpMethod } from './httpMethods.js';
|
|
7
7
|
export { httpStatusCodes } from './httpStatusCodes.js';
|
|
8
8
|
export { isLocalUrl } from './isLocalUrl.js';
|
|
9
9
|
export { isValidUrl } from './isValidUrl.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAKjC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAgB,MAAM,GAAG,aAAa;IAwB1D;;;OAGG;YAEC,SAAS,CAAC,QAAQ,GAClB,WAAW,CAAC,QAAQ;;;;;EAG3B,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAC1C,iBAAiB,EACjB,aAAa,GAAG,WAAW,CAC5B,GACC,IAAI,CACF,sBAAsB,EACtB,gBAAgB,GAAG,eAAe,GAAG,SAAS,CAC/C,GAAG;IACF,mFAAmF;IACnF,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,GAAG,aAAa,EAC5B,EACE,cAAc,EACd,aAAa,EACb,WAAW,EACX,OAAO,EAAE,eAAe,EACxB,qBAA6B,EAC7B,SAAiB,GAClB,GAAE,yBAA8B,GAChC,OAAO,CACN;IACE,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,MAAM,EAAE,SAAS,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;IACjD,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CAuVA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { securitySchemeSchema } from '../entities/spec/security.js';
|
|
2
|
+
import { isHttpMethod } from '../helpers/httpMethods.js';
|
|
2
3
|
import { schemaModel } from '../helpers/schema-model.js';
|
|
3
4
|
import { keysOf } from '@scalar/object-utils/arrays';
|
|
4
5
|
import { load, upgrade, dereference } from '@scalar/openapi-parser';
|
|
5
6
|
import { serverSchema } from '../entities/spec/server.js';
|
|
6
|
-
import {
|
|
7
|
+
import { requestSchema } from '../entities/spec/requests.js';
|
|
7
8
|
import { tagSchema } from '../entities/spec/spec-objects.js';
|
|
8
9
|
import { createExampleFromRequest } from '../entities/spec/request-examples.js';
|
|
9
10
|
import { collectionSchema } from '../entities/spec/collection.js';
|
|
@@ -161,77 +162,77 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
161
162
|
// Path level servers must be saved
|
|
162
163
|
const pathServers = serverSchema.array().parse(path.servers ?? []);
|
|
163
164
|
servers.push(...pathServers);
|
|
164
|
-
|
|
165
|
+
// Creates a sorted array of methods based on the path object.
|
|
166
|
+
const methods = Object.keys(path).filter(isHttpMethod);
|
|
167
|
+
methods.forEach((method) => {
|
|
165
168
|
const operation = path[method];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
169
|
+
const operationServers = serverSchema
|
|
170
|
+
.array()
|
|
171
|
+
.parse(operation.servers ?? []);
|
|
172
|
+
servers.push(...operationServers);
|
|
173
|
+
// We will save a list of all tags to ensure they exists at the top level
|
|
174
|
+
// TODO: make sure we add any loose requests with no tags to the collection children
|
|
175
|
+
operation.tags?.forEach((t) => tagNames.add(t));
|
|
176
|
+
// Remove security here and add it correctly below
|
|
177
|
+
const { security: operationSecurity, ...operationWithoutSecurity } = operation;
|
|
178
|
+
// Grab the security requirements for this operation
|
|
179
|
+
const securityRequirements = (operationSecurity ??
|
|
180
|
+
schema.security ??
|
|
181
|
+
[]).flatMap((s) => {
|
|
182
|
+
const keys = Object.keys(s);
|
|
183
|
+
if (keys.length)
|
|
184
|
+
return keys[0];
|
|
185
|
+
else
|
|
186
|
+
return [];
|
|
187
|
+
});
|
|
188
|
+
let selectedSecuritySchemeUids = [];
|
|
189
|
+
// Set the initially selected security scheme
|
|
190
|
+
if (securityRequirements.length && !setCollectionSecurity) {
|
|
191
|
+
const name = authentication?.preferredSecurityScheme &&
|
|
192
|
+
securityRequirements.includes(authentication.preferredSecurityScheme ?? '')
|
|
193
|
+
? authentication.preferredSecurityScheme
|
|
194
|
+
: securityRequirements[0];
|
|
195
|
+
const uid = securitySchemeMap[name];
|
|
196
|
+
selectedSecuritySchemeUids = [uid];
|
|
197
|
+
}
|
|
198
|
+
const requestPayload = {
|
|
199
|
+
...operationWithoutSecurity,
|
|
200
|
+
method,
|
|
201
|
+
path: pathString,
|
|
202
|
+
selectedSecuritySchemeUids,
|
|
203
|
+
// Merge path and operation level parameters
|
|
204
|
+
parameters: [
|
|
205
|
+
...(path?.parameters ?? []),
|
|
206
|
+
...(operation.parameters ?? []),
|
|
207
|
+
],
|
|
208
|
+
servers: [...pathServers, ...operationServers].map((s) => s.uid),
|
|
209
|
+
};
|
|
210
|
+
// Remove any examples from the request payload as they conflict with our examples property and are not valid
|
|
211
|
+
if (requestPayload.examples) {
|
|
212
|
+
console.warn('[@scalar/api-client] operation.examples is not a valid openapi property');
|
|
213
|
+
delete requestPayload.examples;
|
|
214
|
+
}
|
|
215
|
+
// Add list of UIDs to associate security schemes
|
|
216
|
+
// As per the spec if there is operation level security we ignore the top level requirements
|
|
217
|
+
if (operationSecurity?.length)
|
|
218
|
+
requestPayload.security = operationSecurity.map((s) => {
|
|
180
219
|
const keys = Object.keys(s);
|
|
181
|
-
|
|
182
|
-
|
|
220
|
+
// Handle the case of {} for optional
|
|
221
|
+
if (keys.length) {
|
|
222
|
+
const [key] = Object.keys(s);
|
|
223
|
+
return {
|
|
224
|
+
[key]: s[key],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
183
227
|
else
|
|
184
|
-
return
|
|
228
|
+
return s;
|
|
185
229
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
: securityRequirements[0];
|
|
193
|
-
const uid = securitySchemeMap[name];
|
|
194
|
-
selectedSecuritySchemeUids = [uid];
|
|
195
|
-
}
|
|
196
|
-
const requestPayload = {
|
|
197
|
-
...operationWithoutSecurity,
|
|
198
|
-
method,
|
|
199
|
-
path: pathString,
|
|
200
|
-
selectedSecuritySchemeUids,
|
|
201
|
-
// Merge path and operation level parameters
|
|
202
|
-
parameters: [
|
|
203
|
-
...(path?.parameters ?? []),
|
|
204
|
-
...(operation.parameters ?? []),
|
|
205
|
-
],
|
|
206
|
-
servers: [...pathServers, ...operationServers].map((s) => s.uid),
|
|
207
|
-
};
|
|
208
|
-
// Remove any examples from the request payload as they conflict with our examples property and are not valid
|
|
209
|
-
if (requestPayload.examples) {
|
|
210
|
-
console.warn('[@scalar/api-client] operation.examples is not a valid openapi property');
|
|
211
|
-
delete requestPayload.examples;
|
|
212
|
-
}
|
|
213
|
-
// Add list of UIDs to associate security schemes
|
|
214
|
-
// As per the spec if there is operation level security we ignore the top level requirements
|
|
215
|
-
if (operationSecurity?.length)
|
|
216
|
-
requestPayload.security = operationSecurity.map((s) => {
|
|
217
|
-
const keys = Object.keys(s);
|
|
218
|
-
// Handle the case of {} for optional
|
|
219
|
-
if (keys.length) {
|
|
220
|
-
const [key] = Object.keys(s);
|
|
221
|
-
return {
|
|
222
|
-
[key]: s[key],
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else
|
|
226
|
-
return s;
|
|
227
|
-
});
|
|
228
|
-
// Save parse the request
|
|
229
|
-
const request = schemaModel(requestPayload, requestSchema, false);
|
|
230
|
-
if (!request)
|
|
231
|
-
importWarnings.push(`${method} Request at ${path} is invalid.`);
|
|
232
|
-
else
|
|
233
|
-
requests.push(request);
|
|
234
|
-
}
|
|
230
|
+
// Save parse the request
|
|
231
|
+
const request = schemaModel(requestPayload, requestSchema, false);
|
|
232
|
+
if (!request)
|
|
233
|
+
importWarnings.push(`${method} Request at ${path} is invalid.`);
|
|
234
|
+
else
|
|
235
|
+
requests.push(request);
|
|
235
236
|
});
|
|
236
237
|
});
|
|
237
238
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.85",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -111,9 +111,9 @@
|
|
|
111
111
|
"nanoid": "^5.0.7",
|
|
112
112
|
"yaml": "^2.4.5",
|
|
113
113
|
"zod": "^3.23.8",
|
|
114
|
-
"@scalar/object-utils": "1.1.12",
|
|
115
|
-
"@scalar/themes": "0.9.54",
|
|
116
114
|
"@scalar/openapi-types": "0.1.5",
|
|
115
|
+
"@scalar/themes": "0.9.54",
|
|
116
|
+
"@scalar/object-utils": "1.1.12",
|
|
117
117
|
"@scalar/types": "0.0.23"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
@@ -121,9 +121,9 @@
|
|
|
121
121
|
"vite": "^5.4.10",
|
|
122
122
|
"vitest": "^1.6.0",
|
|
123
123
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
124
|
-
"@scalar/
|
|
124
|
+
"@scalar/openapi-types": "0.1.5",
|
|
125
125
|
"@scalar/openapi-parser": "0.8.10",
|
|
126
|
-
"@scalar/
|
|
126
|
+
"@scalar/build-tooling": "0.1.12"
|
|
127
127
|
},
|
|
128
128
|
"scripts": {
|
|
129
129
|
"build": "scalar-build-rollup",
|