@scalar/openapi-upgrader 0.2.12 → 0.2.13

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,11 @@
1
1
  # @scalar/openapi-upgrader
2
2
 
3
+ ## 0.2.13
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
3
9
  ## 0.2.12
4
10
 
5
11
  ### Patch Changes
@@ -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.13",
24
24
  "engines": {
25
25
  "node": ">=22"
26
26
  },
@@ -74,9 +74,9 @@
74
74
  "@scalar/openapi-types": "0.9.4"
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.10.0",
79
+ "@scalar/types": "0.17.1"
80
80
  },
81
81
  "scripts": {
82
82
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",