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

Not so nice behavior when generating client with trim-unused-schema #557

Open
kirides opened this issue Dec 10, 2024 · 6 comments
Open

Not so nice behavior when generating client with trim-unused-schema #557

kirides opened this issue Dec 10, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@kirides
Copy link
Contributor

kirides commented Dec 10, 2024

Describe the bug
A bunch of "Anonymous" classes get generated.

This is due to the SchemaCleaner not handling DiscriminatorObject.Mapping

Now we have two ways to solve it:

  1. always include all "sum type" instances. This leads to more unused schema being generated.
  2. remove trimmed-schema from the DiscriminatorObject.Mapping, leading to less generated code

@christianhelle What would you prefer?
Always generate full inheritance hierarchy/sum types or remove the unused discriminated values?

OpenAPI Specifications

a snippet of the issue causing schema:

{
  "SomeContract": {
    "allOf": [
      {
        "$ref": "#/components/schemas/ContractBase"
      },
      {
        "type": "object",
        "discriminator": {
          "propertyName": "$type",
          "mapping": {
            "A": "#/components/schemas/A",
            "B": "#/components/schemas/B",
            "C": "#/components/schemas/C"
          }
        },
        "x-abstract": true,
        "additionalProperties": false,
        "required": ["$type"],
        "properties": {
          "$type": {
            "type": "string"
          }
        }
      }
    ]
  }
}

Additional context
Add any other context about the problem here.

@kirides kirides added the bug Something isn't working label Dec 10, 2024
@christianhelle
Copy link
Owner

@kirides removing unused discriminated values sounds better. You had me at "less generated code" 😄

@kirides
Copy link
Contributor Author

kirides commented Dec 10, 2024

Possible issues include a fully abstract endpoint that returns SomeContract would not generate all possibly returned types, same with input parameters.

@christianhelle
Copy link
Owner

@kirides Could we perhaps provide an option to use one or the other?

@kirides
Copy link
Contributor Author

kirides commented Dec 10, 2024

Best would be some kind of Per-Operation configuration overrides, but that doesn't exist yet.

A simpler "KeepDiscriminatedSchema" would be a one or none switch to support 1. & 2. Globally.

Before going into PR i'd like a suggestion which direction to head into ;)

@christianhelle
Copy link
Owner

@kirides I can't see myself using a per-operation configuration override, and in scenarios where I would see this, the entire OpenAPI spec would be full of these examples. I'm of course, speaking only for myself

I would, personally, go for a one-or-none switch to support scenario 1 or 2

@kirides
Copy link
Contributor Author

kirides commented Dec 24, 2024

I've got some code to do that.

Will open a PR after holidays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants