Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ so moving a project cannot silently retarget a test.
- `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/` — Live PostgreSQL via Testcontainers (needs Docker; Inconclusive without, but hard failure under CI=true). The shared container runs `VALUERANGES_POSTGRES_IMAGE`, default `postgres:16-alpine` (the 10.x floor); CI runs both integration projects on 16 and 18, and a server below 16 fails every test (`PostgresServer.cs`). Covers BCL and NodaTime types. Authority on PostgreSQL semantics — run when changing translations or range algebra. `CapturedCollectionProbeTests` sends every discovered range and set type as a captured collection (`Contains`, `Any`, `Count`); it links `RangeProbes` and `SetProbes` from the conventions project rather than copying them. `ComplexIndexesCrossTests` holds this package's columns under `EFCore.ComplexIndexes.PostgreSQL`'s temporal and exclusion constraints and GiST indexes on PostgreSQL 16 and 18 (containers of its own) through a test-only reference; neither shipping package references the other
- `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/` — The same live layer for configuration that is per process: its runtimeconfig sets `Npgsql.DisableDateTimeInfinityConversions`, which Npgsql and the plugin each read once, so it cannot be flipped inside the other project's run. Holds the temporal store rule at the extremes with the conversion off. Own container; CI's integration job runs every `test/*IntegrationTests/`
- `test/Directory.Build.targets` — Floats the EF test projects (every project whose name contains `EFCore`) to a newer EF Core and Npgsql EF patch for one run, `-p:EfFloat=10.0.14 -p:NpgsqlEfFloat=10.0.3`, while `src/` keeps compiling against the floor it ships: a consumer's situation, which floor-only CI missed for #302. Without the properties it does nothing. CI's newest-patch integration legs pass them, and the newest published versions live in one place, the `integration-legs` matrix in `dotnet.yml` (#297). It also runs every test project on a newer runtime major, `-p:ExpectRuntimeMajor=11`: `RollForward=LatestMajor` for each test host, and `test/RuntimeMajorProbe.cs` compiled into each project, which fails unless the tests ran on that major. CI's `Test (.NET 11 runtime, roll-forward)` job builds with it and requires the probe to pass in every suite (#324)
- `test/CodoMetis.ValueRanges.AspNetCore.Tests/` — Host-level behaviour with no ValueRanges registration: configuration binding (`TypeConverter`), MVC and minimal-API binding and JSON bodies via `TestServer`, and the documented OpenAPI schema transformer (`ValueRangesSchemaTransformer.cs`), which `docs/serialization.md` must carry verbatim — edit the test copy, then the doc. `HostCultureProbeTests` binds every discovered type (core and NodaTime) through both hosts under four request cultures; it links `RangeProbes`, `SetProbes`, `WrapperElements` and `Reflect` from the conventions project rather than copying them
- `test/CodoMetis.ValueRanges.AspNetCore.Tests/` — Host-level behaviour with no ValueRanges registration: configuration binding (`TypeConverter`), MVC and minimal-API binding and JSON bodies via `TestServer`, the documented OpenAPI schema transformer (`ValueRangesSchemaTransformer.cs`) and the Swashbuckle schema filter (`ValueRangesSchemaFilter.cs`), which `docs/serialization.md` must carry verbatim — edit the test copy, then the doc. `HostCultureProbeTests` binds every discovered type (core and NodaTime) through both hosts under four request cultures; it links `RangeProbes`, `SetProbes`, `WrapperElements` and `Reflect` from the conventions project rather than copying them
- `test/CodoMetis.ValueRanges.Conventions.Tests/` — Repo-level conventions: changelog consistency and form, packaging metadata (each package's nuspec, generated by NuGet's own pack task, carries its version's changelog section as release notes), release wiring, the SECURITY.md supported-versions table, value set contract compliance, EF mapping parity, translator dispatch (`TranslatorDispatchSweepTests`: every public query member over every type, each operand mapped as its declared type), the default JSON contract, text made with the current culture (`InvariantTextConventionTests` compiles `src/` in memory). Everything is discovered (projects by globbing `src/`, types by reflection), so adding a package or a type needs no edit here
- `test/oracles/` — The bug-finding system (`docs/oracles.md`): `claims.json` quotes every promise the consumer-facing docs make and names the test that holds it (empty `heldBy` is the worklist); `oracles.json` registers the sweep classes; `seeds/*.patch` plant one defect each in `src/` that the named oracles were shown to catch; `surface-waivers.json` names the public members no claim covers, with the reason; `candidates.json` holds disagreements found but not fixed, keyed to issues; `postgres-surface.json` holds every PostgreSQL range, multirange and array operator and function (one entry per row of `postgres-surface.catalog.txt`, the raw `pg_operator`/`pg_proc` listing) with the member that mirrors it, the translation a test asserts, or a waiver or issue; `translation-support.json` is the other direction: every public query member (`QueryMembers`, discovered from the public API, one key per overload) classified as running as SQL, in memory only (with the reason) or planned (with the issue), which `TranslationSupportInventoryTests` holds complete and `TranslationSupportProbeTests` (integration) holds true against EF Core over every closed type; `CloneSweep.cs` is the clone-divergence sweep over the hand-copied type families (sets, arities, ranges, EF registrations), and `clone-waivers.json` explains every divergence it finds between siblings that is right as it is. `Oracle*Tests` and `CloneDivergenceTests` in the conventions project hold all of it consistent in CI without building; `dotnet run tools/oracles.cs seeds` re-proves locally that every seed is caught, `… status` prints the worklist, `… pg-surface` regenerates the listing from a container, `… clones` prints the sibling divergences with their waiver status
- `tools/oracles.cs` — The local prover and status report for `test/oracles/`; file-based app, never run in CI
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Some calls answer differently: [Changed answers in 10.5.0](https://github.com/Ca

- JSON: a property declared as `IRangeFactory<TRange, T>` or `IValueSetFactory<TSet, T>` is written as the range's literal or the set's array, where it was written as `{}` with no error. Reading into one still throws `NotSupportedException` ([#581](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/581), [Migration](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/migration.md#check-json-for-a-property-declared-as-a-factory-interface)).

### Added

- Docs: a schema filter for Swashbuckle, to copy into your API, describes a range, range set or value set as it is sent, as the transformer for `Microsoft.AspNetCore.OpenApi` does ([Swashbuckle](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#swashbuckle), [#49](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/49)).

### Fixed

- Docs: MVC doesn't bind a range set from a header, since it splits the header at commas, and the guide said header parameters were fine. A minimal API binds it; in MVC, take the header as a `string` and call `Parse` ([Bind a range from configuration](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#bind-a-range-from-configuration), [#611](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/611)).
Expand Down
88 changes: 88 additions & 0 deletions docs/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,91 @@ Good to know:
- **An element type with its own `[JsonConverter]` keeps its own schema.** A wrapper element with
its own converter is described by whatever that element's schema is. That is again `{}`, unless
you describe it too.

### Swashbuckle

Swashbuckle (`Swashbuckle.AspNetCore`) describes a type from its public properties. A range comes
out as an object of its properties, and a value set as an object with `values`, `count` and
`isEmpty`. None of that is what the API sends.

Copy this schema filter into your API project instead. It gives each type the same schema as the
transformer above. This repository compiles and tests it, verbatim, against Swashbuckle 10:

```csharp
using CodoMetis.ValueRanges.Core;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

/// <summary>
/// Describes CodoMetis.ValueRanges types in Swashbuckle's OpenAPI document as they appear on the
/// wire. Without it a range, multirange or value set is described as an object with the type's
/// properties, which is not what the API sends. Register it with
/// <c>builder.Services.AddSwaggerGen(o => o.SchemaFilter&lt;ValueRangesSchemaFilter&gt;());</c>
/// </summary>
public sealed class ValueRangesSchemaFilter : ISchemaFilter
{
// Mirrors what the parsers accept: surrounding whitespace, "empty" in any case, quoted bounds.
private const string RangePattern = @"^\s*([Ee][Mm][Pp][Tt][Yy]|[\[(][\s\S]*,[\s\S]*[\])])\s*$";
private const string MultirangePattern = @"^\s*\{[\s\S]*\}\s*$";

public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
// The properties are only mutable on the concrete type.
if (schema is not OpenApiSchema target) return;

if (context.Type.IsGenericType && context.Type.GetGenericTypeDefinition() == typeof(RangeSet<,>))
{
var element = context.Type.GetGenericArguments()[1];
Replace(target, JsonSchemaType.String);
target.Pattern = MultirangePattern;
target.Description = $"A PostgreSQL multirange literal over {element.Name}: ranges in braces, "
+ "e.g. {[1,5],[7,10]}, or {} for none.";
}
else if (FactoryElement(context.Type, typeof(IRangeFactory<,>)) is { } rangeElement)
{
Replace(target, JsonSchemaType.String);
target.Pattern = RangePattern;
target.Description = $"A PostgreSQL range literal over {rangeElement.Name}: [ ] include a bound, "
+ "( ) exclude it, an omitted bound is unbounded, e.g. [1,10) or [5,); "
+ "or 'empty'.";
}
else if (FactoryElement(context.Type, typeof(IValueSetFactory<,>)) is { } setElement)
{
Replace(target, JsonSchemaType.Array);
target.UniqueItems = true;
target.Items = context.SchemaGenerator.GenerateSchema(setElement, context.SchemaRepository);
target.Description = $"A set of distinct {setElement.Name} values.";
}
}

// Swashbuckle describes the type from its public properties, or a range set as a list of ranges;
// none of that is on the wire.
private static void Replace(OpenApiSchema schema, JsonSchemaType type)
{
schema.Type = type;
schema.Items = null;
schema.Properties = null;
schema.Required = null;
schema.AdditionalProperties = null;
schema.AdditionalPropertiesAllowed = true;
}

// A range variant (DateRange.Finite, …) inherits its union's IRangeFactory, so it is described too.
private static Type? FactoryElement(Type type, Type openFactory)
=> Array.Find(type.GetInterfaces(), i => i.IsGenericType && i.GetGenericTypeDefinition() == openFactory)
?.GetGenericArguments()[1];
}
```

Then register it:

```csharp
builder.Services.AddSwaggerGen(o => o.SchemaFilter<ValueRangesSchemaFilter>());
```

Good to know:

- **The patterns are the transformer's.** A test holds the two to the same text, so both generators
accept the same literals.
- **Query, route and header parameters need nothing.** They bind through `TryParse`, as with
ASP.NET Core's own generator.
4 changes: 4 additions & 0 deletions src/CodoMetis.ValueRanges/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Some calls answer differently: [Changed answers in 10.5.0](https://github.com/Ca

- JSON: a property declared as `IRangeFactory<TRange, T>` or `IValueSetFactory<TSet, T>` is written as the range's literal or the set's array, where it was written as `{}` with no error. Reading into one still throws `NotSupportedException` ([#581](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/581), [Migration](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/migration.md#check-json-for-a-property-declared-as-a-factory-interface)).

### Added

- Docs: a schema filter for Swashbuckle, to copy into your API, describes a range, range set or value set as it is sent, as the transformer for `Microsoft.AspNetCore.OpenApi` does ([Swashbuckle](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#swashbuckle), [#49](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/49)).

### Fixed

- Ranges: `Shift` and `Expand` throw the documented `OverflowException` under every culture when a bound would land on the day that stands for infinity. Under `ar-SA` they threw `ArgumentOutOfRangeException`, because the message formatted the day with the current culture. A message now names a value as its literal text, `9999-12-30` ([#552](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/issues/552)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.14" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.14" />
<PackageReference Include="MSTest" Version="4.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading