Repository navigation
Conversation
…Sort Scan the sort parameter's item-count bounds and pass them to @ValidSort: a scalar enum sort gets maxItems = 1, an array sort takes minItems/maxItems from its schema (resolved through $ref chains and allOf). Attributes are only emitted when known, so unbounded array sorts are unchanged. The generated ValidSort annotation gains minItems/maxItems (default unbounded); the validator counts Pageable sort orders and reports a violation on the sort node when out of bounds. An unsorted Pageable stays valid. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rule) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
All reported issues were addressed across 22 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…m bounds - Guard ModelUtils.resolveMin/MaxItems against cyclic allOf/$ref graphs - Render open-ended bounds as 'at least N' / 'at most N' in violation message - Reword docs: unsorted Pageable is always accepted, even with minItems - Clarify generateSortValidation option description; regenerate docs - Fix getReferencedSchemaChain Javadoc, wrap long lines, tighten tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
2 issues found across 22 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java:1060">
P2: The `$ref` chain resolver drops sibling constraints from OpenAPI 3.1 Schema Objects, so `minItems`/`maxItems` declared beside a sort schema `$ref` are not enforced. Preserve and merge the current schema's bounds with the referenced target while traversing the chain.</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringPageableScanUtils.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringPageableScanUtils.java:677">
P2: `findFirst()` makes composed array schemas unsound: values allowed by the first item enum can bypass a later `allOf` item enum. Intersect all non-empty item enum constraints across the array schemas before emitting `allowedValues` (and treat an empty enum as rejecting all values).</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| if (next == schema) { | ||
| break; | ||
| } | ||
| schema = next; |
There was a problem hiding this comment.
P2: The $ref chain resolver drops sibling constraints from OpenAPI 3.1 Schema Objects, so minItems/maxItems declared beside a sort schema $ref are not enforced. Preserve and merge the current schema's bounds with the referenced target while traversing the chain.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java, line 1060:
<comment>The `$ref` chain resolver drops sibling constraints from OpenAPI 3.1 Schema Objects, so `minItems`/`maxItems` declared beside a sort schema `$ref` are not enforced. Preserve and merge the current schema's bounds with the referenced target while traversing the chain.</comment>
<file context>
@@ -1038,6 +1039,79 @@ public static ResolvedMinBound resolveMinimumBound(OpenAPI openAPI, Schema<?> sc
+ if (next == schema) {
+ break;
+ }
+ schema = next;
+ }
+ return schema;
</file context>
There was a problem hiding this comment.
Already handled: OpenAPINormalizer.normalizeReferenceSchema rewrites { $ref, maxItems } into { allOf: [$ref], maxItems } before preprocessOpenAPI, so the bound is honoured. Covered by SpringPageableScanUtilsTest.scanSortValidationEnums_refWithSiblingBounds_mergedAfterNormalization.
| openAPI, array.getItems())) | ||
| .filter(items -> items != null && items.getEnum() != null | ||
| && !items.getEnum().isEmpty()) | ||
| .findFirst() |
There was a problem hiding this comment.
P2: findFirst() makes composed array schemas unsound: values allowed by the first item enum can bypass a later allOf item enum. Intersect all non-empty item enum constraints across the array schemas before emitting allowedValues (and treat an empty enum as rejecting all values).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringPageableScanUtils.java, line 677:
<comment>`findFirst()` makes composed array schemas unsound: values allowed by the first item enum can bypass a later `allOf` item enum. Intersect all non-empty item enum constraints across the array schemas before emitting `allowedValues` (and treat an empty enum as rejecting all values).</comment>
<file context>
@@ -625,37 +654,76 @@ public static Map<String, List<String>> scanSortValidationEnums(
+ openAPI, array.getItems()))
+ .filter(items -> items != null && items.getEnum() != null
+ && !items.getEnum().isEmpty())
+ .findFirst()
+ .orElse(null)
+ : schema;
</file context>
There was a problem hiding this comment.
Intentional: only the first item enum is honoured. Combining different enums via allOf is not a realistic sort spec; define the enum in one schema.
- Escape the requested sort property before building the violation
message template, so { } $ \ are not interpolated
- Kotlin: move minItems/maxItems after message to keep positional
@ValidSort(...) usages source compatible
- Add findPetsWithMinSortBounds (minItems: 2) sample endpoint and
runtime tests for the lower bound and the 'at least N' message
- Test that OAS 3.1 $ref sibling bounds are merged after normalization
- Make the Java validator assertions indentation independent; sort imports
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enforce the
sortparameter's item-count bounds in the generated@ValidSort(Spring and Kotlin Spring,generateSortValidation=true). Previously only allowed sort values were checked, so a spec allowing a single sort accepted any number of sort orders.sort→maxItems = 1; an arraysorttakesminItems/maxItemsfrom its schema, resolved through$refchains andallOf(cycle-safe; OAS 3.1$refsiblings via the normalizer). Contradictory bounds are dropped with a warning.minItems/maxItemsare added to@ValidSort(...)only when known; outputs without bounds are unchanged.ValidSortgainsminItems/maxItems(default unbounded; in Kotlin placed aftermessageso positional usages still compile). The validator countsPageablesort orders and reports a violation onsort(at least N/at most N/N..M). An unsortedPageablestays valid. Sort properties are escaped in violation messages.generateSortValidationdescription, regenerated docs and thespringboot-sort-validation/kotlin-springboot-sort-validationsamples, with runtime tests for the bounds.Tests run (JDK 17):
./mvnw -pl modules/openapi-generator test -Dtest='ArchUnitRulesTest,SpringPageableScanUtilsTest,SpringCodegenTest,KotlinSpringServerCodegenTest': passed./mvnw -f samples/server/petstore/springboot-sort-validation/pom.xml test: passed./mvnw -f samples/server/petstore/kotlin-springboot-sort-validation/pom.xml test: passedPR checklist
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.
Summary by cubic
Enforces the sort parameter's item-count bounds in the generated
@ValidSortannotation for Spring and Kotlin Spring. Previously only the allowed sort enum values were validated; now the number of sort orders is checked too.sortgetsmaxItems = 1; an arraysorttakes itsminItems/maxItemsfrom the schema, resolved through$refchains andallOf.messageso existing positional@ValidSort(...)usages still compile.Pageableremains valid even whenminItemsis set; violations reportat least N/at most N/min..maxbounds and escape user sort properties so{ } $ \are not interpolated.minItems>maxItems) are dropped with a warning; boundary resolution is protected against cyclicallOf/$refgraphs.Written for commit 41211a4. Summary will update on new commits.