|
| 1 | +--- |
| 2 | +"@objectstack/spec": patch |
| 3 | +--- |
| 4 | + |
| 5 | +fix(spec): the reference generator quotes a literal by its `typeof`, so numeric literals stop being written down as strings (#5729) |
| 6 | + |
| 7 | +`formatType()`'s two literal branches wrapped every value in `'…'` without |
| 8 | +looking at its type — `prop.enum.map(e => `'${e}'`)` and |
| 9 | +`return `'${prop.const}'`` — so a **numeric** literal union was printed as a |
| 10 | +**string** one. `FormSection.columns` is the specimen the issue was filed from: |
| 11 | +it is declared |
| 12 | + |
| 13 | +```ts |
| 14 | +z.union([z.enum(['1', '2', '3', '4']), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]) |
| 15 | +``` |
| 16 | + |
| 17 | +and `content/docs/references/ui/view.mdx` rendered it as |
| 18 | +`Enum<'1' | '2' | '3' | '4'> | '1' | '2' | '3' | '4'`, where the second half is |
| 19 | +those four `z.literal(<number>)` variants. The two halves came out |
| 20 | +indistinguishable, so the page claimed the key takes strings only — while the |
| 21 | +schema accepts both `2` and `'2'`. |
| 22 | + |
| 23 | +For these pages that is a contract error, not a typo. They are the authoritative |
| 24 | +input for an AI author (ADR-0033), and a literal union is a copy-the-spelling |
| 25 | +surface: whatever quoting the page shows is what gets written. #5611 paid for it |
| 26 | +directly — its `RecordDetailsProps.sections[].columns` was meant to be a numeric |
| 27 | +literal union, the generated reference said strings, and the PR abandoned the |
| 28 | +shape for `z.number().int().min(1).max(4)` to escape the contradiction. The |
| 29 | +generator was defining the contract backwards. |
| 30 | + |
| 31 | +Quoting is now decided per **value**, not per node, because JSON Schema states |
| 32 | +member types per value and an `enum` may mix them (`z.nativeEnum({ A: 1 })` |
| 33 | +emits a numeric `enum`): strings stay quoted, `number`/`boolean` render bare, |
| 34 | +and `null` renders as the keyword. |
| 35 | + |
| 36 | +Eight reference pages change, 11 lines, and in one direction only — quotes are |
| 37 | +removed from 18 non-string literals and no string literal loses its: |
| 38 | +`api/dispatcher`, `api/errors` (`success: false`), `data/data-engine` |
| 39 | +(`sort: Record< string, 1 | -1 >`), `data/driver-nosql` (`projection: |
| 40 | +Record< string, 0 | 1 >`), `data/object` (`systemFields` / `stageField: false`), |
| 41 | +`security/explain` (`version: 1`), `ui/dashboard` (`filterBindings`) and |
| 42 | +`ui/view` (`columns: … | 1 | 2 | 3 | 4`). Every `Enum<'a' | 'b'>` on those |
| 43 | +pages is untouched. |
0 commit comments