Skip to content

Incorrect OpenAPI generation #63460

@johnkors

Description

@johnkors

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The OpenAPI generator does not generate item-types when multiple arrays have the same type:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();

app.MapOpenApi();

app.MapGet("/", () => TypedResults.Ok(new SomeType(
  SubtypesOne: [new SomeSubType(1, "First"), new SomeSubType(2, "Second")],
  SubTypesTwo: [new SomeSubType(3, "Third")])
));

app.Run();

public record SomeType(SomeSubType[] SubtypesOne, SomeSubType[] SubTypesTwo);

public record SomeSubType(int Id, string Name);

Even though SubtypesOne and SubtypesTwo are of the same type SomeSubtype[], only the first member gets a valid type generated in the spec json:

            "SomeType": {
                "required": [
                    "subtypesOne",
                    "subTypesTwo"
                ],
                "type": "object",
                "properties": {
                    "subtypesOne": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/SomeSubType"
                        }
                    },
                    "subTypesTwo": {
                        "type": "array",
                        "items": {}
                    }
                }
            }

Expected Behavior

I would have expected both subTypesOne and subTypesTwo to emit identical $ref entries for both arrays.

                    "subTypesTwo": {
                        "type": "array",
-                        "items": {}
+                        "items": {
+                            "$ref": "#/components/schemas/SomeSubType"
+                        }
                    }

Steps To Reproduce

Repro:
https://github.com/johnkors/aspnetcore-openapi-repro-bug/

Run the project, and open http://localhost:5121/openapi/v1.json

Exceptions (if any)

No response

.NET Version

9.0.303

Anything else?

Running on .NET 9 and referencing Microsoft.AspNetCore.OpenApi/9.0.8.

Runtime: Microsoft.NETCore.App 9.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-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