Skip to content

[OpenAPI] Duplicated object definitions in openapi spec #62154

Open
@januszj

Description

@januszj

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using two classes as result from minimal api, that are using same class, openapi definition contains two copies of the object for example: WeatherForecast and WeatherForecast2.

"components": {
    "schemas": {
      "WeatherForecast": {
        "required": [
          "date",
          "temperatureC",
          "summary"
        ],
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "temperatureC": {
            "type": "integer",
            "format": "int32"
          },
          "summary": {
            "type": "string",
            "nullable": true
          },
          "temperatureF": {
            "type": "integer",
            "format": "int32"
          }
        },
        "nullable": true
      },
      "WeatherForecast2": {
        "required": [
          "date",
          "temperatureC",
          "summary"
        ],
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "temperatureC": {
            "type": "integer",
            "format": "int32"
          },
          "summary": {
            "type": "string",
            "nullable": true
          },
          "temperatureF": {
            "type": "integer",
            "format": "int32"
          }
        }
      },

I created reproduction sample code.

WebApplication3.zip

Expected Behavior

It should generated schema with one WeatherForecast.

Steps To Reproduce

Run repo project, open scalar and click Download OpenAPI Document

Exceptions (if any)

No response

.NET Version

9.0.5

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