Skip to content

7.1.10

Choose a tag to compare

@avgalex avgalex released this 12 Jul 10:22
· 17 commits to master since this release
55c62b0

Fixed — Issue #223: a [FromQuery] DTO shared by several endpoints lost its rules on every endpoint after the first

When the same [FromQuery]/[AsParameters] DTO was bound by more than one endpoint, only the first operation received FluentValidation constraints (minLength, pattern, maximum, ...) — every subsequent endpoint silently lost them. Reproduces with the default RemoveUnusedQuerySchemas = true.

app.MapGet("/hello1", ([FromQuery] HelloRequest request) => ...); // constraints emitted
app.MapGet("/hello2", ([FromQuery] HelloRequest request) => ...); // before: constraints lost — after: emitted
  • Root cause: FluentValidationOperationFilter runs once per operation. The Issue #180 cleanup removes the temporary [FromQuery] container schema from SchemaRepository.Schemas, but Swashbuckle also keeps the type in its internal reserved-ids map, which the cleanup cannot touch. For the 2nd+ endpoint GenerateSchema then returns a bare $ref with no Properties, so the "has properties" guard skipped all rules.
  • Fix: SwashbuckleSchemaProvider.GetSchemaForType detects this reserved-but-removed state and recovers the concrete schema by generating it into a throwaway SchemaRepository. Fully isolated — the shared repository and its reserved-id state are never mutated — so the Issue #180 cleanup and all other operation-filter behavior (required marking #209, nested [FromQuery] #211/#213, request bodies and encoding.contentType #216) are preserved.
  • Follow-up hardening is tracked in #226: body-bound shared DTOs, and a ReplaceSchemaId-based state-healing cleanup on the net10.0 target (needs Swashbuckle >= 10.1.0).

Thanks to @jgarciadelanoceda for the report and the ReplaceSchemaId discussion.


Full changelog: https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation/blob/master/CHANGELOG.md