@scalar/openapi-upgrader 0.4.10 → 0.5.0

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,21 @@
1
1
  # @scalar/openapi-upgrader
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#10997](https://github.com/scalar/scalar/pull/10997): Upgrade referenced OpenAPI 2.0 and 3.0 resources before bundling, including bare fragments interpreted in their owning API description's dialect and media types. Preserve authored reference targets when schemas and parameters move, and retain their context through lazy loading, serialization, and export.
8
+
9
+ Add JSON Magic resource and target lifecycle hooks and the typed `upgradeFragment` API. Headerless external resources are traversed through referenced subtrees, including when reached from OpenAPI 3.1/3.2 descriptions. Exports retain compact `x-scalar-upgrade` bookkeeping only when lazy external references still need the original dialect, relocation mappings, or media types.
10
+
11
+ Resources already stored in an input bundle's `x-ext` keep their existing layout so saved references remain valid. Legacy keywords in those stored resources, including OpenAPI 2.0 schema `x-nullable` and `type: file`, deliberately remain unconverted; newly loaded legacy resources are upgraded.
12
+
13
+ ## 0.4.11
14
+
15
+ ### Patch Changes
16
+
17
+ - [#11004](https://github.com/scalar/scalar/pull/11004): Preserve package output paths and application aliases when building with TypeScript 6.
18
+
3
19
  ## 0.4.10
4
20
 
5
21
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { OpenAPIV3 } from '@scalar/openapi-types';
1
+ import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types';
2
2
  import type { UnknownObject } from '@scalar/types/utils';
3
3
  /**
4
4
  * Upgrade Swagger 2.0 to OpenAPI 3.0
@@ -6,4 +6,25 @@ import type { UnknownObject } from '@scalar/types/utils';
6
6
  * https://swagger.io/blog/news/whats-new-in-openapi-3-0/
7
7
  */
8
8
  export declare function upgradeFromTwoToThree(originalSpecification: UnknownObject): UnknownObject | OpenAPIV3.Document<{}>;
9
+ /**
10
+ * Converts Swagger discriminator and nullability fields to their OpenAPI 3.0 forms.
11
+ * Visit only OpenAPI 2.0 subschema keywords so example/default values and custom extensions remain user data.
12
+ * Set recursive to false when the caller already owns schema traversal.
13
+ */
14
+ export declare const migrateSchema: (schema: unknown, recursive?: boolean) => void;
15
+ /** Schema-valued fields moved from a 2.0 non-body parameter or header into its schema. */
16
+ export declare const parameterSchemaFields: readonly ["type", "format", "default", "items", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "minLength", "pattern", "maxItems", "minItems", "uniqueItems", "enum", "multipleOf", "x-nullable"];
17
+ /** Convert a 2.0 non-body parameter in place, moving validation fields into its schema. */
18
+ export declare function transformParameterObject(parameter: OpenAPIV2.ParameterObject | OpenAPIV2.ReferenceObject): OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject;
19
+ /**
20
+ * Transform OpenAPI 2.0 response header to OpenAPI 3.0 format.
21
+ * Response headers do not have "in", "name", "style", or "explode" properties.
22
+ */
23
+ export declare function transformResponseHeader(header: OpenAPIV2.HeaderObject | OpenAPIV2.ReferenceObject): OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject;
24
+ /** Convert a 2.0 body parameter in place using the owning operation's effective request media types. */
25
+ export declare function migrateBodyParameter(bodyParameter: OpenAPIV2.ParameterObject, consumes: string[]): OpenAPIV3.RequestBodyObject;
26
+ /** Combine 2.0 form parameters without modifying them, using the effective request media types. */
27
+ export declare function migrateFormDataParameter(parameters: OpenAPIV2.ParameterObject[], consumes?: string[] | undefined): OpenAPIV3.RequestBodyObject;
28
+ /** Convert a 2.0 response in place using the owning operation's effective response media types. */
29
+ export declare const transformResponseObject: (responseObj: UnknownObject, produces: string[]) => UnknownObject;
9
30
  //# sourceMappingURL=upgrade-from-two-to-three.d.ts.map
@@ -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":"AAGA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAmMxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAsfzE"}
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":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAmMxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAiXzE;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,OAAO,EAAE,mBAAgB,KAAG,IA0CjE,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,qBAAqB,+NAkBxB,CAAA;AA0BV,2FAA2F;AAC3F,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,CAAC,eAAe,GAAG,SAAS,CAAC,eAAe,GAC/D,SAAS,CAAC,eAAe,GAAG,SAAS,CAAC,eAAe,CAuDvD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,GACzD,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,CAmBpD;AAuFD,wGAAwG;AACxG,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,SAAS,CAAC,eAAe,EACxC,QAAQ,EAAE,MAAM,EAAE,GACjB,SAAS,CAAC,iBAAiB,CA8E7B;AAED,mGAAmG;AACnG,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,SAAS,CAAC,eAAe,EAAE,EACvC,QAAQ,GAAE,MAAM,EAAE,GAAG,SAAmC,GACvD,SAAS,CAAC,iBAAiB,CAwD7B;AA6GD,mGAAmG;AACnG,eAAO,MAAM,uBAAuB,GAAI,aAAa,aAAa,EAAE,UAAU,MAAM,EAAE,KAAG,aAwExF,CAAA"}
@@ -310,71 +310,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
310
310
  }
