@scalar/openapi-upgrader 0.2.15 → 0.2.16

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,16 @@
1
1
  # @scalar/openapi-upgrader
2
2
 
3
+ ## 0.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - [#9666](https://github.com/scalar/scalar/pull/9666): Only normalize OpenAPI Reference Objects during bundling, never Schema Objects. `normalizeRefs` used to strip every sibling except `$ref` on any node outside `components/schemas`, which also hit inline schemas. In JSON Schema 2020-12 a `$ref` may legally carry sibling keywords — for example a `$defs`/`$dynamicAnchor` binding that specializes a generic template like `Paginated<T>` — and such schemas appear inline anywhere a schema is allowed (a response's `content.<media>.schema`, an `allOf` branch, …). Dropping those siblings discarded the binding, leaving `$dynamicRef` to resolve to the template's empty fallback and rendering an empty array (for example the `data` array of `GET /planets` in the Scalar Galaxy). Reference Objects are still normalized as before. A new `@scalar/helpers/openapi/is-schema-path` helper detects schema positions.
8
+ - [#10140](https://github.com/scalar/scalar/pull/10140): Replace redundant type assertions with compiler-checked annotations, typed accumulators, and existing guards across helpers, API conversion, request handling, and schema rendering.
9
+
10
+ Narrow DOM elements and caught errors before accessing their properties. Correct header lookup to include missing values and handle them during PowerShell snippet generation.
11
+
12
+ Validate release-note provider responses, represent unresolved references and absent groups in helper return types, and require narrowing merged object values. Preserve AsyncAPI broker credentials separately from HTTP authentication schemes.
13
+
3
14
  ## 0.2.15
4
15
 
5
16
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA8LxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAoczE"}
1
+ {"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA2LxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CA4bzE"}
@@ -1,3 +1,4 @@
1
+ import { isObjectLike } from '@scalar/helpers/object/is-object';
1
2
  import { traverse } from '../helpers/traverse.js';
2
3
  const DEFAULT_MEDIA_TYPE = 'application/json';
3
4
  /** Extracts and removes x-example and x-examples extensions from an object */
@@ -24,7 +25,7 @@ function isNamedExamplesCollection(value) {
24
25
  }
25
26
  /** Checks if a schema is empty (no meaningful properties defined) */
26
27
  function isEmptySchema(schema) {
27
- if (typeof schema !== 'object' || schema === null) {
28
+ if (!isObjectLike(schema)) {
28
29
  return true;
29
30
  }
30
31
  const s = schema;
@@ -73,14 +74,14 @@ function removeEmptySchemaOnlyContentEntries(content) {
73
74
  const keys = Object.keys(content);
74
75
  const hasEntryWithExample = keys.some((key) => {
75
76
  const entry = content[key];
76
- return entry?.example !== undefined || entry?.examples !== undefined;
77
+ return isObjectLike(entry) && (entry.example !== undefined || entry.examples !== undefined);
77
78
  });
78
79
  if (!hasEntryWithExample) {
79
80
  return;
80
81
  }
81
82
  for (const key of keys) {
82
83
  const entry = content[key];
83
- if (!entry)
84
+ if (!isObjectLike(entry))
84
85
  continue;
85
86
  const hasExample = entry.example !== undefined || entry.examples !== undefined;
86
87
  const hasOnlySchema = entry.schema !== undefined && !hasExample && Object.keys(entry).length === 1;
@@ -213,7 +214,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
213
214
  if (!schemaName) {
214
215
  return schema;
215
216
  }
216
- const param = document.parameters && typeof document.parameters === 'object' && schemaName in document.parameters
217
+ const param = isObjectLike(document.parameters) && schemaName in document.parameters
217
218
  ? document.parameters[schemaName]
218
219
  : undefined;
219
220
  if (param && typeof param === 'object' && 'in' in param && (param.in === 'body' || param.in === 'formData')) {
@@ -228,9 +229,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
228
229
  document.components ??= {};
229
230
  const params = {};
230
231
  const bodyParams = {};
231
- const parameters = document.parameters && typeof document.parameters === 'object'
232
- ? document.parameters
233
- : {};
232
+ const parameters = isObjectLike(document.parameters) ? document.parameters : {};
234
233
  for (const [name, param] of Object.entries(parameters)) {
235
234
  if (param && typeof param === 'object') {
236
235
  // Handle reference objects
@@ -275,7 +274,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
275
274
  const migratedResponses = {};
276
275
  const responses = document.responses;
277
276
  for (const [name, response] of Object.entries(responses)) {
278
- if (response && typeof response === 'object') {
277
+ if (isObjectLike(response)) {
279
278
  // Handle reference objects
280
279
  if ('$ref' in response) {
281
280
  migratedResponses[name] = response;
@@ -335,7 +334,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
335
334
  removeEmptySchemaOnlyContentEntries(responseObj.content);
336
335
  }
337
336
  // Transform headers if present
338
- if (responseObj.headers && typeof responseObj.headers === 'object') {
337
+ if (isObjectLike(responseObj.headers)) {
339
338
  responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
340
339
  if (header && typeof header === 'object') {
341
340
  return {
@@ -360,9 +359,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
360
359
  if (typeof document.paths === 'object') {
361
360
  for (const path in document.paths) {
362
361
  if (Object.hasOwn(document.paths, path)) {
363
- const pathItem = document.paths && typeof document.paths === 'object' && path in document.paths
364
- ? document.paths[path]
365
- : undefined;
362
+ const pathItem = isObjectLike(document.paths) && path in document.paths ? document.paths[path] : undefined;
366
363
  if (!pathItem || typeof pathItem !== 'object') {
367
364
  continue;
368
365
  }
@@ -657,8 +654,7 @@ function getParameterSerializationStyle(parameter) {
657
654
  return {};
658
655
  }
659
656
  const collectionFormat = parameter.collectionFormat ?? 'csv';
660
- if (parameter.in in serializationStyles &&
661
- collectionFormat in serializationStyles[parameter.in]) {
657
+ if (parameter.in in serializationStyles && collectionFormat in serializationStyles[parameter.in]) {
662
658
  return serializationStyles[parameter.in][collectionFormat];
663
659
  }
664
660
  return {};
@@ -1,7 +1,5 @@
1
1
  import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
2
  import type { UnknownObject } from '@scalar/types/utils';
3
- /** Determine if the current path is within a schema - optimized version */
4
- export declare function isSchemaPath(path: string[] | undefined): boolean;
5
3
  /**
6
4
  * Upgrade from OpenAPI 3.0.x to 3.1.1
7
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgBxD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAsBhE;AA8DD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE"}
1
+ {"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgExD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE"}
@@ -1,35 +1,5 @@
1
+ import { isSchemaPath } from '@scalar/helpers/openapi/is-schema-path';
1
2
  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',
12
- ]);
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
- }
31
- return false;
32
- }
33
3
  // Segments whose value is a map of *named* subschemas. Keys inside these maps are
34
4
  // arbitrary names (property names, definition names), never schema keywords.
35
5
  const NAMED_SCHEMA_MAP_SEGMENTS = new Set(['properties', 'patternProperties', '$defs', 'definitions']);
@@ -55,7 +55,7 @@ function migrateTagGroups(document) {
55
55
  // Update existing tags with kind property based on group name
56
56
  if (Array.isArray(document.tags)) {
57
57
  for (const tag of document.tags) {
58
- if (typeof tag === 'object' && tag !== null && 'name' in tag) {
58
+ if (typeof tag === 'object' && tag !== null && 'name' in tag && typeof tag.name === 'string') {
59
59
  const groupName = tagGroupMap.get(tag.name);
60
60
  if (groupName) {
61
61
  // Map group names to kind values
@@ -1 +1 @@
1
- {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/helpers/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,aAAa,EACrE,IAAI,GAAE,MAAM,EAAO,iBA6BpB"}
1
+ {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/helpers/traverse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,aAAa,EACrE,IAAI,GAAE,MAAM,EAAO,iBA6BpB"}
@@ -1,3 +1,4 @@
1
+ import { isObjectLike } from '@scalar/helpers/object/is-object';
1
2
  /**
2
3
  * Recursively traverses the content and applies the transform function to each node.
3
4
  */
@@ -14,7 +15,7 @@ export function traverse(content, transform, path = []) {
14
15
  });
15
16
  continue;
16
17
  }
17
- if (typeof value === 'object' && value !== null) {
18
+ if (isObjectLike(value)) {
18
19
  result[key] = traverse(value, transform, currentPath);
19
20
  continue;
20
21
  }
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "openapi 3.0",
21
21
  "openapi 3.1"
22
22
  ],
23
- "version": "0.2.15",
23
+ "version": "0.2.16",
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.5"
74
+ "@scalar/openapi-types": "0.9.6",
75
+ "@scalar/helpers": "0.12.0"
75
76
  },
76
77
  "devDependencies": {
77
78
  "vite": "8.1.5",
78
- "@scalar/helpers": "0.11.1",
79
- "@scalar/types": "0.18.2"
79
+ "@scalar/types": "0.20.0"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",