@scalar/openapi-upgrader 0.2.12 → 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,23 @@
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
+
15
+ ## 0.2.13
16
+
17
+ ### Patch Changes
18
+
19
+ - [#9827](https://github.com/scalar/scalar/pull/9827): Convert nullable `$ref` patterns to the 3.1 null-union form when upgrading from OpenAPI 3.0 to 3.1
20
+
3
21
  ## 0.2.12
4
22
 
5
23
  ### 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);
@@ -107,6 +107,24 @@ const applyChangesToDocument = (schema, path) => {
107
107
  schema.type = [schema.type, 'null'];
108
108
  delete schema.nullable;
109
109
  }
110
+ // 1b. Handle nullable `$ref` patterns.
111
+ // OpenAPI 3.0 had no way to mark a `$ref` as nullable, so people wrote `nullable: true` next to
112
+ // a `$ref`, or next to an `allOf` wrapping one. `nullable` does not exist in 3.1, so leaving these
113
+ // untouched would silently drop the null option. Rewrite them to the 3.1 null-union form. This only
114
+ // runs when there is no sibling `type` (that case is handled above).
115
+ else if (schema.nullable === true && schema.type === undefined) {
116
+ if (typeof schema.$ref === 'string') {
117
+ const { nullable: _nullable, $ref, ...rest } = schema;
118
+ return { ...rest, anyOf: [{ $ref }, { type: 'null' }] };
119
+ }
120
+ if (Array.isArray(schema.allOf)) {
121
+ const { nullable: _nullable, allOf, ...rest } = schema;
122
+ // A single-member `allOf` unwraps so the union reads `anyOf: [<member>, { type: 'null' }]`.
123
+ const base = allOf.length === 1 ? allOf[0] : { allOf };
124
+ return { ...rest, anyOf: [base, { type: 'null' }] };
125
+ }
126
+ // Otherwise there is nothing for `nullable` to attach to, so leave the schema untouched.
127
+ }
110
128
  // 2. Handle exclusiveMinimum and exclusiveMaximum
111
129
  if (schema.exclusiveMinimum === true) {
112
130
  schema.exclusiveMinimum = schema.minimum;
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "openapi 3.0",
21
21
  "openapi 3.1"
22
22
  ],
23
- "version": "0.2.12",
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
- "vite": "8.0.0",
78
- "@scalar/types": "0.17.0",
79
- "@scalar/helpers": "0.9.2"
77
+ "vite": "8.1.5",
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",