@scalar/openapi-upgrader 0.1.11 → 0.2.1
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 +19 -0
- package/dist/2.0-to-3.0/index.js +1 -5
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.js +641 -550
- package/dist/3.0-to-3.1/index.js +1 -5
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +139 -111
- package/dist/3.1-to-3.2/index.js +1 -5
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +94 -64
- package/dist/helpers/traverse.js +21 -22
- package/dist/index.js +1 -5
- package/dist/upgrade.bench.js +42 -27
- package/dist/upgrade.js +19 -20
- package/package.json +7 -9
- package/dist/2.0-to-3.0/index.js.map +0 -7
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.js.map +0 -7
- package/dist/3.0-to-3.1/index.js.map +0 -7
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js.map +0 -7
- package/dist/3.1-to-3.2/index.js.map +0 -7
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js.map +0 -7
- package/dist/helpers/traverse.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/upgrade.bench.js.map +0 -7
- package/dist/upgrade.js.map +0 -7
package/dist/3.0-to-3.1/index.js
CHANGED
|
@@ -1,126 +1,154 @@
|
|
|
1
|
-
import { traverse } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { traverse } from '../helpers/traverse.js';
|
|
2
|
+
// Create Sets for faster schema path lookups
|
|
3
|
+
const SCHEMA_SEGMENTS = new Set([
|
|
4
|
+
'properties',
|
|
5
|
+
'items',
|
|
6
|
+
'allOf',
|
|
7
|
+
'anyOf',
|
|
8
|
+
'oneOf',
|
|
9
|
+
'not',
|
|
10
|
+
'additionalProperties',
|
|
11
|
+
'schema',
|
|
11
12
|
]);
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/** Determine if the current path is within a schema - optimized version */
|
|
14
|
+
export function isSchemaPath(path) {
|
|
15
|
+
// Early return if path is undefined
|
|
16
|
+
if (!path) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
// Check for schema segments first (most common case)
|
|
20
|
+
if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
// Check for schema suffix
|
|
24
|
+
if (path.some((segment) => segment.endsWith('Schema'))) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// Check for components/schemas path
|
|
28
|
+
if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
14
31
|
return false;
|
|
15
|
-
}
|
|
16
|
-
if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
if (path.some((segment) => segment.endsWith("Schema"))) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (path.length >= 2 && path[0] === "components" && path[1] === "schemas") {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Upgrade from OpenAPI 3.0.x to 3.1.1
|
|
35
|
+
*
|
|
36
|
+
* https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
|
|
37
|
+
*/
|
|
38
|
+
export function upgradeFromThreeToThreeOne(originalContent) {
|
|
39
|
+
let content = originalContent;
|
|
40
|
+
// Version check - early return if not 3.0.x
|
|
41
|
+
if (content === null || typeof content.openapi !== 'string' || !content.openapi.startsWith('3.0')) {
|
|
42
|
+
return content;
|
|
43
|
+
}
|
|
44
|
+
content.openapi = '3.1.1';
|
|
45
|
+
// Single traversal that handles all transformations
|
|
46
|
+
content = traverse(content, applyChangesToDocument);
|
|
30
47
|
return content;
|
|
31
|
-
}
|
|
32
|
-
content.openapi = "3.1.1";
|
|
33
|
-
content = traverse(content, applyChangesToDocument);
|
|
34
|
-
return content;
|
|
35
48
|
}
|
|
36
49
|
const applyChangesToDocument = (schema, path) => {
|
|
37
|
-
|
|
38
|
-
schema.type
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (schema.exclusiveMinimum === true) {
|
|
42
|
-
schema.exclusiveMinimum = schema.minimum;
|
|
43
|
-
delete schema.minimum;
|
|
44
|
-
} else if (schema.exclusiveMinimum === false) {
|
|
45
|
-
delete schema.exclusiveMinimum;
|
|
46
|
-
}
|
|
47
|
-
if (schema.exclusiveMaximum === true) {
|
|
48
|
-
schema.exclusiveMaximum = schema.maximum;
|
|
49
|
-
delete schema.maximum;
|
|
50
|
-
} else if (schema.exclusiveMaximum === false) {
|
|
51
|
-
delete schema.exclusiveMaximum;
|
|
52
|
-
}
|
|
53
|
-
const isInsideExamplesMap = path?.some((segment, index) => {
|
|
54
|
-
if (segment === "examples" && index > 0) {
|
|
55
|
-
const parent = path[index - 1];
|
|
56
|
-
return parent !== "properties";
|
|
50
|
+
// 1. Handle nullable types
|
|
51
|
+
if (schema.type !== undefined && schema.nullable === true) {
|
|
52
|
+
schema.type = [schema.type, 'null'];
|
|
53
|
+
delete schema.nullable;
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
// 2. Handle exclusiveMinimum and exclusiveMaximum
|
|
56
|
+
if (schema.exclusiveMinimum === true) {
|
|
57
|
+
schema.exclusiveMinimum = schema.minimum;
|
|
58
|
+
delete schema.minimum;
|
|
59
|
+
}
|
|
60
|
+
else if (schema.exclusiveMinimum === false) {
|
|
61
|
+
delete schema.exclusiveMinimum;
|
|
62
|
+
}
|
|
63
|
+
if (schema.exclusiveMaximum === true) {
|
|
64
|
+
schema.exclusiveMaximum = schema.maximum;
|
|
65
|
+
delete schema.maximum;
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
else if (schema.exclusiveMaximum === false) {
|
|
68
|
+
delete schema.exclusiveMaximum;
|
|
69
|
+
}
|
|
70
|
+
// 3. Handle examples
|
|
71
|
+
// Skip conversion if we're already inside an examples map to avoid double nesting
|
|
72
|
+
// Check if 'examples' appears as an exact path segment (not just a substring)
|
|
73
|
+
// BUT exclude cases where 'examples' is just a schema property name
|
|
74
|
+
const isInsideExamplesMap = path?.some((segment, index) => {
|
|
75
|
+
// Only consider it an examples map if 'examples' is not a schema property name
|
|
76
|
+
if (segment === 'examples' && index > 0) {
|
|
77
|
+
const parent = path[index - 1];
|
|
78
|
+
// If parent is 'properties', then 'examples' is just a property name, not an examples map
|
|
79
|
+
return parent !== 'properties';
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
76
82
|
});
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (schema.example !== undefined && !isInsideExamplesMap) {
|
|
84
|
+
if (isSchemaPath(path)) {
|
|
85
|
+
schema.examples = [schema.example];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
schema.examples = {
|
|
89
|
+
default: {
|
|
90
|
+
value: schema.example,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
82
93
|
}
|
|
83
|
-
|
|
94
|
+
delete schema.example;
|
|
84
95
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
// 4. Handle multipart file uploads
|
|
97
|
+
if (schema.type === 'object' && schema.properties !== undefined) {
|
|
98
|
+
const parentPath = path?.slice(0, -1);
|
|
99
|
+
const isMultipart = parentPath?.some((segment, index) => {
|
|
100
|
+
return segment === 'content' && path?.[index + 1] === 'multipart/form-data';
|
|
101
|
+
});
|
|
102
|
+
if (isMultipart && schema.properties !== null) {
|
|
103
|
+
for (const value of Object.values(schema.properties)) {
|
|
104
|
+
if (typeof value === 'object' &&
|
|
105
|
+
value !== null &&
|
|
106
|
+
'type' in value &&
|
|
107
|
+
'format' in value &&
|
|
108
|
+
value.type === 'string' &&
|
|
109
|
+
value.format === 'binary') {
|
|
110
|
+
value.contentMediaType = 'application/octet-stream';
|
|
111
|
+
delete value.format;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
97
115
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
type: "string",
|
|
102
|
-
contentEncoding: "base64"
|
|
103
|
-
};
|
|
116
|
+
// 5. Handle binary file uploads
|
|
117
|
+
if (path?.includes('content') && path?.includes('application/octet-stream')) {
|
|
118
|
+
return {};
|
|
104
119
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
// 6. Handle older formats
|
|
121
|
+
const { format: _, ...rest } = schema;
|
|
122
|
+
if (schema.type === 'string') {
|
|
123
|
+
if (schema.format === 'binary') {
|
|
124
|
+
return {
|
|
125
|
+
...rest,
|
|
126
|
+
type: 'string',
|
|
127
|
+
contentMediaType: 'application/octet-stream',
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (schema.format === 'base64') {
|
|
131
|
+
return {
|
|
132
|
+
...rest,
|
|
133
|
+
type: 'string',
|
|
134
|
+
contentEncoding: 'base64',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (schema.format === 'byte') {
|
|
138
|
+
const parentPath = path?.slice(0, -1);
|
|
139
|
+
const contentMediaType = parentPath?.find((_, index) => path?.[index - 1] === 'content');
|
|
140
|
+
return {
|
|
141
|
+
...rest,
|
|
142
|
+
type: 'string',
|
|
143
|
+
contentEncoding: 'base64',
|
|
144
|
+
contentMediaType,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
114
147
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
export {
|
|
123
|
-
isSchemaPath,
|
|
124
|
-
upgradeFromThreeToThreeOne
|
|
148
|
+
// 7. Handle x-webhooks
|
|
149
|
+
if (schema['x-webhooks'] !== undefined) {
|
|
150
|
+
schema.webhooks = schema['x-webhooks'];
|
|
151
|
+
delete schema['x-webhooks'];
|
|
152
|
+
}
|
|
153
|
+
return schema;
|
|
125
154
|
};
|
|
126
|
-
//# sourceMappingURL=upgrade-from-three-to-three-one.js.map
|
package/dist/3.1-to-3.2/index.js
CHANGED
|
@@ -1,77 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively migrate XML object properties from 3.1 to 3.2 format
|
|
3
|
+
*/
|
|
1
4
|
function migrateXmlObjects(obj) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
if (Array.isArray(obj)) {
|
|
6
|
-
for (const item of obj) {
|
|
7
|
-
migrateXmlObjects(item);
|
|
5
|
+
if (obj === null || typeof obj !== 'object') {
|
|
6
|
+
return;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (obj.xml.wrapped === true) {
|
|
16
|
-
delete obj.xml.wrapped;
|
|
17
|
-
obj.xml.nodeType = "element";
|
|
8
|
+
// Handle arrays
|
|
9
|
+
if (Array.isArray(obj)) {
|
|
10
|
+
for (const item of obj) {
|
|
11
|
+
migrateXmlObjects(item);
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
// Handle xml property migration
|
|
16
|
+
if (obj.xml && typeof obj.xml === 'object') {
|
|
17
|
+
if (obj.xml.wrapped === true && obj.xml.attribute === true) {
|
|
18
|
+
throw new Error('Invalid XML configuration: wrapped and attribute cannot be true at the same time.');
|
|
19
|
+
}
|
|
20
|
+
// Migrate wrapped: true to nodeType: 'element'
|
|
21
|
+
if (obj.xml.wrapped === true) {
|
|
22
|
+
delete obj.xml.wrapped;
|
|
23
|
+
obj.xml.nodeType = 'element';
|
|
24
|
+
}
|
|
25
|
+
// Migrate attribute: true to nodeType: 'attribute'
|
|
26
|
+
if (obj.xml.attribute === true) {
|
|
27
|
+
delete obj.xml.attribute;
|
|
28
|
+
obj.xml.nodeType = 'attribute';
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
// Recursively process all object properties
|
|
32
|
+
for (const key in obj) {
|
|
33
|
+
if (Object.hasOwn(obj, key)) {
|
|
34
|
+
migrateXmlObjects(obj[key]);
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
|
-
}
|
|
29
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Migrate x-tagGroups to kind property on tags
|
|
40
|
+
*/
|
|
30
41
|
function migrateTagGroups(document) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
if (document['x-tagGroups'] && Array.isArray(document['x-tagGroups'])) {
|
|
43
|
+
const tagGroups = document['x-tagGroups'];
|
|
44
|
+
// Ensure tags array exists
|
|
45
|
+
if (!document.tags) {
|
|
46
|
+
document.tags = [];
|
|
47
|
+
}
|
|
48
|
+
// Create a map of tag names to their group information
|
|
49
|
+
const tagGroupMap = new Map();
|
|
50
|
+
for (const group of tagGroups) {
|
|
51
|
+
for (const tagName of group.tags) {
|
|
52
|
+
tagGroupMap.set(tagName, group.name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Update existing tags with kind property based on group name
|
|
56
|
+
if (Array.isArray(document.tags)) {
|
|
57
|
+
for (const tag of document.tags) {
|
|
58
|
+
if (typeof tag === 'object' && tag !== null && 'name' in tag) {
|
|
59
|
+
const groupName = tagGroupMap.get(tag.name);
|
|
60
|
+
if (groupName) {
|
|
61
|
+
// Map group names to kind values
|
|
62
|
+
// This is a simplified mapping - in practice, you might want more sophisticated logic
|
|
63
|
+
if (groupName.toLowerCase().includes('nav') || groupName.toLowerCase().includes('navigation')) {
|
|
64
|
+
tag.kind = 'nav';
|
|
65
|
+
}
|
|
66
|
+
else if (groupName.toLowerCase().includes('audience')) {
|
|
67
|
+
tag.kind = 'audience';
|
|
68
|
+
}
|
|
69
|
+
else if (groupName.toLowerCase().includes('badge')) {
|
|
70
|
+
tag.kind = 'badge';
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Default to nav for unknown group types
|
|
74
|
+
tag.kind = 'nav';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
55
78
|
}
|
|
56
|
-
}
|
|
57
79
|
}
|
|
58
|
-
|
|
80
|
+
// Remove x-tagGroups
|
|
81
|
+
delete document['x-tagGroups'];
|
|
59
82
|
}
|
|
60
|
-
delete document["x-tagGroups"];
|
|
61
|
-
}
|
|
62
83
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Upgrade OpenAPI 3.1 to 3.2
|
|
86
|
+
*
|
|
87
|
+
* @see https://github.com/OAI/OpenAPI-Specification/compare/main...v3.2-dev
|
|
88
|
+
*/
|
|
89
|
+
export function upgradeFromThreeOneToThreeTwo(originalDocument) {
|
|
90
|
+
const document = originalDocument;
|
|
91
|
+
// Version
|
|
92
|
+
if (document !== null &&
|
|
93
|
+
typeof document === 'object' &&
|
|
94
|
+
typeof document.openapi === 'string' &&
|
|
95
|
+
document.openapi?.startsWith('3.1')) {
|
|
96
|
+
document.openapi = '3.2.0';
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Skip if it's something else than 3.1.x
|
|
100
|
+
return document;
|
|
101
|
+
}
|
|
102
|
+
// Migrate x-tagGroups to kind property
|
|
103
|
+
migrateTagGroups(document);
|
|
104
|
+
// Migrate XML object properties
|
|
105
|
+
migrateXmlObjects(document);
|
|
68
106
|
return document;
|
|
69
|
-
}
|
|
70
|
-
migrateTagGroups(document);
|
|
71
|
-
migrateXmlObjects(document);
|
|
72
|
-
return document;
|
|
73
107
|
}
|
|
74
|
-
export {
|
|
75
|
-
upgradeFromThreeOneToThreeTwo
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=upgrade-from-three-one-to-three-two.js.map
|
package/dist/helpers/traverse.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Recursively traverses the content and applies the transform function to each node.
|
|
3
|
+
*/
|
|
4
|
+
export function traverse(content, transform, path = []) {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const [key, value] of Object.entries(content)) {
|
|
7
|
+
const currentPath = [...path, key];
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
result[key] = value.map((item, index) => {
|
|
10
|
+
if (typeof item === 'object' && !Array.isArray(item) && item !== null) {
|
|
11
|
+
return traverse(item, transform, [...currentPath, index.toString()]);
|
|
12
|
+
}
|
|
13
|
+
return item;
|
|
14
|
+
});
|
|
15
|
+
continue;
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
result[key] = traverse(value, transform, currentPath);
|
|
16
|
-
continue;
|
|
17
|
+
if (typeof value === 'object' && value !== null) {
|
|
18
|
+
result[key] = traverse(value, transform, currentPath);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
result[key] = value;
|
|
17
22
|
}
|
|
18
|
-
result
|
|
19
|
-
}
|
|
20
|
-
return transform(result, path);
|
|
23
|
+
return transform(result, path);
|
|
21
24
|
}
|
|
22
|
-
export {
|
|
23
|
-
traverse
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=traverse.js.map
|
package/dist/index.js
CHANGED
package/dist/upgrade.bench.js
CHANGED
|
@@ -1,31 +1,46 @@
|
|
|
1
|
-
import { bench, describe, expect } from
|
|
2
|
-
import { upgradeFromTwoToThree } from
|
|
3
|
-
import { upgrade } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { bench, describe, expect } from 'vitest';
|
|
2
|
+
import { upgradeFromTwoToThree } from './2.0-to-3.0/upgrade-from-two-to-three.js';
|
|
3
|
+
// import { upgrade as upgradeOld } from './slow/upgrade'
|
|
4
|
+
// import { upgradeFromTwoToThree as upgradeFromTwoToThreeOld } from './slow/upgradeFromTwoToThree'
|
|
5
|
+
import { upgrade } from './upgrade.js';
|
|
6
|
+
// Setup the test data
|
|
7
|
+
const STRIPE = await fetch('https://raw.githubusercontent.com/stripe/openapi/refs/heads/master/openapi/spec3.json').then((r) => r.json());
|
|
8
|
+
const PETSTORE = await fetch('https://petstore.swagger.io/v2/swagger.json').then((r) => r.json());
|
|
9
|
+
describe('upgrade', () => {
|
|
10
|
+
describe('Petstore: Swagger 2.0 to OpenAPI 3.0', () => {
|
|
11
|
+
bench('new', () => {
|
|
12
|
+
expect(PETSTORE.swagger).toBe('2.0');
|
|
13
|
+
const result = upgradeFromTwoToThree({ ...PETSTORE });
|
|
14
|
+
expect(result.openapi).toBe('3.0.4');
|
|
15
|
+
});
|
|
16
|
+
// bench('old', () => {
|
|
17
|
+
// expect(PETSTORE.swagger).toBe('2.0')
|
|
18
|
+
// const result = upgradeFromTwoToThreeOld({ ...PETSTORE })
|
|
19
|
+
// expect(result.openapi).toBe('3.0.4')
|
|
20
|
+
// })
|
|
14
21
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
describe('Stripe: OpenAPI 3.0 to 3.1', () => {
|
|
23
|
+
bench('new', () => {
|
|
24
|
+
expect(STRIPE.openapi).toBe('3.0.0');
|
|
25
|
+
const document = upgrade(STRIPE, '3.1');
|
|
26
|
+
expect(document?.openapi).toBe('3.1.1');
|
|
27
|
+
});
|
|
28
|
+
// bench('old', () => {
|
|
29
|
+
// expect(STRIPE.openapi).toBe('3.0.0')
|
|
30
|
+
// const document = upgradeOld(STRIPE)
|
|
31
|
+
// expect(document?.openapi).toBe('3.1.1')
|
|
32
|
+
// })
|
|
21
33
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
describe('Petstore: Swagger 2.0 to OpenAPI 3.1', () => {
|
|
35
|
+
bench('new', () => {
|
|
36
|
+
expect(PETSTORE.swagger).toBe('2.0');
|
|
37
|
+
const document = upgrade(PETSTORE, '3.1');
|
|
38
|
+
expect(document?.openapi).toBe('3.1.1');
|
|
39
|
+
});
|
|
40
|
+
// bench('old', () => {
|
|
41
|
+
// expect(PETSTORE.swagger).toBe('2.0')
|
|
42
|
+
// const document = upgradeOld(PETSTORE)
|
|
43
|
+
// expect(document?.openapi).toBe('3.1.1')
|
|
44
|
+
// })
|
|
28
45
|
});
|
|
29
|
-
});
|
|
30
46
|
});
|
|
31
|
-
//# sourceMappingURL=upgrade.bench.js.map
|
package/dist/upgrade.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { upgradeFromThreeOneToThreeTwo } from
|
|
2
|
-
import { upgradeFromTwoToThree } from
|
|
3
|
-
import { upgradeFromThreeToThreeOne } from
|
|
4
|
-
function upgrade(value, targetVersion) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { upgradeFromThreeOneToThreeTwo } from './3.1-to-3.2/index.js';
|
|
2
|
+
import { upgradeFromTwoToThree } from './2.0-to-3.0/index.js';
|
|
3
|
+
import { upgradeFromThreeToThreeOne } from './3.0-to-3.1/index.js';
|
|
4
|
+
export function upgrade(value, targetVersion) {
|
|
5
|
+
// Swagger 2.0 -> OpenAPI 3.0
|
|
6
|
+
const openapi30 = upgradeFromTwoToThree(value);
|
|
7
|
+
if (targetVersion === '3.0') {
|
|
8
|
+
return openapi30;
|
|
9
|
+
}
|
|
10
|
+
// OpenAPI 3.0 -> OpenAPI 3.1
|
|
11
|
+
const openapi31 = upgradeFromThreeToThreeOne(openapi30);
|
|
12
|
+
if (targetVersion === '3.1') {
|
|
13
|
+
return openapi31;
|
|
14
|
+
}
|
|
15
|
+
// OpenAPI 3.1 -> OpenAPI 3.2
|
|
16
|
+
const openapi32 = upgradeFromThreeOneToThreeTwo(openapi31);
|
|
17
|
+
if (targetVersion === '3.2') {
|
|
18
|
+
return openapi32;
|
|
19
|
+
}
|
|
15
20
|
return openapi32;
|
|
16
|
-
}
|
|
17
|
-
return openapi32;
|
|
18
21
|
}
|
|
19
|
-
export {
|
|
20
|
-
upgrade
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=upgrade.js.map
|