@scalar/postman-to-openapi 0.7.38 → 0.7.40
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 +10 -0
- package/dist/helpers/merge-operation.d.ts.map +1 -1
- package/dist/helpers/merge-operation.js +24 -8
- package/dist/helpers/parameters.d.ts.map +1 -1
- package/dist/helpers/parameters.js +5 -22
- package/dist/helpers/schemas.d.ts +1 -1
- package/dist/helpers/schemas.d.ts.map +1 -1
- package/dist/helpers/schemas.js +4 -3
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @scalar/postman-to-openapi
|
|
2
2
|
|
|
3
|
+
## 0.7.40
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.7.39
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#11341](https://github.com/scalar/scalar/pull/11341): fix: infer string schemas for blank Postman query and header values and for non-finite numbers. When merging requests, use populated examples to infer the shared parameter type and preserve blank and valueless examples.
|
|
12
|
+
|
|
3
13
|
## 0.7.38
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-operation.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"merge-operation.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAmCxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,eAAe,GAC1B,YAAY,WAAW,CAAC,eAAe,EACvC,YAAY,WAAW,CAAC,eAAe,KACtC,WAAW,CAAC,eAsHd,CAAA"}
|
|
@@ -10,6 +10,17 @@ const SCRIPT_MERGE_CONFIG = [
|
|
|
10
10
|
outputKey: 'x-post-response',
|
|
11
11
|
},
|
|
12
12
|
];
|
|
13
|
+
const hasOnlyUnpopulatedExamples = (parameter) => {
|
|
14
|
+
const examples = Object.values(parameter.examples ?? {});
|
|
15
|
+
return (examples.length > 0 &&
|
|
16
|
+
examples.every((example) => {
|
|
17
|
+
if ('$ref' in example || example.externalValue !== undefined) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const value = example.value;
|
|
21
|
+
return value === null || value === undefined || (typeof value === 'string' && value.trim() === '');
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
13
24
|
/**
|
|
14
25
|
* Merges two OpenAPI OperationObject instances.
|
|
15
26
|
* Assumes that all example names (keys in the 'examples' objects) are unique across both operations.
|
|
@@ -81,15 +92,20 @@ export const mergeOperations = (operation1, operation2) => {
|
|
|
81
92
|
if (operation1.parameters) {
|
|
82
93
|
for (const parameter of operation1.parameters) {
|
|
83
94
|
const id = getParameterKey(parameter);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
const existingParameter = parameters.get(id);
|
|
96
|
+
if (existingParameter) {
|
|
97
|
+
// Keep the earlier schema when the incoming examples supply no populated values.
|
|
98
|
+
if ((existingParameter.in === 'query' || existingParameter.in === 'header') &&
|
|
99
|
+
parameter.schema &&
|
|
100
|
+
hasOnlyUnpopulatedExamples(existingParameter) &&
|
|
101
|
+
!hasOnlyUnpopulatedExamples(parameter)) {
|
|
102
|
+
existingParameter.schema = parameter.schema;
|
|
92
103
|
}
|
|
104
|
+
// Example keys are expected to be unique, so shallow merge is safe.
|
|
105
|
+
existingParameter.examples = {
|
|
106
|
+
...existingParameter.examples,
|
|
107
|
+
...parameter.examples,
|
|
108
|
+
};
|
|
93
109
|
}
|
|
94
110
|
else {
|
|
95
111
|
parameters.set(id, parameter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../src/helpers/parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,SAAS,CAAA;AAwC9C,4FAA4F;AAC5F,eAAO,MAAM,eAAe,GAAI,WAAW,WAAW,CAAC,eAAe,KAAG,MAA6C,CAAA;AAEtH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAC9B,WAAW,CAAC,eAAe,EAAE,CA+D/B;AAoBD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,EACpC,WAAW,EAAE,MAAM,GAClB,WAAW,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../src/helpers/parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,SAAS,CAAA;AAwC9C,4FAA4F;AAC5F,eAAO,MAAM,eAAe,GAAI,WAAW,WAAW,CAAC,eAAe,KAAG,MAA6C,CAAA;AAEtH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,GAC9B,WAAW,CAAC,eAAe,EAAE,CA+D/B;AAoBD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,EACpC,WAAW,EAAE,MAAM,GAClB,WAAW,CAAC,eAAe,CA2C7B"}
|
|
@@ -119,13 +119,15 @@ function extractPathVariablesFromPathArray(pathArray) {
|
|
|
119
119
|
*/
|
|
120
120
|
export function createParameterObject(param, paramIn, exampleName) {
|
|
121
121
|
const description = normalizeDescription(param.description);
|
|
122
|
+
const value = param.value;
|
|
122
123
|
const parameter = {
|
|
123
124
|
name: param.key || '',
|
|
124
125
|
in: paramIn,
|
|
125
126
|
description,
|
|
126
127
|
examples: {
|
|
127
128
|
[exampleName]: {
|
|
128
|
-
|
|
129
|
+
// JSON serialization would otherwise replace non-finite numbers with null.
|
|
130
|
+
value: typeof value === 'number' && !Number.isFinite(value) ? String(value) : value,
|
|
129
131
|
'x-disabled': !!param.disabled,
|
|
130
132
|
},
|
|
131
133
|
},
|
|
@@ -145,27 +147,8 @@ export function createParameterObject(param, paramIn, exampleName) {
|
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// This prevents converting string IDs like "testId" to integers
|
|
151
|
-
if (paramIn === 'path') {
|
|
152
|
-
// Path parameters are typically strings (IDs, slugs, etc.)
|
|
153
|
-
// Only use number/integer if the value is actually a number type, not a string
|
|
154
|
-
if (typeof param.value === 'number') {
|
|
155
|
-
parameter.schema = inferSchemaType(param.value);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// For strings (including empty strings), default to string type
|
|
159
|
-
parameter.schema = { type: 'string' };
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
parameter.schema = inferSchemaType(param.value);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
parameter.schema = { type: 'string' }; // Default to string if no value is provided
|
|
168
|
-
}
|
|
150
|
+
// Keep string IDs like "001" as strings in path parameters.
|
|
151
|
+
parameter.schema = paramIn === 'path' && typeof value !== 'number' ? { type: 'string' } : inferSchemaType(value);
|
|
169
152
|
// Add x-scalar-disabled extension if parameter is disabled
|
|
170
153
|
if (param.disabled === true) {
|
|
171
154
|
// @ts-expect-error - x-scalar-disabled is not a valid parameter object property
|
|
@@ -9,5 +9,5 @@ export declare const inferSchemaFromExample: (example: unknown) => OpenAPIV3_1.S
|
|
|
9
9
|
* by checking its JavaScript type and attempting to parse it
|
|
10
10
|
* as a number or boolean if it's a string.
|
|
11
11
|
*/
|
|
12
|
-
export declare function inferSchemaType(value:
|
|
12
|
+
export declare function inferSchemaType(value: unknown): OpenAPIV3_1.NonArraySchemaObject;
|
|
13
13
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/helpers/schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMxD;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,OAAO,KAAG,WAAW,CAAC,YAAuC,CAAA;AA+D7G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/helpers/schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMxD;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,OAAO,KAAG,WAAW,CAAC,YAAuC,CAAA;AA+D7G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,oBAAoB,CAuBhF"}
|
package/dist/helpers/schemas.js
CHANGED
|
@@ -66,15 +66,16 @@ const getSchemaKey = (value, keyword) => {
|
|
|
66
66
|
* as a number or boolean if it's a string.
|
|
67
67
|
*/
|
|
68
68
|
export function inferSchemaType(value) {
|
|
69
|
-
if (typeof value === 'number') {
|
|
69
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
70
70
|
return { type: Number.isInteger(value) ? 'integer' : 'number' };
|
|
71
71
|
}
|
|
72
72
|
if (typeof value === 'boolean') {
|
|
73
73
|
return { type: 'boolean' };
|
|
74
74
|
}
|
|
75
75
|
if (typeof value === 'string') {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// `Number('')` is 0, so an empty value would otherwise look like an integer.
|
|
77
|
+
const num = value.trim() === '' ? Number.NaN : Number(value);
|
|
78
|
+
if (Number.isFinite(num)) {
|
|
78
79
|
return { type: Number.isInteger(num) ? 'integer' : 'number' };
|
|
79
80
|
}
|
|
80
81
|
if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"export",
|
|
20
20
|
"scalar"
|
|
21
21
|
],
|
|
22
|
-
"version": "0.7.
|
|
22
|
+
"version": "0.7.40",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=22"
|
|
25
25
|
},
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"CHANGELOG.md"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@scalar/helpers": "0.21.
|
|
41
|
+
"@scalar/helpers": "0.21.2",
|
|
42
42
|
"@scalar/openapi-types": "0.9.10"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@scalar/openapi-parser": "0.29.
|
|
46
|
-
"@types/node": "^24.19.
|
|
47
|
-
"vite": "8.
|
|
45
|
+
"@scalar/openapi-parser": "0.29.33",
|
|
46
|
+
"@types/node": "^24.19.4",
|
|
47
|
+
"vite": "8.4.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|