Skip to content

Microsoft.AspNetCore.OpenAPI v10 sets no type for components #64797

@cheesi

Description

@cheesi

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a simple type like:

public record TestObject
{
    public int Number32 { get; set; }
}

And an API Controller:

[ApiController]
public class TestController : ControllerBase
{
    [HttpGet("/test")]
    public ActionResult<TestObject> Get() => new TestObject { Number32 = 1 };
}

And a Program.cs according to the default template, but set the OpenAPI Version to 3.0. Full repro: https://github.com/cheesi/OpenApi-Test-pattern-behaviour

This generates the following OpenAPI specification:

{
  "openapi": "3.0.4",
  "info": {
    "title": "OpenApi-Test | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5261/"
    }
  ],
  "paths": {
    "/test": {
      "get": {
        "tags": [
          "Test"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/TestObject"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestObject"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/TestObject"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TestObject": {
        "type": "object",
        "properties": {
          "number32": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "format": "int32"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Test"
    }
  ]
}

The TestObjectnow only contains a format, but no type any more. This is in accordance with the OpenAPI specification 3.0.4:

This means JSON Schema keywords and formats do NOT implicitly require the expected type. Use the type keyword to explicitly constrain the type.

This is however not in accordance with previous OpenAPI Versions from the 3.0.X series: https://spec.openapis.org/oas/v3.0.3.html#data-types

The missing type information can cause problems with other tooling. For example https://github.com/OpenAPITools/openapi-generator does really not like, that there is no type and is generating many any types for our TypeScript client.

Expected Behavior

"TestObject": {
  "type": "object",
  "properties": {
    "number32": {
      "type": "integer",
      "format": "int32"
    }
  }
}

Ideally:
Option to include the type parameter (or an OpenApiSpecVersion of 3.0.3, as they really seem to like doing breaking changes with minor and now even patch versions?)
(Or just include the type parameter by default, because it is not forbidden, simply not required anymore - so it would not be a breaking change any more)

Or list it as a breaking change here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/breaking-changes

Steps To Reproduce

Repro: https://github.com/cheesi/OpenApi-Test-pattern-behaviour

Exceptions (if any)

No response

.NET Version

10.0.100

Anything else?

Microsoft.AspNetCore.OpenApi 10.0.1

.NET SDK:
Version: 10.0.100
Commit: b0f34d51fc
Workload version: 10.0.100-manifests.4c0ca8ba
MSBuild version: 18.0.2+b0f34d51f

Runtime Environment:
OS Name: Mac OS X
OS Version: 26.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/10.0.100/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0
Architecture: arm64
Commit: b0f34d51fc

.NET SDKs installed:
8.0.201 [/usr/local/share/dotnet/sdk]
9.0.101 [/usr/local/share/dotnet/sdk]
10.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.20 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions