Repository navigation
Commit bb5ec77
authored
fix(openapi): serialize the document before downgrading to OpenAPI 3.1/3.0 (#2439)
## Problem
`OpenAPIGenerator.generate` downgraded the 3.2 document to the requested
version first and serialized it afterwards. That meant the downgraders
worked on non-JSON values. For example, a schema with `const: Infinity`
downgraded to 3.0 became `{ type: 'number', enum: [Infinity] }`. The
serializer then wrote that as `enum: [null]` on a non-nullable `number`,
which is an invalid schema and disagrees with what the runtime
serializer sends.
## Fix
Serialize the 3.2 document first, then downgrade the JSON form. `const:
Infinity` now goes through the downgrader as `const: null`, the same as
an explicit `const: null`.
Earlier commits also dropped `undefined` fields before serializing, so a
serializer configured with `omitUndefinedProperties: false` couldn't
write `summary: null`. That option was removed in #2441, so the
serializer always omits undefined properties and the extra pass is gone
again.
## Tests
`downgrades non-JSON schema values as their serialized form in OpenAPI
%s`: fails on `main` for 3.0.4 and passes with this change.
`pnpm check` and `pnpm test` pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01VVaw7RubDmUVdyQ2K8XBxp1 parent 12df131 commit bb5ec77
2 files changed
Lines changed: 21 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
883 | 884 | | |
884 | 885 | | |
885 | 886 | | |
886 | | - | |
| 887 | + | |
887 | 888 | | |
888 | 889 | | |
889 | 890 | | |
| |||
900 | 901 | | |
901 | 902 | | |
902 | 903 | | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
903 | 920 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
| |||
0 commit comments