@scalar/openapi-upgrader 0.2.13 → 0.2.15

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,17 @@
1
1
  # @scalar/openapi-upgrader
2
2
 
3
+ ## 0.2.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [#9941](https://github.com/scalar/scalar/pull/9941): Republish every package through npm trusted publishing. No functional changes.
8
+
9
+ ## 0.2.14
10
+
11
+ ### Patch Changes
12
+
13
+ - [#9910](https://github.com/scalar/scalar/pull/9910): Keep the full schema of a Swagger 2.0 `formData` parameter when upgrading to OpenAPI 3.0. The request body property was rebuilt from `type`, `description` and `format` only, so a parameter with `type: 'array'` lost its `items` and consumers of the upgraded document saw an array of unknown values. `items`, `enum`, `default` and the other validation keywords now survive, and the array `collectionFormat` is carried over as an OpenAPI 3.0 `encoding` entry (`style`/`explode`) instead of being dropped.
14
+
3
15
  ## 0.2.13
4
16
 
5
17
  ### Patch Changes
@@ -663,6 +663,23 @@ function getParameterSerializationStyle(parameter) {
663
663
  }
664
664
  return {};
665
665
  }
666
+ /**
667
+ * Translate the Swagger 2.0 `collectionFormat` of a formData array parameter into an OpenAPI 3.0
668
+ * encoding entry. Form bodies serialize arrays with the same styles as query parameters, so the
669
+ * query serialization mapping is reused. Returns undefined when there is nothing to preserve, for
670
+ * example a non-array parameter, one without a `collectionFormat`, or `tsv` which has no OpenAPI
671
+ * 3.0 equivalent.
672
+ */
673
+ function getFormDataEncoding(parameter) {
674
+ if (parameter.type !== 'array' || typeof parameter.collectionFormat !== 'string') {
675
+ return undefined;
676
+ }
677
+ const encoding = querySerialization[parameter.collectionFormat];
678
+ if (!encoding || Object.keys(encoding).length === 0) {
679
+ return undefined;
680
+ }
681
+ return encoding;
682
+ }
666
683
  function migrateBodyParameter(bodyParameter, consumes) {
667
684
  // Extract x-example and x-examples before deleting other properties
668
685
  // @see https://redocly.com/docs-legacy/api-reference-docs/specification-extensions/x-examples
@@ -742,10 +759,18 @@ function migrateFormDataParameter(parameters, consumes = ['multipart/form-data']
742
759
  for (const param of parameters) {
743
760
  if (param.name && formContent.schema.properties) {
744
761
  formContent.schema.properties[param.name] = {
745
- type: param.type,
746
- description: param.description,
747
- ...(param.format ? { format: param.format } : {}),
762
+ ...transformItemsObject(structuredClone(param)),
763
+ // Only carry the description over when it exists, so a parameter without one does not
764
+ // end up with an explicit `description: undefined` on its schema.
765
+ ...(param.description !== undefined ? { description: param.description } : {}),
748
766
  };
767
+ // Preserve the array serialization hint (Swagger 2.0 `collectionFormat`) as an
768
+ // OpenAPI 3.0 encoding entry on the media type, so it is not silently dropped.
769
+ const encoding = getFormDataEncoding(param);
770
+ if (encoding) {
771
+ formContent.encoding ??= {};
772
+ formContent.encoding[param.name] = encoding;
773
+ }
749
774
  // Add to required array if param is required
750
775
  if (param.required && Array.isArray(formContent.schema.required)) {
751
776
  formContent.schema.required.push(param.name);
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "openapi 3.0",
21
21
  "openapi 3.1"
22
22
  ],
23
- "version": "0.2.13",
23
+ "version": "0.2.15",
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.4"
74
+ "@scalar/openapi-types": "0.9.5"
75
75
  },
76
76
  "devDependencies": {
77
77
  "vite": "8.1.5",
78
- "@scalar/helpers": "0.10.0",
79
- "@scalar/types": "0.17.1"
78
+ "@scalar/helpers": "0.11.1",
79
+ "@scalar/types": "0.18.2"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",