Skip to content

OpenApi default number types #64920

@johnnyreilly

Description

@johnnyreilly

Background and Motivation

I've recently been writing up using.NET OpenAPI support combined with openapi-ts:

https://johnnyreilly.com/dotnet-openapi-and-openapi-ts

It's worked out well, but the default choice for numbers, specifically integers seems peculiar:

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

Here an integer is surfaced as an integer or a string. This seems like a surprising choice. It can be worked around with custom IOpenApiSchemaTransformers:

https://johnnyreilly.com/dotnet-openapi-and-openapi-ts#adjusting-microsoftaspnetcoreopenapi-surfaced-types

But it's surprising this is necessary in the first place.

I'm wondering if the default transformers make the most sense? Would they be more useful if they were more along the lines of the customised examples in my post?

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-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