orval icon indicating copy to clipboard operation
orval copied to clipboard

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

Open AndyRightNow opened this issue 11 months ago • 2 comments

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

AndyRightNow avatar Dec 03 '24 13:12 AndyRightNow

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

soartec-lab avatar Dec 05 '24 10:12 soartec-lab

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.

AndyRightNow avatar Dec 05 '24 12:12 AndyRightNow