@scalar/oas-utils 0.2.44 → 0.2.46
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 +14 -0
- package/dist/entities/spec/request-examples.d.ts +1 -0
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +19 -5
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/prettyPrintJson.js +1 -1
- package/dist/helpers/regexHelpers.d.ts +1 -0
- package/dist/helpers/regexHelpers.d.ts.map +1 -1
- package/dist/helpers/regexHelpers.js +2 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.46
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b75354: fix: null example bug
|
|
8
|
+
- 437d54d: fix: runtime null error prettyprint
|
|
9
|
+
|
|
10
|
+
## 0.2.45
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- ddeaada: fix: adds path regex helper
|
|
15
|
+
- 71278e1: fix(api-client): add back content header
|
|
16
|
+
|
|
3
17
|
## 0.2.44
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -57,6 +57,7 @@ export type RequestExampleParameter = z.infer<typeof requestExampleParametersSch
|
|
|
57
57
|
* TODO: This list may not be comprehensive enough
|
|
58
58
|
*/
|
|
59
59
|
export declare const exampleRequestBodyEncoding: readonly ["json", "text", "html", "javascript", "xml", "yaml", "edn"];
|
|
60
|
+
export type BodyEncoding = (typeof exampleRequestBodyEncoding)[number];
|
|
60
61
|
export declare const exampleRequestBodySchema: z.ZodObject<{
|
|
61
62
|
raw: z.ZodOptional<z.ZodObject<{
|
|
62
63
|
encoding: z.ZodDefault<z.ZodEnum<["json", "text", "html", "javascript", "xml", "yaml", "edn"]>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAMA,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;AAEtC,eAAO,MAAM,8BAA8B;;;;;;IAMzC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUlF,CAAA;AAEF,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,8BAA8B,CACtC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,uEAQ7B,CAAA;AACV,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;YAjCnC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDlF,CAAA;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEzE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;gBAvD/B,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
+
import { schemaModel } from '../../helpers/schema-model.js';
|
|
2
3
|
import { getRequestBodyFromOperation } from '../../spec-getters/getRequestBodyFromOperation.js';
|
|
3
4
|
import { getServerVariableExamples } from '../../spec-getters/getServerVariableExamples.js';
|
|
4
5
|
import { nanoidSchema } from '../shared/utility.js';
|
|
@@ -83,7 +84,8 @@ function createParamInstance(param) {
|
|
|
83
84
|
* - Need to handle unions/array values for schema
|
|
84
85
|
*/
|
|
85
86
|
const value = String(schema?.default ?? schema?.examples?.[0] ?? '');
|
|
86
|
-
|
|
87
|
+
// safe parse the example
|
|
88
|
+
const example = schemaModel({
|
|
87
89
|
...schema,
|
|
88
90
|
key: param.name,
|
|
89
91
|
value,
|
|
@@ -91,7 +93,13 @@ function createParamInstance(param) {
|
|
|
91
93
|
required: param.required,
|
|
92
94
|
/** Initialized all required properties to enabled */
|
|
93
95
|
enabled: !!param.required,
|
|
94
|
-
});
|
|
96
|
+
}, requestExampleParametersSchema, false);
|
|
97
|
+
if (!example) {
|
|
98
|
+
console.warn(`Example at ${param.name} is invalid.`);
|
|
99
|
+
return requestExampleParametersSchema.parse({});
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
return example;
|
|
95
103
|
}
|
|
96
104
|
/**
|
|
97
105
|
* Create new request example from a request
|
|
@@ -155,14 +163,20 @@ function createExampleFromRequest(request, name, server) {
|
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
const serverVariables = server ? getServerVariableExamples(server) : {};
|
|
158
|
-
|
|
166
|
+
// safe parse the example
|
|
167
|
+
const example = schemaModel({
|
|
159
168
|
requestUid: request.uid,
|
|
160
169
|
parameters,
|
|
161
170
|
name,
|
|
162
171
|
body,
|
|
163
172
|
serverVariables,
|
|
164
|
-
});
|
|
165
|
-
|
|
173
|
+
}, requestExampleSchema, false);
|
|
174
|
+
if (!example) {
|
|
175
|
+
console.warn(`Example at ${request.uid} is invalid.`);
|
|
176
|
+
return requestExampleSchema.parse({});
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
return example;
|
|
166
180
|
}
|
|
167
181
|
|
|
168
182
|
export { createExampleFromRequest, createParamInstance, exampleRequestBodyEncoding, exampleRequestBodySchema, requestExampleParametersSchema, requestExampleSchema };
|
package/dist/helpers/index.js
CHANGED
|
@@ -17,4 +17,4 @@ export { schemaModel } from './schema-model.js';
|
|
|
17
17
|
export { defaultStateFactory, ssrState } from './ssrState.js';
|
|
18
18
|
export { camelToTitleWords, capitalize } from './string.js';
|
|
19
19
|
export { isValidUrl } from './isValidUrl.js';
|
|
20
|
-
export { variableRegex } from './regexHelpers.js';
|
|
20
|
+
export { pathRegex, variableRegex } from './regexHelpers.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAA+B,CAAA"}
|
|
1
|
+
{"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAA+B,CAAA;AACzD,eAAO,MAAM,SAAS,QAA2B,CAAA"}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.46",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -93,9 +93,9 @@
|
|
|
93
93
|
"yaml": "^2.4.5",
|
|
94
94
|
"zod": "^3.23.8",
|
|
95
95
|
"@scalar/object-utils": "1.1.8",
|
|
96
|
-
"@scalar/
|
|
96
|
+
"@scalar/openapi-types": "0.1.1",
|
|
97
97
|
"@scalar/types": "0.0.9",
|
|
98
|
-
"@scalar/
|
|
98
|
+
"@scalar/themes": "0.9.30"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"rollup": "^4.16.4",
|
|
@@ -103,8 +103,8 @@
|
|
|
103
103
|
"vite": "^5.2.10",
|
|
104
104
|
"vitest": "^1.6.0",
|
|
105
105
|
"zod-to-ts": "^1.2.0",
|
|
106
|
-
"@scalar/build-tooling": "0.1.10",
|
|
107
106
|
"@scalar/openapi-parser": "0.8.3",
|
|
107
|
+
"@scalar/build-tooling": "0.1.10",
|
|
108
108
|
"@scalar/openapi-types": "0.1.1"
|
|
109
109
|
},
|
|
110
110
|
"scripts": {
|