Skip to content

docs: a Swashbuckle schema filter for ranges and sets (#49) - #605

Merged
CaffeinatedCoder merged 3 commits into
mainfrom
docs/49-swashbuckle-schema-filter
Nov 30, 2026
Merged

CaffeinatedCoder merged 3 commits into
mainfrom
docs/49-swashbuckle-schema-filter

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #49

For both lines: this merges into main, then is cherry-picked with -x into release/10.x (the port PR follows). Documentation and its test only; no package changes.

Problem

docs/serialization.md documents an OpenAPI schema transformer for Microsoft.AspNetCore.OpenApi, but many consumers use Swashbuckle. Swashbuckle describes a type from its public properties. Measured with Swashbuckle 11.0.1 on this branch:

  • a DateRange is {"type":"object","properties":{"length":…}};
  • a StringSet is an object with values, count and isEmpty;
  • a DateRangeSet is an array of those range objects.

None of that is what the API sends.

Change

  • test/CodoMetis.ValueRanges.AspNetCore.Tests/ValueRangesSchemaFilter.cs (new): an ISchemaFilter that gives each type the schema the transformer gives, with the same three branches and the same two patterns. A range or variant becomes a string with the range-literal pattern, a range set a string with the multirange pattern, and a value set type: array, uniqueItems: true with items from the element's own schema. It also drops the properties Swashbuckle wrote. It uses IOpenApiSchema and casts to OpenApiSchema to mutate, as Swashbuckle's v10 migration guide prescribes.
  • docs/serialization.md: a "Swashbuckle" section under "OpenAPI" that carries the filter verbatim, its registration (AddSwaggerGen(o => o.SchemaFilter<ValueRangesSchemaFilter>())) and three "Good to know" bullets.
  • The test project references Swashbuckle.AspNetCore 11.0.1, which uses Microsoft.OpenApi 3.11, the version Microsoft.AspNetCore.OpenApi 11 uses.
  • Changelogs: a Docs: row under ### Added of [11.0.0-preview.3] in the root and core changelogs. AGENTS.md names the second verbatim snippet.

Tests

SwashbuckleSchemaFilterTests (new, 7 tests) generate a real Swashbuckle document through TestServer:

  • without the filter, a range is not a string and has no pattern;
  • with it, the range, multirange and value set schemas are as above, with no properties left, and no items on a range set (Swashbuckle writes a range set as a list of ranges; the second commit drops them, and the test fails without that line);
  • the filter's patterns are the transformer's text, character for character;
  • DocumentedSnippet_IsThisFile holds the doc to the compiled copy. It failed before the doc section was written.

AspNetCore tests: 99 pass. Conventions: 432 pass.

🤖 Generated with Claude Code

Swashbuckle describes a type from its public properties: a range is an
object with "length", a value set an object with "values", "count" and
"isEmpty", a range set an array of those objects. None of it is what the
API sends. docs/serialization.md gets a "Swashbuckle" section with a
schema filter to copy, ValueRangesSchemaFilter, which gives each type the
schema the documented Microsoft.AspNetCore.OpenApi transformer gives:
the range and multirange literal as a string with its pattern, a value
set as an array of unique elements.

As with the transformer, the AspNetCore test project compiles the filter
and SwashbuckleSchemaFilterTests holds the doc to it verbatim. The tests
generate a real Swashbuckle 11.0.1 document both ways and check that the
filter's patterns are the transformer's text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.5.0 milestone Nov 30, 2026
@CaffeinatedCoder CaffeinatedCoder added documentation Improvements or additions to documentation area/json System.Text.Json and TypeConverter wire forms package/core Affects CodoMetis.ValueRanges labels Nov 30, 2026
Swashbuckle describes a range set as a list of ranges, so its schema
carried "items" beside the string type the filter set. Replace clears
them, and the multirange test asserts it; it fails without the line.
The bullet saying Swashbuckle 10 works too goes: it was not run here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder
CaffeinatedCoder merged commit 5f3ced0 into main Nov 30, 2026
14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the docs/49-swashbuckle-schema-filter branch November 30, 2026 13:52
CaffeinatedCoder added a commit that referenced this pull request Nov 30, 2026
…ema-filter-10.x

docs: a Swashbuckle schema filter for ranges and sets (#49, port of #605)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/json System.Text.Json and TypeConverter wire forms documentation Improvements or additions to documentation package/core Affects CodoMetis.ValueRanges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document a Swashbuckle schema filter for ranges and sets

1 participant