Skip to content

Commit 8e5ee5d

Browse files
committed
Update OpenAPI config, docs, and NuGet package versions
- Use UseStrictNumericSchemas() in OpenAPI setup for stricter numeric schema generation - Expand README with explanation and example for UseStrictNumericSchemas - Bump Dapper, TinyHelpers, and EF Core Relational package versions in csproj files
1 parent bdfec18 commit 8e5ee5d

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

samples/TinyHelpers.AspNetCore.Sample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
// This helps avoid naming collisions when multiple types have the same name.
7474
// options.UseFullTypeNameSchemaIds();
7575

76-
// Remove the string fallback from numeric schemas generated for OpenAPI.
76+
// Remove the string fallback from numeric OpenAPI schemas (because ASP.NET Core Web JSON defaults to AllowReadingFromString).
7777
options.UseStrictNumericSchemas();
7878
});
7979

src/TinyHelpers.AspNetCore/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ builder.Services.AddOpenApi(options =>
8484

8585
This is particularly useful when you have multiple types with the same name in different namespaces. For example, if you have both `MyApp.Models.User` and `MyApp.DTOs.User`, the default behavior would create a single schema named "User", potentially causing conflicts. With `UseFullTypeNameSchemaIds()`, the schemas will be named "MyApp.Models.User" and "MyApp.DTOs.User" respectively.
8686

87+
- `UseStrictNumericSchemas()`: updates the generated OpenAPI schema for numeric values by removing the `string` fallback that ASP.NET Core emits for numbers, avoiding definitions such as `type: ["integer", "string"]` with a numeric pattern. This makes the published OpenAPI contract clearer for tools and client generators that expect numeric values to be described only as numeric types, but it does not change the runtime behavior of the API:
88+
89+
```csharp
90+
builder.Services.AddOpenApi(options =>
91+
{
92+
options.UseStrictNumericSchemas();
93+
});
94+
```
95+
96+
This transformer is necessary because, by default, ASP.NET Core uses the Web JSON serializer settings, where `NumberHandling = JsonNumberHandling.AllowReadingFromString`. For this reason, OpenAPI always describes numeric values as a union of the numeric type and `string`, to reflect that numbers can also be read from JSON strings at runtime. While technically correct, this representation can lead to less clear schemas and to client generators producing less desirable types, such as `number | string` or `integer | string`, even when you want to expose those values as numeric in the published contract.
97+
98+
Use this transformer when you want to publish a stricter OpenAPI description for numeric schemas, while keeping the existing model binding or JSON serialization behavior unchanged.
99+
87100
**Contribute**
88101

89102
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.

src/TinyHelpers.Dapper/TinyHelpers.Dapper.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Dapper" Version="2.1.72" />
25-
<PackageReference Include="TinyHelpers" Version="3.3.20" />
24+
<PackageReference Include="Dapper" Version="2.1.79" />
25+
<PackageReference Include="TinyHelpers" Version="3.3.21" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

src/TinyHelpers.EntityFrameworkCore/TinyHelpers.EntityFrameworkCore.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="TinyHelpers" Version="3.3.20" />
24+
<PackageReference Include="TinyHelpers" Version="3.3.21" />
2525
</ItemGroup>
2626

2727
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
28-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.26" />
28+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.27" />
2929
</ItemGroup>
3030

3131
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
32-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.15" />
32+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.16" />
3333
</ItemGroup>
3434

3535
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
36-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.6" />
36+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.8" />
3737
</ItemGroup>
3838

3939
<ItemGroup>

0 commit comments

Comments
 (0)