[core] Normalizer: x-items extension for List customization

Merged
JP
2mo ago
+57-4

fixes #25113 : keep ‘@Valid’ for items with $ref
fixes #23705: [REQ] Possibilty of annoted type arguments with bean Validation for Java Collections (closed because there is a workaround in #25049)

Add normalization of x-items-xxx to add vendorExtensions in array.items.

Example:

listRef:
  type: array
  x-items-x-field-extra-annotation: '@NotEmpty'
  items:
    $ref: '#/components/schemas/Stubb'

is converted into

listRef:
  type: array
  items:
    allOf:
       - $ref: '#/components/schemas/Stubb'
    x-field-extra-annotation: '@NotEmpty'

It works for generators that supports arrays of items with allOf (for Example Java generators)

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes #25113 by normalizing x-items-* vendor extensions so array item types can be annotated in generated Java code, enabling generics like List<@NotEmpty @Valid Stubb>.

  • The normalizer moves x-items-* extensions onto the item schema, stripping the prefix.
  • $ref items with siblings are wrapped in allOf: [$ref]; Java generation now emits @Valid for these.
  • Regression tests cover $ref and inline object items.