Commit bcbbd34
OpenAPI 3.1 / JSON Schema 2020-12: $ref+description fix and further feature support (#382)
* Support additional OpenAPI 3.1 / JSON Schema 2020-12 features
Follow-up to the $ref+description fix, addressing further 3.1 gaps found in an
audit of the schema generator. Structural correctness fixes (narrow blast
radius; only affect specs using these constructs):
- $defs: collect top-level `$defs` as a schema source and resolve
`$ref: '#/$defs/...'` (ApiTool.getComponentSchemas). Models under $defs now
generate and are referenceable.
- prefixItems / items:false: tuple arrays and `items:false` degrade to
List<Object> instead of an empty/invalid element type.
- type:"null": a scalar null type degrades to Object instead of emitting an
invalid `null` Java type.
- nullability: a field that is nullable (3.0 `nullable:true` or the 3.1
["T","null"] idiom) is no longer marked required, so no spurious @NotNull is
generated (ApiTool.isNullable).
- patternProperties: an object with patternProperties maps to Map<String,V>
instead of an empty POJO.
- 3.1 binary strings: `contentEncoding` / `contentMediaType` are recognised as
binary (MultipartFile), complementing `format: binary`.
Adds regression test `testOpenApi31Completeness` covering all of the above.
Documented limitations (left non-breaking, deferred as larger work):
- multi-type unions still pick the first concrete type (tested behaviour;
needs a real union type model);
- description/summary/examples propagation (wide blast radius: 51 specs use
field-level description);
- contains/propertyNames/unevaluated*/dependent*/if-then-else validation
(needs new validators; parsed-through today);
- info.summary / license.identifier metadata;
- $id/$anchor resolution and $schema/$dynamicRef (ignored non-fatally).
Bumps version 6.4.2 -> 6.5.0 (new features).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Propagate schema description and example(s) into generated models
Carry property-level `description` and `example` (3.0) / `examples` (3.1, first
entry) into the generated model classes via the @Schema annotation. This also
surfaces the sibling `description` of a `$ref` (OpenAPI 3.1), completing the
earlier $ref+description fix. Values are Java-string-escaped in the template.
- SchemaFieldObject gains `description`/`example`.
- ApiTool.getDescription/getExample (examples[0] fallback).
- ModelBuilder applies them at the property choke point (applyMetadata).
- templateSchema.ftlh emits `description`/`example` on @Schema when present.
Assets across the OpenAPI and AsyncAPI generators are regenerated accordingly.
Note: the Lombok model template does not use @Schema, so descriptions are not
emitted there (unchanged).
Full multiapi-engine suite: 110/110 passing (mvn clean test).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: joseegarcia <jose.garcia@disashop.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 7164d96 commit bcbbd34
30 files changed
Lines changed: 633 additions & 52 deletions
File tree
- multiapi-engine
- src
- main
- java/com/sngular/api/generator/plugin/common
- model
- tools
- resources/templates/model
- test
- java/com/sngular/api/generator/plugin/openapi
- resources
- asyncapigenerator
- v2
- testCustomValidators/assets
- testIssueGeneration/assets
- testIssueSimpleTypeGeneration/assets
- testReferenceFromLocalIssue/assets
- testSubObjectSameName/assets
- input/model
- output/model
- v3
- testCustomValidators/assets
- testIssueGeneration/assets
- testIssueSimpleTypeGeneration/assets
- testReferenceFromLocalIssue/assets
- testSubObjectSameName/assets
- input/model
- output/model
- openapigenerator
- testOpenApi31Completeness
- assets
- testRefWithDescription/assets
- scs-multiapi-gradle-plugin
- scs-multiapi-maven-plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
multiapi-engine/src/main/java/com/sngular/api/generator/plugin/common/model/SchemaFieldObject.java
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
Lines changed: 97 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
156 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
157 | 173 | | |
158 | 174 | | |
159 | 175 | | |
| |||
226 | 242 | | |
227 | 243 | | |
228 | 244 | | |
229 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
230 | 254 | | |
231 | 255 | | |
232 | 256 | | |
| |||
347 | 371 | | |
348 | 372 | | |
349 | 373 | | |
350 | | - | |
351 | | - | |
| 374 | + | |
| 375 | + | |
352 | 376 | | |
353 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
354 | 380 | | |
355 | 381 | | |
356 | 382 | | |
357 | 383 | | |
358 | 384 | | |
359 | 385 | | |
360 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
361 | 427 | | |
362 | 428 | | |
363 | 429 | | |
| |||
414 | 480 | | |
415 | 481 | | |
416 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
417 | 509 | | |
418 | 510 | | |
419 | 511 | | |
| |||
Lines changed: 68 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | 172 | | |
175 | 173 | | |
176 | | - | |
| 174 | + | |
177 | 175 | | |
| 176 | + | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
| |||
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
| 342 | + | |
340 | 343 | | |
341 | 344 | | |
342 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
343 | 364 | | |
344 | 365 | | |
345 | 366 | | |
| |||
426 | 447 | | |
427 | 448 | | |
428 | 449 | | |
429 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
430 | 455 | | |
431 | 456 | | |
432 | 457 | | |
433 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
434 | 461 | | |
435 | 462 | | |
436 | 463 | | |
| |||
626 | 653 | | |
627 | 654 | | |
628 | 655 | | |
629 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
630 | 659 | | |
631 | 660 | | |
632 | 661 | | |
| |||
888 | 917 | | |
889 | 918 | | |
890 | 919 | | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
891 | 953 | | |
892 | 954 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
185 | 192 | | |
186 | 193 | | |
187 | 194 | | |
| |||
891 | 898 | | |
892 | 899 | | |
893 | 900 | | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
894 | 920 | | |
895 | 921 | | |
896 | 922 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
0 commit comments