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

Generated schema contains "Record<string, any>" even with "additionalProperties: false" in openapi.json #258

Open
De4dVo1ce opened this issue Jul 2, 2024 · 0 comments

Comments

@De4dVo1ce
Copy link

What problem am I facing?

Background

Hello there,
I'm building an application with a react frontend and C# REST API backend.
In the backend, I'm basically using dtos the following way (simplified):

// PersonDto.cs
public abstract class PersonDto
{
    public required string Name { get; set; }
}

// ChildDto.cs
public class ChildDto : PersonDto
{
}

// AdultDto.cs
public class AdultDto : PersonDto
{
    public required PersonDto[] Children { get; set; }
}

The generated openapi.json looks like this:

{
  "components": {
    "schemas": {
      "AdultDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PersonDto"
          },
          {
            "required": ["children"],
            "properties": {
              "children": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/PersonDto"
                }
              }
            },
            "additionalProperties": false
          }
        ]
      },
      "ChildDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PersonDto"
          },
          {
            "type": "object",
            "additionalProperties": false
          }
        ]
      },
      "PersonDto": {
        "required": ["name"],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    }
  }
}

My openapi-codegen Problem

Now, when I run the code generation with this json, the generated schemas look like this:

export type AdultDto = PersonDto & {
  children: PersonDto[];
};

export type ChildDto = PersonDto & Record<string, any>;

export type PersonDto = {
  name: string;
};

My expectation was:

export type ChildDto = PersonDto;

Questions

Is this the correct behavior or really a bug?
Is there a way to configure this behavior?

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

1 participant