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

Feature Request: support removing unused schemas based on refs in paths #1734

Open
AndyRightNow opened this issue Dec 3, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@AndyRightNow
Copy link

AndyRightNow commented Dec 3, 2024

What happens?

After a bunch of filtering, excluding and transforming, only parts of the original paths would be preserved and some schema definitions become irrelevant and stale after the referencing paths have been filtered out.

What were you expecting to happen?

  1. There should be a configurable property in the output section of the config to specify whether or not to remove unused schemas.
  2. If set to true, unused schemas will not be generated to the output file.
  3. Note that the resolution should be traced exhaustively.

Any logs, error output, etc?

None.

Any other comments?

For now, this can probably be implemented in input.override.transformer, but it's not efficient if every time a user wants the feature, they would need to implement it by themselves. On second thought, it's actually not practical because it might have conflicts with other filtering features of the tool.

On top of that, if you think it's a desirable feature to add, I can help open a PR for it.

What versions are you using?

7.3.0

@melloware melloware added the enhancement New feature or request label Dec 3, 2024
@soartec-lab
Copy link
Member

Thank you for your suggestion. Could you please provide a minimal concrete case so that I can refine my understanding?

@AndyRightNow
Copy link
Author

AndyRightNow commented Dec 5, 2024

Thank you for your suggestion. Could you please provide a minimal concrete case so that I can refine my understanding?

Hi @soartec-lab here is a minimal demo https://stackblitz.com/edit/stackblitz-starters-hcjqq8?view=editor

The directory src/types/complete is a pet store swagger output without any filters, and the directory src/types/partial is one with an input transformer and some filters.

In src/types/partial, only 2 APIs get generated and based on the import trace, only these schemas are used in the resolution paths of these 2 APIs:

{
  FindPetsByStatusParams,
  FindPetsByTagsParams,
  FindPetsByStatusStatus,
  Pet,
  Category,
  PetStatus
}

On the contrary, all other schemas in components have been generated.

On top of that, I also specifically excluded a schema Customer which references another schema Address. After it's filtered out, Address has essentially no reference anywhere else so it becomes a dangling definition.

The ideal behavior is that all the unused schemas should be left out.

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

No branches or pull requests

3 participants