Commit 19493d0
feat(generator): constraint doc comments + x-enum-varnames (Q2.4, Q2.6)
Two doc-comment-emitting features. Both default-on, both feed
non-binding human-readable hints to callers without adding any
runtime crate dependencies.
## Q2.4 — constraint annotations as doc comments
Pre-Q2.4 the generator parsed minimum/maximum/min_length/
max_length/pattern/multiple_of/min_items/max_items/uniqueItems
into SchemaDetails but never emitted them. Real specs use these
heavily (13k+ uniqueItems and 4k+ min/max occurrences across the
corpus); dropping them was a real loss for callers trying to
understand the contract.
Now each property with at least one constraint gets a
`/// Constraint: <key>=<value>, …` doc comment. Pattern strings
are escaped so `///` and `*/` substrings can't terminate the
surrounding doc comment.
Toggle: `[generator.types.constraints] mode = "doc"` (default) /
`"off"` (suppress entirely).
**No client-side validation** by design. The generator never
emits `#[validate(...)]` attributes or pulls in the `validator`
crate. OpenAPI constraints belong on the wire contract; the
server is the source of truth. Doc comments give callers
visibility without the SDK duplicating server logic and going
brittle when rules drift. The `no_validate_attribute_is_ever_emitted`
test pins this guarantee.
Implementation:
- `PropertyConstraints` struct in analysis.rs captures the
relevant SchemaDetails fields per property.
- `PropertyInfo` carries the constraints alongside the schema type.
- Generator emits the doc line via `generate_constraint_doc()`
+ `format_constraints_doc()` helper.
## Q2.6 — x-enum-varnames / x-enum-descriptions
Common vendor extensions for enum schemas: arrays of Rust-friendly
variant identifiers and per-variant descriptions, parallel to the
spec's `enum` array. Used by arcade.yaml, datadog-v2.yaml, and
others in the corpus.
When `x-enum-varnames` is present and length-matches the enum
array, the generator uses those identifiers for variant names
instead of the default PascalCase heuristic. Wire format is
preserved via `#[serde(rename = "<original-value>")]`. When
`x-enum-descriptions` is present, each entry becomes the variant's
doc comment.
Length-mismatched extensions are silently dropped at analysis
time with a stderr warning; the generator falls back to the
default heuristic.
Toggles: `[generator.types.enums]` `x_enum_varnames` /
`x_enum_descriptions` (both default true).
Implementation:
- `EnumExtensions` struct in analysis.rs holds the validated
varnames + descriptions.
- `SchemaAnalysis.enum_extensions` side-channel keyed by analyzed-
schema name (avoided extending every StringEnum constructor).
- `extract_enum_extensions()` populates after analyze() by reading
`original` JSON.
- `generate_string_enum` + `generate_extensible_enum` accept an
`Option<&EnumExtensions>` and apply overrides when toggles allow.
## Verification
- 8 new tests in tests/constraint_doc_test.rs (Q2.4).
- 6 new tests in tests/x_enum_varnames_test.rs (Q2.6).
- 1 snapshot updated (union_array_naming) where a real spec
field with a `pattern` got its constraint doc surfaced.
- Full integration suite passes; spec-compile gate verification
pending in next commit.
Closes openapi-generator-d8y (Q2.4) and openapi-generator-4mu (Q2.6).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 05d555b commit 19493d0
9 files changed
Lines changed: 794 additions & 26 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
8 | 64 | | |
9 | 65 | | |
10 | 66 | | |
| |||
23 | 79 | | |
24 | 80 | | |
25 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
26 | 105 | | |
27 | 106 | | |
28 | 107 | | |
| |||
104 | 183 | | |
105 | 184 | | |
106 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
107 | 255 | | |
108 | 256 | | |
109 | 257 | | |
| |||
774 | 922 | | |
775 | 923 | | |
776 | 924 | | |
| 925 | + | |
777 | 926 | | |
778 | 927 | | |
779 | 928 | | |
| |||
861 | 1010 | | |
862 | 1011 | | |
863 | 1012 | | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
864 | 1030 | | |
865 | 1031 | | |
866 | 1032 | | |
| |||
1484 | 1650 | | |
1485 | 1651 | | |
1486 | 1652 | | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
1487 | 1656 | | |
1488 | 1657 | | |
1489 | 1658 | | |
| |||
1566 | 1735 | | |
1567 | 1736 | | |
1568 | 1737 | | |
| 1738 | + | |
1569 | 1739 | | |
1570 | 1740 | | |
1571 | 1741 | | |
| |||
2231 | 2401 | | |
2232 | 2402 | | |
2233 | 2403 | | |
| 2404 | + | |
2234 | 2405 | | |
2235 | 2406 | | |
2236 | 2407 | | |
| |||
0 commit comments