311
311
  else {
312
312
  // Transform the response object
313
- const responseObj = response;
314
- const produces = document.produces ?? [DEFAULT_MEDIA_TYPE];
315
- // Transform schema to content
316
- if (responseObj.schema) {
317
- migrateSchema(responseObj.schema);
318
- if (typeof responseObj.content !== 'object') {
319
- responseObj.content = {};
320
- }
321
- for (const type of produces) {
322
- ;
323
- responseObj.content[type] = {
324
- schema: responseObj.schema,
325
- };
326
- }
327
- delete responseObj.schema;
328
- }
329
- // Transform examples from Swagger 2.0 to OpenAPI 3.0 format
330
- if (responseObj.examples && typeof responseObj.examples === 'object') {
331
- if (typeof responseObj.content !== 'object') {
332
- responseObj.content = {};
333
- }
334
- const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
335
- for (const [key, exampleValue] of Object.entries(responseObj.examples)) {
336
- // Media-type keys (e.g. application/json) go to content[key]; named example keys go to content[defaultMediaType].examples[key].
337
- if (isMediaTypeKey(key, produces)) {
338
- if (typeof responseObj.content[key] !== 'object') {
339
- ;
340
- responseObj.content[key] = {};
341
- }
342
- ;
343
- responseObj.content[key].example =
344
- exampleValue;
345
- }
346
- else {
347
- if (typeof responseObj.content[defaultMediaType] !== 'object') {
348
- ;
349
- responseObj.content[defaultMediaType] = {};
350
- }
351
- const mediaEntry = responseObj.content[defaultMediaType];
352
- if (typeof mediaEntry.examples !== 'object') {
353
- mediaEntry.examples = {};
354
- }
355
- ;
356
- mediaEntry.examples[key] =
357
- wrapAsExampleObject(exampleValue);
358
- }
359
- }
360
- delete responseObj.examples;
361
- }
362
- // Clean up content entries that only have an empty schema when other entries have examples
363
- if (responseObj.content && typeof responseObj.content === 'object') {
364
- removeEmptySchemaOnlyContentEntries(responseObj.content);
365
- }
366
- // Transform headers if present
367
- if (isObjectLike(responseObj.headers)) {
368
- responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
369
- if (header && typeof header === 'object') {
370
- return {
371
- [headerName]: transformResponseHeader(header),
372
- ...acc,
373
- };
374
- }
375
- return acc;
376
- }, {});
377
- }
313
+ const responseObj = transformResponseObject(response, document.produces ?? [DEFAULT_MEDIA_TYPE]);
378
314
  migratedResponses[name] = responseObj;
379
315
  }
380
316
  }
@@ -439,65 +375,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
439
375
  if (operationItem.responses) {
440
376
  for (const response in operationItem.responses) {
441
377
  if (Object.hasOwn(operationItem.responses, response)) {
442
- const responseItem = operationItem.responses[response];
443
- if (responseItem.headers && typeof responseItem.headers === 'object') {
444
- responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {
445
- if (header && typeof header === 'object') {
446
- return {
447
- [name]: transformResponseHeader(header),
448
- ...acc,
449
- };
450
- }
451
- return acc;
452
- }, {});
453
- }
454
- if (responseItem.schema) {
455
- migrateSchema(responseItem.schema);
456
- const produces = operationItem.produces ?? document.produces ?? [DEFAULT_MEDIA_TYPE];
457
- if (typeof responseItem.content !== 'object') {
458
- responseItem.content = {};
459
- }
460
- for (const type of produces) {
461
- responseItem.content[type] = {
462
- schema: responseItem.schema,
463
- };
464
- }
465
- delete responseItem.schema;
466
- }
467
- // Transform response examples from Swagger 2.0 to OpenAPI 3.0 format
468
- // In Swagger 2.0, examples are at response level: examples: { DEFAULT_MEDIA_TYPE: {...} } or named: { 'Example': {...} }
469
- // In OpenAPI 3.0, examples move inside content: content: { DEFAULT_MEDIA_TYPE: { example: {...} } } or examples: { Example: { value: {...} } }
470
- if (responseItem.examples && typeof responseItem.examples === 'object') {
471
- if (typeof responseItem.content !== 'object') {
472
- responseItem.content = {};
473
- }
474
- const produces = operationItem.produces ?? document.produces ?? [DEFAULT_MEDIA_TYPE];
475
- const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
476
- for (const [key, exampleValue] of Object.entries(responseItem.examples)) {
477
- // Media-type keys (e.g. application/json) go to content[key]; named example keys go to content[defaultMediaType].examples[key].
478
- if (isMediaTypeKey(key, produces)) {
479
- if (typeof responseItem.content[key] !== 'object') {
480
- responseItem.content[key] = {};
481
- }
482
- responseItem.content[key].example = exampleValue;
483
- }
484
- else {
485
- if (typeof responseItem.content[defaultMediaType] !== 'object') {
486
- responseItem.content[defaultMediaType] = {};
487
- }
488
- const mediaEntry = responseItem.content[defaultMediaType];
489
- if (typeof mediaEntry.examples !== 'object') {
490
- mediaEntry.examples = {};
491
- }
492
- mediaEntry.examples[key] = wrapAsExampleObject(exampleValue);
493
- }
494
- }
495
- delete responseItem.examples;
496
- }
497
- // Clean up content entries that only have an empty schema when other entries have examples
498
- if (responseItem.content && typeof responseItem.content === 'object') {
499
- removeEmptySchemaOnlyContentEntries(responseItem.content);
500
- }
378
+ operationItem.responses[response] = transformResponseObject(operationItem.responses[response], operationItem.produces ?? document.produces ?? [DEFAULT_MEDIA_TYPE]);
501
379
  }
502
380
  }
503
381
  }
