Fixing Kiota integer properties generated as UntypedNode
On this page3 sections ▾
After upgrading from .NET 9 to .NET 10 and regenerating my Kiota client, integer properties started appearing as UntypedNode instead of int or int?. The API still built, but the generated client types had changed.
Setting JsonNumberHandling.Strict resolved the integer schema in this case. That setting also changes which JSON values the API accepts, so check existing clients before applying it.
Here's the warning I was seeing during generation:
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/components/schemas/OrderSummary/properties/totalItems -
The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.#The root cause
ASP.NET Core's web defaults for System.Text.Json allow reading numbers from strings. It accepts both:
42(an actual number)"42"(the same value as a string)
Because of that, the ASP.NET Core OpenAPI generator produces a schema that looks like this:
"totalItems": {
"type": ["integer", "string"],
"format": "int32"
}It's saying "this can be an integer OR a string".
That union type and format combination caused the Kiota generation problem. The warning and generated fallback can differ between versions, so compare the schema with the client output.
#Configure number handling
I first tried an IOpenApiDocumentTransformer that replaced the union types with integer types. It became difficult to maintain across nested objects and arrays. Kiota issue #6541 led me to the number-handling setting behind the schema.
The schema reflects the configured serializer behaviour: accepting both strings and numbers produces a union type. Microsoft's OpenAPI metadata documentation describes how AllowReadingFromString and Strict map numeric types.
To require JSON numbers, set NumberHandling to Strict.
For the HTTP JSON options used by Minimal APIs and OpenAPI generation, add this where you configure services:
builder.Services.ConfigureHttpJsonOptions(options =>
{
// Use strict number handling to prevent ASP.NET Core from generating union types ["integer", "string"]
// for integer properties in OpenAPI schemas. This ensures Kiota generates proper int types.
options.SerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.Strict;
});With that in place, the OpenAPI generator produces a clean integer schema:
"totalItems": {
"type": "integer",
"format": "int32"
}Once you've made that change, restart your API and regenerate your Kiota client. Check that the affected properties now have the expected integer types.
#Keep the runtime and schema consistent
ConfigureHttpJsonOptions configures the HTTP JSON options. MVC controllers have separate options through AddControllers().AddJsonOptions(...); set JsonSerializerOptions.NumberHandling there too if those controllers should enforce the same contract. Microsoft documents the two option scopes.
Where strict handling applies, clients sending strings such as "id": "123" will need to send numbers such as "id": 123. Regenerate the OpenAPI document and Kiota client, inspect the property types, and test representative requests before treating the change as complete.