Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type reference #1995

Closed
fvaillancourt opened this issue Dec 18, 2024 · 2 comments
Closed

Incorrect type reference #1995

fvaillancourt opened this issue Dec 18, 2024 · 2 comments

Comments

@fvaillancourt
Copy link

fvaillancourt commented Dec 18, 2024

Describe the bug
Incorrect type reference returned for certain class (record) structure.

Steps To Reproduce

  1. Create a new ASP.net project with top level statements (.Net 9)
  2. Add Microsoft.AspNetCore.OpenApi 9.0
  3. Replace the code with:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();

var app = builder.Build();
app.MapOpenApi();
app.MapPost("/", (TypeA _) => "Hello World");
app.Run();

public record TypeC(string Id);
public record TypeB(TypeC C);
public record TypeD(TypeB B);
public record TypeA(TypeB B, TypeD D);

Observed behavior
Here is a portion of the file with the offending content. Look at the $ref type.

      "TypeB2": {
        "required": [
          "c"
        ],
        "type": "object",
        "properties": {
          "c": {
            "$ref": "#/components/schemas/#/properties/b/properties/c"
          }
        }
      }

Expected behavior
Not sure yet why we get a TypeB (not shown) and TypeB2, maybe cause here by the bug as it has different type (ref). I would expect the $ref value to be "#/components/schemas/TypeC" and not "#/components/schemas/#/properties/b/properties/c". I am not an OpenApi expert but it does not look like a valid type reference and it fails to parse in all tools I tried.

@max-skimmer
Copy link

Another case of this issue:

public record TypeC(string Id);
public record TypeB(List<TypeC> C);
public record TypeD(List<TypeC> C);
public record TypeA(TypeB B, TypeD D);

Observed behavior
There is no duplicates (like TypeB and TypeB2)
But TypeD now looks as

    "TypeD": {
        "required": [
            "c"
        ],
        "type": "object",
        "properties": {
            "c": {
                "type": "array",
                "items": {
                    "$ref": "#/components/schemas/#/properties/b/properties/c/items"
                }
            }
        }
    }

Expected behavior
The $ref value to be "#/components/schemas/TypeC"

@MaggieKimani1
Copy link
Contributor

Closing this issue as it seems to be a duplicate of #2254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants