@scalar/openapi-upgrader 0.2.16 → 0.2.17

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,5 +1,14 @@
1
1
  # @scalar/openapi-upgrader
2
2
 
3
+ ## 0.2.17
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10236](https://github.com/scalar/scalar/pull/10236): Omit exclusive bounds without a minimum or maximum when upgrading OpenAPI 3.0 descriptions.
8
+ - [#10236](https://github.com/scalar/scalar/pull/10236): Avoid undefined or inferred media types for base64-encoded data when upgrading OpenAPI 3.0 descriptions.
9
+ - [#10236](https://github.com/scalar/scalar/pull/10236): Fix format conversion for nullable strings when upgrading OpenAPI 3.0 descriptions.
10
+ - [#10236](https://github.com/scalar/scalar/pull/10236): Omit JSON type constraints for raw binary schemas and preserve media metadata when upgrading OpenAPI 3.0 descriptions.
11
+
3
12
  ## 0.2.16
4
13
 
5
14
  ### Patch Changes
@@ -96,18 +96,18 @@ const applyChangesToDocument = (schema, path) => {
96
96
  // Otherwise there is nothing for `nullable` to attach to, so leave the schema untouched.
97
97
  }
98
98
  // 2. Handle exclusiveMinimum and exclusiveMaximum
99
- if (schema.exclusiveMinimum === true) {
99
+ if (schema.exclusiveMinimum === true && schema.minimum !== undefined) {
100
100
  schema.exclusiveMinimum = schema.minimum;
101
101
  delete schema.minimum;
102
102
  }
103
- else if (schema.exclusiveMinimum === false) {
103
+ else if (typeof schema.exclusiveMinimum === 'boolean') {
104
104
  delete schema.exclusiveMinimum;
105
105
  }
106
- if (schema.exclusiveMaximum === true) {
106
+ if (schema.exclusiveMaximum === true && schema.maximum !== undefined) {
107
107
  schema.exclusiveMaximum = schema.maximum;
108
108
  delete schema.maximum;
109
109
  }
110
- else if (schema.exclusiveMaximum === false) {
110
+ else if (typeof schema.exclusiveMaximum === 'boolean') {
111
111
  delete schema.exclusiveMaximum;
112
112
  }
113
113
  // 3. Handle examples
@@ -136,59 +136,27 @@ const applyChangesToDocument = (schema, path) => {
136
136
  }
137
137
  delete schema.example;
138
138
  }
139
- // 4. Handle multipart file uploads
140
- if (schema.type === 'object' && schema.properties !== undefined) {
141
- const parentPath = path?.slice(0, -1);
142
- const isMultipart = parentPath?.some((segment, index) => {
143
- return segment === 'content' && path?.[index + 1] === 'multipart/form-data';
144
- });
145
- if (isMultipart && schema.properties !== null) {
146
- for (const value of Object.values(schema.properties)) {
147
- if (typeof value === 'object' &&
148
- value !== null &&
149
- 'type' in value &&
150
- 'format' in value &&
151
- value.type === 'string' &&
152
- value.format === 'binary') {
153
- value.contentMediaType = 'application/octet-stream';
154
- delete value.format;
155
- }
156
- }
157
- }
158
- }
159
- // 5. Handle binary file uploads
160
- if (path?.includes('content') && path?.includes('application/octet-stream')) {
161
- return {};
162
- }
163
- // 6. Handle older formats
139
+ // 4. Handle older formats
164
140
  const { format: _, ...rest } = schema;
165
- if (schema.type === 'string') {
141
+ if (schema.type === 'string' || (Array.isArray(schema.type) && schema.type.includes('string'))) {
166
142
  if (schema.format === 'binary') {
167
- return {
168
- ...rest,
169
- type: 'string',
170
- contentMediaType: 'application/octet-stream',
171
- };
172
- }
173
- if (schema.format === 'base64') {
174
- return {
175
- ...rest,
176
- type: 'string',
177
- contentEncoding: 'base64',
178
- };
143
+ // Raw binary is outside JSON Schema's types, including nullable type unions.
144
+ const { type: _type, ...binarySchema } = rest;
145
+ const hasMediaType = path?.at(-1) === 'schema' && path.at(-3) === 'content';
146
+ // A whole-body schema already has its media type. Reusable schemas and multipart
147
+ // properties need a fallback, while explicit Encoding Objects remain authoritative.
148
+ return hasMediaType ? binarySchema : { contentMediaType: 'application/octet-stream', ...binarySchema };
179
149
  }
180
- if (schema.format === 'byte') {
181
- const parentPath = path?.slice(0, -1);
182
- const contentMediaType = parentPath?.find((_, index) => path?.[index - 1] === 'content');
150
+ if (schema.format === 'base64' || schema.format === 'byte') {
151
+ // The surrounding media type describes the container, not necessarily the
152
+ // encoded bytes. Preserve an explicit contentMediaType without guessing one.
183
153
  return {
184
154
  ...rest,
185
- type: 'string',
186
155
  contentEncoding: 'base64',
187
- contentMediaType,
188
156
  };
189
157
  }
190
158
  }
191
- // 7. Handle x-webhooks
159
+ // 5. Handle x-webhooks
192
160
  // `x-webhooks` is a document-root extension, so only rename it there. Anywhere else (a schema
193
161
  // property, an example) a key named `x-webhooks` is unrelated and must be left alone.
194
162
  if (schema['x-webhooks'] !== undefined && (path === undefined || path.length === 0)) {
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "openapi 3.0",
21
21
  "openapi 3.1"
22
22
  ],
23
- "version": "0.2.16",
23
+ "version": "0.2.17",
24
24
  "engines": {
25
25
  "node": ">=22"
26
26
  },
@@ -71,12 +71,12 @@
71
71
  },
72
72
  "sideEffects": false,
73
73
  "dependencies": {
74
- "@scalar/openapi-types": "0.9.6",
75
- "@scalar/helpers": "0.12.0"
74
+ "@scalar/helpers": "0.12.0",
75
+ "@scalar/openapi-types": "0.9.6"
76
76
  },
77
77
  "devDependencies": {
78
- "vite": "8.1.5",
79
- "@scalar/types": "0.20.0"
78
+ "@scalar/types": "0.20.0",
79
+ "vite": "8.1.5"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",