@@ -575,8 +453,9 @@ export function upgradeFromTwoToThree(originalSpecification) {
575
453
  /**
576
454
  * Converts Swagger discriminator and nullability fields to their OpenAPI 3.0 forms.
577
455
  * Visit only OpenAPI 2.0 subschema keywords so example/default values and custom extensions remain user data.
456
+ * Set recursive to false when the caller already owns schema traversal.
578
457
  */
579
- const migrateSchema = (schema) => {
458
+ export const migrateSchema = (schema, recursive = true) => {
580
459
  if (!isObjectLike(schema)) {
581
460
  return;
582
461
  }
@@ -598,6 +477,9 @@ const migrateSchema = (schema) => {
598
477
  }
599
478
  delete schema['x-nullable'];
600
479
  }
480
+ if (!recursive) {
481
+ return;
482
+ }
601
483
  if (isObjectLike(schema.properties)) {
602
484
  for (const property of Object.values(schema.properties)) {
603
485
  migrateSchema(property);
@@ -611,27 +493,28 @@ const migrateSchema = (schema) => {
611
493
  }
612
494
  }
613
495
  };
496
+ /** Schema-valued fields moved from a 2.0 non-body parameter or header into its schema. */
497
+ export const parameterSchemaFields = [
498
+ 'type',
499
+ 'format',
500
+ 'default',
501
+ 'items',
502
+ 'maximum',
503
+ 'exclusiveMaximum',
504
+ 'minimum',
505
+ 'exclusiveMinimum',
506
+ 'maxLength',
507
+ 'minLength',
508
+ 'pattern',
509
+ 'maxItems',
510
+ 'minItems',
511
+ 'uniqueItems',
512
+ 'enum',
513
+ 'multipleOf',
514
+ 'x-nullable',
515
+ ];
614
516
  function transformItemsObject(obj) {
615
- const schemaProperties = [
616
- 'type',
617
- 'format',
618
- 'default',
619
- 'items',
620
- 'maximum',
621
- 'exclusiveMaximum',
622
- 'minimum',
623
- 'exclusiveMinimum',
624
- 'maxLength',
625
- 'minLength',
626
- 'pattern',
627
- 'maxItems',
628
- 'minItems',
629
- 'uniqueItems',
630
- 'enum',
631
- 'multipleOf',
632
- 'x-nullable',
633
- ];
634
- const schema = schemaProperties.reduce((acc, property) => {
517
+ const schema = parameterSchemaFields.reduce((acc, property) => {
635
518
  if (Object.hasOwn(obj, property)) {
636
519
  acc[property] = obj[property];
637
520
  delete obj[property];
@@ -650,7 +533,8 @@ function getParameterLocation(location) {
650
533
  }
651
534
  return location;
652
535
  }
653
- function transformParameterObject(parameter) {
536
+ /** Convert a 2.0 non-body parameter in place, moving validation fields into its schema. */
537
+ export function transformParameterObject(parameter) {
654
538
  if (Object.hasOwn(parameter, '$ref') && typeof parameter.$ref === 'string') {
655
539
  return {
656
540
  $ref: parameter.$ref,
@@ -700,7 +584,7 @@ function transformParameterObject(parameter) {
700
584
  * Transform OpenAPI 2.0 response header to OpenAPI 3.0 format.
701
585
  * Response headers do not have "in", "name", "style", or "explode" properties.
702
586
  */
703
- function transformResponseHeader(header) {
587
+ export function transformResponseHeader(header) {
704
588
  if (Object.hasOwn(header, '$ref') && typeof header.$ref === 'string') {
705
589
  return {
706
590
  $ref: header.$ref,
@@ -780,7 +664,8 @@ function getFormDataEncoding(parameter) {
780
664
  }
781
665
  return encoding;
782
666
  }
783
- function migrateBodyParameter(bodyParameter, consumes) {
667
+ /** Convert a 2.0 body parameter in place using the owning operation's effective request media types. */
668
+ export function migrateBodyParameter(bodyParameter, consumes) {
784
669
  // Extract x-example and x-examples before deleting other properties
785
670
  // @see https://redocly.com/docs-legacy/api-reference-docs/specification-extensions/x-examples
786
671
  const { xExample, xExamples } = extractXExampleExtensions(bodyParameter);
@@ -843,7 +728,8 @@ function migrateBodyParameter(bodyParameter, consumes) {
843
728
  }
844
729
  return requestBodyObject;
845
730
  }
846
- function migrateFormDataParameter(parameters, consumes = ['multipart/form-data']) {
731
+ /** Combine 2.0 form parameters without modifying them, using the effective request media types. */
732
+ export function migrateFormDataParameter(parameters, consumes = ['multipart/form-data']) {
847
733
  const requestBodyObject = {
848
734
  content: {},
849
735
  };
@@ -973,3 +859,71 @@ function migrateParameters(parameters, consumes, sharedBodyParameters, globalCon
973
859
  }
974
860
  return result;
975
861
  }
862
+ /** Convert a 2.0 response in place using the owning operation's effective response media types. */
863
+ export const transformResponseObject = (responseObj, produces) => {
864
+ if (typeof responseObj.$ref === 'string') {
865
+ return responseObj;
866
+ }
867
+ // Transform schema to content
868
+ if (responseObj.schema) {
869
+ migrateSchema(responseObj.schema);
870
+ if (typeof responseObj.content !== 'object') {
871
+ responseObj.content = {};
872
+ }
873
+ for (const type of produces) {
874
+ ;
875
+ responseObj.content[type] = {
876
+ schema: responseObj.schema,
877
+ };
878
+ }
879
+ delete responseObj.schema;
880
+ }
881
+ // Transform examples from Swagger 2.0 to OpenAPI 3.0 format
882
+ if (responseObj.examples && typeof responseObj.examples === 'object') {
883
+ if (typeof responseObj.content !== 'object') {
884
+ responseObj.content = {};
885
+ }
886
+ const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
887
+ for (const [key, exampleValue] of Object.entries(responseObj.examples)) {
888
+ // Media-type keys (e.g. application/json) go to content[key]; named example keys go to content[defaultMediaType].examples[key].
889
+ if (isMediaTypeKey(key, produces)) {
890
+ if (typeof responseObj.content[key] !== 'object') {
891
+ ;
892
+ responseObj.content[key] = {};
893
+ }
894
+ ;
895
+ responseObj.content[key].example = exampleValue;
896
+ }
897
+ else {
898
+ if (typeof responseObj.content[defaultMediaType] !== 'object') {
899
+ ;
900
+ responseObj.content[defaultMediaType] = {};
901
+ }
902
+ const mediaEntry = responseObj.content[defaultMediaType];
903
+ if (typeof mediaEntry.examples !== 'object') {
904
+ mediaEntry.examples = {};
905
+ }
906
+ ;
907
+ mediaEntry.examples[key] = wrapAsExampleObject(exampleValue);
908
+ }
909
+ }
910
+ delete responseObj.examples;
911
+ }
912
+ // Clean up content entries that only have an empty schema when other entries have examples
913
+ if (responseObj.content && typeof responseObj.content === 'object') {
914
+ removeEmptySchemaOnlyContentEntries(responseObj.content);
915
+ }
916
+ // Transform headers if present
917
+ if (isObjectLike(responseObj.headers)) {
918
+ responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
919
+ if (header && typeof header === 'object') {
920
+ return {
921
+ [headerName]: transformResponseHeader(header),
922
+ ...acc,
923
+ };
924
+ }
925
+ return acc;
926
+ }, {});
927
+ }
928
+ return responseObj;
929
+ };
@@ -18,4 +18,6 @@ export declare function upgradeFromThreeToThreeOne(originalContent: UnknownObjec
18
18
  [customExtension: `x-${string}`]: any;
19
19
  [key: string]: any;
20
20
  });
21
+ /** Apply one migration step to a node at its semantic OpenAPI location. */
22
+ export declare const applyChangesToDocument: (schema: UnknownObject, path?: string[]) => UnknownObject;
21
23
  //# sourceMappingURL=upgrade-from-three-to-three-one.d.ts.map
@@ -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":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAmDxD;;;;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;AAmDxD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE;AAED,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,GAAI,QAAQ,aAAa,EAAE,OAAO,MAAM,EAAE,kBAqH5E,CAAA"}
@@ -56,7 +56,8 @@ export function upgradeFromThreeToThreeOne(originalContent) {
56
56
  content = traverse(content, applyChangesToDocument);
57
57
  return content;
58
58
  }
59
- const applyChangesToDocument = (schema, path) => {
59
+ /** Apply one migration step to a node at its semantic OpenAPI location. */
60
+ export const applyChangesToDocument = (schema, path) => {
60
61
  // 0. Bail out inside data values (example, default, const, enum). These hold user data, not a
61
62
  // schema, so none of the schema transforms below apply and running them would corrupt the data.
62
63
  if (isInsideDataValue(path, '3.0')) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { type UpgradeOptions, type UpgradeResult, upgrade } from './upgrade.js';
2
+ export { type FragmentKind, type FragmentLocation, type FragmentUpgradeOptions, type FragmentUpgradeResult, upgradeFragment, } from './upgrade-fragment.js';
2
3
  export { UpgradeIncompatibilityError } from './upgrade-incompatibility-error.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { upgrade } from './upgrade.js';
2
+ export { upgradeFragment, } from './upgrade-fragment.js';
2
3
  export { UpgradeIncompatibilityError } from './upgrade-incompatibility-error.js';
@@ -0,0 +1,44 @@
1
+ /** The OpenAPI object a reference expects, independent of its storage location. */
2
+ export type FragmentKind = 'document' | 'schema' | 'parameter' | 'header' | 'response' | 'path-item' | 'operation' | 'request-body' | 'callback';
3
+ /** Original and converted JSON Pointer segments, relative to the fragment root.
4
+ * Apply the longest source prefix to authored pointers; the first output is canonical when media types copy a schema.
5
+ * Generated bundle pointers and already converted discriminator mappings must not be remapped.
6
+ */
7
+ export type FragmentLocation = {
8
+ source: readonly string[];
9
+ output: readonly string[];
10
+ };
11
+ /** Context required to interpret a fragment that has no version header. */
12
+ export type FragmentUpgradeOptions = {
13
+ from: '2.0' | '3.0';
14
+ to: '3.1';
15
+ kind: FragmentKind;
16
+ consumes?: readonly string[];
17
+ produces?: readonly string[];
18
+ /**
19
+ * Resolve original 2.0 parameter aliases before choosing parameters or requestBody.
20
+ * Return source content with nested refs rebased to the consuming resource. Failed lookups
21
+ * retain the authored reference. Without this callback, referenced body/form parameters stay in parameters.
22
+ */
23
+ resolveSource?: (ref: string) => Promise<unknown>;
24
+ };
25
+ /** Converted content and the locations of original reference targets. */
26
+ export type FragmentUpgradeResult = {
27
+ value: unknown;
28
+ /** Changed locations in traversal order. Unchanged descendants inherit their parent mapping. */
29
+ locations: FragmentLocation[];
30
+ /** Effective operation media types, needed when later loading bare external fragments. */
31
+ contexts: {
32
+ path: readonly string[];
33
+ consumes: readonly string[];
34
+ produces: readonly string[];
35
+ }[];
36
+ };
37
+ /**
38
+ * Upgrade a complete document or a typed fragment without inventing a wrapper document.
39
+ * Returns a copy; literal examples and extension payloads remain data.
40
+ * Authored references retain source pointers: use locations to resolve them against converted content.
41
+ * A standalone schema resource with $schema retains its declared dialect.
42
+ */
43
+ export declare const upgradeFragment: (input: unknown, options: FragmentUpgradeOptions) => Promise<FragmentUpgradeResult>;
44
+ //# sourceMappingURL=upgrade-fragment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-fragment.d.ts","sourceRoot":"","sources":["../src/upgrade-fragment.ts"],"names":[],"mappings":"AAkBA,mFAAmF;AACnF,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,UAAU,GACV,WAAW,GACX,WAAW,GACX,cAAc,GACd,UAAU,CAAA;AAEd;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAA;AAEvF,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IACnB,EAAE,EAAE,KAAK,CAAA;IACT,IAAI,EAAE,YAAY,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAClD,CAAA;AAED,yEAAyE;AACzE,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,OAAO,CAAA;IACd,gGAAgG;IAChG,SAAS,EAAE,gBAAgB,EAAE,CAAA;IAC7B,0FAA0F;IAC1F,QAAQ,EAAE;QAAE,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;CAClG,CAAA;AAsCD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,OAAO,EACd,SAAS,sBAAsB,KAC9B,OAAO,CAAC,qBAAqB,CA+c/B,CAAA"}
@@ -0,0 +1,461 @@
1
+ import { HTTP_METHODS } from '@scalar/helpers/http/http-methods';
2
+ import { isObject } from '@scalar/helpers/object/is-object';
3
+ import { migrateDiscriminatorMappings } from './2.0-to-3.0/migrate-discriminator-mappings.js';
4
+ import { migrateBodyParameter, migrateFormDataParameter, migrateSchema, parameterSchemaFields, transformParameterObject, transformResponseHeader, transformResponseObject, upgradeFromTwoToThree, } from './2.0-to-3.0/upgrade-from-two-to-three.js';
5
+ import { applyChangesToDocument } from './3.0-to-3.1/upgrade-from-three-to-three-one.js';
6
+ const schemaMaps = new Set(['properties', 'patternProperties', '$defs', 'definitions', 'dependentSchemas']);
7
+ const schemaChildren = new Set([
8
+ 'items',
9
+ 'additionalProperties',
10
+ 'unevaluatedProperties',
11
+ 'unevaluatedItems',
12
+ 'contains',
13
+ 'contentSchema',
14
+ 'propertyNames',
15
+ 'not',
16
+ 'if',
17
+ 'then',
18
+ 'else',
19
+ 'allOf',
20
+ 'anyOf',
21
+ 'oneOf',
22
+ 'prefixItems',
23
+ ]);
24
+ /** Define authored keys without invoking inherited setters. */
25
+ const setOwn = (target, key, value) => {
26
+ Object.defineProperty(target, key, { value, enumerable: true, configurable: true, writable: true });
27
+ };
28
+ /**
29
+ * Upgrade a complete document or a typed fragment without inventing a wrapper document.
30
+ * Returns a copy; literal examples and extension payloads remain data.
31
+ * Authored references retain source pointers: use locations to resolve them against converted content.
32
+ * A standalone schema resource with $schema retains its declared dialect.
33
+ */
34
+ export const upgradeFragment = async (input, options) => {
35
+ const locations = [];
36
+ const contexts = [];
37
+ const v2 = options.from === '2.0';
38
+ const resolvedParameters = new Map();
39
+ const resolveParameter = (parameter) => {
40
+ if (!v2 || !isObject(parameter) || typeof parameter.$ref !== 'string' || !options.resolveSource) {
41
+ return Promise.resolve(parameter);
42
+ }
43
+ const cached = resolvedParameters.get(parameter.$ref);
44
+ if (cached) {
45
+ return cached;
46
+ }
47
+ const resolved = Promise.resolve()
48
+ .then(() => options.resolveSource?.(parameter.$ref))
49
+ .then((value) => value ?? parameter)
50
+ .catch(() => parameter);
51
+ resolvedParameters.set(parameter.$ref, resolved);
52
+ return resolved;
53
+ };
54
+ const recordedSources = new Set();
55
+ const remember = (source, output) => {
56
+ const key = JSON.stringify(source);
57
+ // Reused schemas can have several destinations. Keep the first, including unchanged ones.
58
+ if (recordedSources.has(key)) {
59
+ return;
60
+ }
61
+ recordedSources.add(key);
62
+ if (source.length !== output.length || source.some((part, index) => part !== output[index])) {
63
+ locations.push({ source, output });
64
+ }
65
+ };
66
+ const rememberFormFields = (parameter, source, output, mediaTypes) => {
67
+ for (const media of mediaTypes) {
68
+ const property = [...output, 'content', media, 'schema', 'properties', String(parameter.name)];
69
+ for (const key of parameterSchemaFields) {
70
+ if (Object.hasOwn(parameter, key)) {
71
+ remember([...source, key], [...property, key]);
72
+ }
73
+ }
74
+ }
75
+ };
76
+ const visit = async (value, { kind, source, output, consumes, produces, semanticPath, parameterSources, generated }) => {
77
+ if (!generated) {
78
+ remember(source, output);
79
+ }
80
+ if (!isObject(value)) {
81
+ return value;
82
+ }
83
+ // A declared JSON Schema dialect must not be interpreted as an OpenAPI 3.0 schema.
84
+ if (kind === 'schema' && options.kind === 'schema' && source.length === 0 && typeof value.$schema === 'string') {
85
+ return value;
86
+ }
87
+ let result = { ...value };
88
+ const child = (entry, childKind, from, to = from) => visit(entry, {
89
+ kind: childKind,
90
+ source: [...source, ...from],
91
+ output: [...output, ...to],
92
+ consumes,
93
+ produces,
94
+ semanticPath: [...semanticPath, ...to],
95
+ generated,
96
+ });
97
+ const map = async (entries, childKind, from, to = from) => {
98
+ const converted = {};
99
+ if (!isObject(entries)) {
100
+ return converted;
101
+ }
102
+ for (const [name, entry] of Object.entries(entries)) {
103
+ setOwn(converted, name, await child(entry, childKind, [...from, name], [...to, name]));
104
+ }
105
+ return converted;
106
+ };
107
+ if (kind === 'document') {
108
+ const sourceConsumes = Array.isArray(value.consumes) ? value.consumes : consumes;
109
+ const sourceProduces = Array.isArray(value.produces) ? value.produces : produces;
110
+ if (value.consumes || value.produces) {
111
+ contexts.push({ path: output, consumes: sourceConsumes, produces: sourceProduces });
112
+ }
113
+ // The existing document converter owns root-only metadata such as servers and security schemes.
114
+ const { paths, definitions, parameters, responses, components, ...metadata } = result;
115
+ result = v2 ? upgradeFromTwoToThree(metadata) : result;
116
+ result.openapi = '3.1.1';
117
+ if (v2 && isObject(definitions)) {
118
+ Object.values(definitions).forEach((schema) => migrateSchema(schema));
119
+ migrateDiscriminatorMappings(definitions);
120
+ }
121
+ const convertedComponents = isObject(components) ? { ...components } : {};
122
+ const sections = v2
123
+ ? [
124
+ [definitions, 'schema', ['definitions'], ['components', 'schemas']],
125
+ [responses, 'response', ['responses'], ['components', 'responses']],
126
+ ]
127
+ : [
128
+ [convertedComponents.schemas, 'schema', ['components', 'schemas'], ['components', 'schemas']],
129
+ [convertedComponents.parameters, 'parameter', ['components', 'parameters'], ['components', 'parameters']],
130
+ [convertedComponents.responses, 'response', ['components', 'responses'], ['components', 'responses']],
131
+ [convertedComponents.headers, 'header', ['components', 'headers'], ['components', 'headers']],
132
+ [
133
+ convertedComponents.requestBodies,
134
+ 'request-body',
135
+ ['components', 'requestBodies'],
136
+ ['components', 'requestBodies'],
137
+ ],
138
+ [convertedComponents.pathItems, 'path-item', ['components', 'pathItems'], ['components', 'pathItems']],
139
+ [convertedComponents.callbacks, 'callback', ['components', 'callbacks'], ['components', 'callbacks']],
140
+ ];
141
+ for (const [entries, childKind, from, to] of sections) {
142
+ if (!isObject(entries)) {
143
+ continue;
144
+ }
145
+ const values = {};
146
+ for (const [name, entry] of Object.entries(entries)) {
147
+ setOwn(values, name, await visit(entry, {
148
+ kind: childKind,
149
+ source: [...source, ...from, name],
150
+ output: [...output, ...to, name],
151
+ consumes: sourceConsumes,
152
+ produces: sourceProduces,
153
+ semanticPath: [...to, name],
154
+ }));
155
+ }
156
+ convertedComponents[to[1]] = values;
157
+ }
158
+ if (v2 && isObject(parameters)) {
159
+ for (const [name, parameter] of Object.entries(parameters)) {
160
+ const resolved = await resolveParameter(parameter);
161
+ const body = isObject(resolved) && (resolved.in === 'body' || resolved.in === 'formData');
162
+ const section = body ? 'requestBodies' : 'parameters';
163
+ const entries = isObject(convertedComponents[section]) ? convertedComponents[section] : {};
164
+ convertedComponents[section] = entries;
165
+ setOwn(entries, name, await visit(body ? structuredClone(resolved) : parameter, {
166
+ kind: body ? 'request-body' : 'parameter',
167
+ source: [...source, 'parameters', name],
168
+ output: [...output, 'components', section, name],
169
+ consumes: sourceConsumes,
170
+ produces: sourceProduces,
171
+ semanticPath: ['components', section, name],
172
+ }));
173
+ }
174
+ }
175
+ if (Object.keys(convertedComponents).length) {
176
+ result.components = { ...(isObject(result.components) ? result.components : {}), ...convertedComponents };
177
+ }
178
+ if (isObject(paths)) {
179
+ const convertedPaths = {};
180
+ result.paths = convertedPaths;
181
+ for (const [name, entry] of Object.entries(paths)) {
182
+ const converted = name.startsWith('x-')
183
+ ? structuredClone(entry)
184
+ : await visit(entry, {
185
+ kind: 'path-item',
186
+ source: [...source, 'paths', name],
187
+ output: [...output, 'paths', name],
188
+ consumes: sourceConsumes,
189
+ produces: sourceProduces,
190
+ semanticPath: ['paths', name],
191
+ });
192
+ setOwn(convertedPaths, name, converted);
193
+ }
194
+ }
195
+ if (isObject(value['x-webhooks'])) {
196
+ result.webhooks = await map(value['x-webhooks'], 'path-item', ['x-webhooks'], ['webhooks']);
197
+ }
198
+ delete result['x-webhooks'];
199
+ return result;
200
+ }
201
+ if (kind === 'callback') {
202
+ for (const [expression, pathItem] of Object.entries(value)) {
203
+ if (!expression.startsWith('x-') && expression !== '$ref') {
204
+ setOwn(result, expression, await child(pathItem, 'path-item', [expression]));
205
+ }
206
+ }
207
+ return result;
208
+ }
209
+ if (kind === 'path-item') {
210
+ for (const method of HTTP_METHODS) {
211
+ if (!isObject(value[method])) {
212
+ continue;
213
+ }
214
+ const operation = value[method];
215
+ // Path-level parameters participate in each operation's effective parameter list.
216
+ const inherited = v2 && Array.isArray(value.parameters) ? value.parameters : [];
217
+ const own = Array.isArray(operation.parameters) ? operation.parameters : [];
218
+ const ownIdentities = await Promise.all(own.map(resolveParameter));
219
+ const effective = [];
220
+ for (const [index, parameter] of inherited.entries()) {
221
+ const identity = await resolveParameter(parameter);
222
+ const overridden = ownIdentities.some((candidate) => isObject(identity) &&
223
+ isObject(candidate) &&
224
+ typeof identity.name === 'string' &&
225
+ typeof identity.in === 'string' &&
226
+ candidate.name === identity.name &&
227
+ candidate.in === identity.in);
228
+ if (!overridden) {
229
+ effective.push({ parameter, source: [...source, 'parameters', String(index)] });
230
+ }
231
+ }
232
+ effective.push(...own.map((parameter, index) => ({ parameter, source: [...source, method, 'parameters', String(index)] })));
233
+ result[method] = await visit(inherited.length ? { ...operation, parameters: effective.map((entry) => entry.parameter) } : operation, {
234
+ kind: 'operation',
235
+ source: [...source, method],
236
+ output: [...output, method],
237
+ consumes,
238
+ produces,
239
+ semanticPath: [...semanticPath, method],
240
+ parameterSources: effective.map((entry) => entry.source),
241
+ });
242
+ }
243
+ if (v2) {
244
+ delete result.parameters;
245
+ }
246
+ else if (Array.isArray(value.parameters)) {
247
+ result.parameters = await Promise.all(value.parameters.map((parameter, index) => child(parameter, 'parameter', ['parameters', String(index)])));
248
+ }
249
+ return result;
250
+ }
251
+ if (kind === 'operation') {
252
+ const effectiveConsumes = Array.isArray(value.consumes) ? value.consumes : consumes;
253
+ const effectiveProduces = Array.isArray(value.produces) ? value.produces : produces;
254
+ if (value.consumes || value.produces) {
255
+ contexts.push({ path: output, consumes: effectiveConsumes, produces: effectiveProduces });
256
+ }
257
+ if (isObject(value.callbacks)) {
258
+ result.callbacks = await map(value.callbacks, 'callback', ['callbacks']);
259
+ }
260
+ const parameters = [];
261
+ const forms = [];
262
+ if (Array.isArray(value.parameters)) {
263
+ for (const [index, original] of value.parameters.entries()) {
264
+ const parameter = await resolveParameter(original);
265
+ const parameterSource = parameterSources?.[index] ?? [...source, 'parameters', String(index)];
266
+ if (v2 && isObject(parameter) && parameter.in === 'formData') {
267
+ forms.push({ parameter: structuredClone(parameter), source: parameterSource });
268
+ }
269
+ else if (v2 && isObject(parameter) && parameter.in === 'body') {
270
+ result.requestBody = await visit(parameter, {
271
+ kind: 'request-body',
272
+ source: parameterSource,
273
+ output: [...output, 'requestBody'],
274
+ consumes: effectiveConsumes,
275
+ produces: effectiveProduces,
276
+ semanticPath: [...semanticPath, 'requestBody'],
277
+ });
278
+ }
279
+ else {
280
+ parameters.push(await visit(original, {
281
+ kind: 'parameter',
282
+ source: parameterSource,
283
+ output: [...output, 'parameters', String(parameters.length)],
284
+ consumes: effectiveConsumes,
285
+ produces: effectiveProduces,
286
+ semanticPath: [...semanticPath, 'parameters', String(parameters.length)],
287
+ }));
288
+ }
289
+ }
290
+ if (parameters.length) {
291
+ result.parameters = parameters;
292
+ }
293
+ else {
294
+ delete result.parameters;
295
+ }
296
+ }
297
+ if (forms.length) {
298
+ const body = migrateFormDataParameter(forms.map((entry) => entry.parameter), [...effectiveConsumes]);
299
+ for (const form of forms) {
300
+ rememberFormFields(form.parameter, form.source, [...output, 'requestBody'], Object.keys(body.content ?? {}));
301
+ }
302
+ result.requestBody = await visit(body, {
303
+ kind: 'request-body',
304
+ source: [...source, 'parameters'],
305
+ output: [...output, 'requestBody'],
306
+ generated: true,
307
+ consumes: effectiveConsumes,
308
+ produces: effectiveProduces,
309
+ semanticPath: [...semanticPath, 'requestBody'],
310
+ });
311
+ }
312
+ if (isObject(value.responses)) {
313
+ const convertedResponses = {};
314
+ result.responses = convertedResponses;
315
+ for (const [status, response] of Object.entries(value.responses)) {
316
+ const converted = await visit(response, {
317
+ kind: 'response',
318
+ source: [...source, 'responses', status],
319
+ output: [...output, 'responses', status],
320
+ consumes: effectiveConsumes,
321
+ produces: effectiveProduces,
322
+ semanticPath: [...semanticPath, 'responses', status],
323
+ });
324
+ setOwn(convertedResponses, status, converted);
325
+ }
326
+ }
327
+ if (isObject(value.requestBody)) {
328
+ result.requestBody = await child(value.requestBody, 'request-body', ['requestBody']);
329
+ }
330
+ delete result.consumes;
331
+ delete result.produces;
332
+ return result;
333
+ }
334
+ if (kind === 'schema') {
335
+ if (v2) {
336
+ migrateSchema(result, false);
337
+ if (result.type === 'file') {
338
+ result.type = 'string';
339
+ result.format = 'binary';
340
+ }
341
+ }
342
+ // Plan nullable allOf destinations before visiting descendants, so unchanged paths
343
+ // need no temporary records and nested relocations require no full-list rewrites.
344
+ const unwrapAllOf = result.nullable === true && result.type === undefined && typeof result.$ref !== 'string';
345
+ for (const [key, entry] of Object.entries(result)) {
346
+ if (schemaMaps.has(key)) {
347
+ result[key] = await map(entry, 'schema', [key]);
348
+ }
349
+ else if (schemaChildren.has(key)) {
350
+ if (Array.isArray(entry)) {
351
+ result[key] = await Promise.all(entry.map((item, index) => visit(item, {
352
+ kind: 'schema',
353
+ source: [...source, key, String(index)],
354
+ output: key === 'allOf' && unwrapAllOf
355
+ ? [...output, 'anyOf', '0', ...(entry.length === 1 ? [] : ['allOf', String(index)])]
356
+ : [...output, key, String(index)],
357
+ consumes,
358
+ produces,
359
+ semanticPath: [...semanticPath, key, String(index)],
360
+ generated,
361
+ })));
362
+ }
363
+ else if (isObject(entry)) {
364
+ result[key] = await child(entry, 'schema', [key]);
365
+ }
366
+ }
367
+ }
368
+ const converted = applyChangesToDocument(result, semanticPath);
369
+ return converted;
370
+ }
371
+ if (v2 && kind === 'parameter' && !result.$ref) {
372
+ if (result.in === 'formData' || result.in === 'body') {
373
+ throw new Error('Body and form parameters require an owning operation or request-body context');
374
+ }
375
+ result = transformParameterObject(result);
376
+ for (const key of parameterSchemaFields) {
377
+ if (Object.hasOwn(value, key)) {
378
+ remember([...source, key], [...output, 'schema', key]);
379
+ }
380
+ }
381
+ }
382
+ if (v2 && kind === 'header' && !result.$ref) {
383
+ result = transformResponseHeader(result);
384
+ for (const key of parameterSchemaFields) {
385
+ if (Object.hasOwn(value, key)) {
386
+ remember([...source, key], [...output, 'schema', key]);
387
+ }
388
+ }
389
+ }
390
+ if (v2 && kind === 'request-body' && result.in === 'formData') {
391
+ const body = migrateFormDataParameter([result], [...consumes]);
392
+ rememberFormFields(value, source, output, Object.keys(body.content ?? {}));
393
+ result = body;
394
+ }
395
+ if (v2 && kind === 'request-body' && result.in === 'body') {
396
+ result = migrateBodyParameter(result, [...consumes]);
397
+ for (const media of consumes) {
398
+ remember([...source, 'schema'], [...output, 'content', media, 'schema']);
399
+ }
400
+ }
401
+ if (v2 && kind === 'response' && !result.$ref) {
402
+ const { headers, ...response } = result;
403
+ result = transformResponseObject(response, [...produces]);
404
+ if (headers !== undefined) {
405
+ result.headers = headers;
406
+ }
407
+ for (const media of produces) {
408
+ remember([...source, 'schema'], [...output, 'content', media, 'schema']);
409
+ }
410
+ }
411
+ if (isObject(result.schema)) {
412
+ const schemaSource = v2 && (kind === 'parameter' || kind === 'header') ? source : [...source, 'schema'];
413
+ result.schema = await visit(result.schema, {
414
+ kind: 'schema',
415
+ source: schemaSource,
416
+ output: [...output, 'schema'],
417
+ consumes,
418
+ produces,
419
+ semanticPath: [...semanticPath, 'schema'],
420
+ generated,
421
+ });
422
+ }
423
+ if (isObject(result.headers)) {
424
+ result.headers = await map(v2 && kind === 'response' ? value.headers : result.headers, 'header', ['headers']);
425
+ }
426
+ if (isObject(result.content)) {
427
+ for (const [media, entry] of Object.entries(result.content)) {
428
+ if (!isObject(entry)) {
429
+ continue;
430
+ }
431
+ if (entry.schema !== undefined) {
432
+ const from = v2 && (kind === 'response' || value.in === 'body') ? ['schema'] : ['content', media, 'schema'];
433
+ entry.schema = await child(entry.schema, 'schema', from, ['content', media, 'schema']);
434
+ }
435
+ if (isObject(entry.encoding)) {
436
+ for (const [name, encoding] of Object.entries(entry.encoding)) {
437
+ if (isObject(encoding) && isObject(encoding.headers)) {
438
+ encoding.headers = await map(encoding.headers, 'header', ['content', media, 'encoding', name, 'headers']);
439
+ }
440
+ }
441
+ }
442
+ applyChangesToDocument(entry, [...semanticPath, 'content', media]);
443
+ }
444
+ }
445
+ // Match the document upgrader's example normalization without traversing literal values.
446
+ if (kind === 'parameter' || kind === 'header') {
447
+ applyChangesToDocument(result, semanticPath);
448
+ }
449
+ return result;
450
+ };
451
+ const semanticPath = options.kind === 'schema' ? ['components', 'schemas', 'fragment'] : [];
452
+ const value = await visit(structuredClone(input), {
453
+ kind: options.kind,
454
+ source: [],
455
+ output: [],
456
+ consumes: options.consumes ?? ['application/json'],
457
+ produces: options.produces ?? ['application/json'],
458
+ semanticPath,
459
+ });
460
+ return { value, locations, contexts };
461
+ };
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "openapi 3.0",
21
21
  "openapi 3.1"
22
22
  ],
23
- "version": "0.4.10",
23
+ "version": "0.5.0",
24
24
  "engines": {
25
25
  "node": ">=22"
26
26
  },
@@ -71,12 +71,12 @@
71
71
  },
72
72
  "sideEffects": false,
73
73
  "dependencies": {
74
- "@scalar/helpers": "0.18.0",
75
- "@scalar/openapi-types": "0.9.9"
74
+ "@scalar/helpers": "0.18.1",
75
+ "@scalar/openapi-types": "0.9.10"
76
76
  },
77
77
  "devDependencies": {
78
- "@scalar/types": "0.29.0",
79
- "vite": "8.3.4"
78
+ "@scalar/types": "0.30.0",
79
+ "vite": "8.3.8"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",