Skip to content

Generation of OpenApi document conflicts with Kiota's expectations #64501

@somnatic

Description

@somnatic

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've been doing some tests with .NET10, OpenApi and Kiota recently and stumbled upon something that seems odd. I cannot really consider it a bug but it's something I would like to point out. If this is by design, that's ok with me as well.

I have put together a fully working demo here: https://github.com/somnatic/openapi-int32-issue-demo. It's basically the "ASP.NET Core Web API" project template. Not a single line was changed.

This project generates an OpenApi definition with the following definition for temperatureC (the full document is also in the Github project):

          "temperatureC": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "integer",
              "string"
            ],
            "format": "int32"
          },

According to the OpenApi spec this is essentially correct: "can be an integer or a string, needs to follow a specific pattern"

Now, when generating a client with Kiota, Kiota will output the following warning:

warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/components/schemas/WeatherForecast/properties/temperatureC - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.

I can force AddOpenApi using a SchemaTransformer for "int" I can make AddOpenApi generate the following definition which Kiota will perfectly accept.

         "temperatureC": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "integer",
              "string"
            ],
            "format": "int32"
          },

Now basically my question or proposal is: Shouldn't this be the default behavior?

I just hope this question isn't too stupid or the solution too obvious.

Expected Behavior

I'd expect the integer creation as outlined above to be the default

Steps To Reproduce

Project is here:
https://github.com/somnatic/openapi-int32-issue-demo

You can un-comment the TypeTransformer.MapType<int>(new OpenApiSchema {Type = JsonSchemaType.Integer, Format = "int32"}); to see what happens if we force the creation of a normal int type.

Exceptions (if any)

No response

.NET Version

10.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions