autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Is it possible to include/exclude paths/operations + models?

Open jmerkow opened this issue 2 years ago • 4 comments

I am using autorest to generate a c# client for an application our group is building. We are actually using only a small subset of endpoints/models defined in the api spec.

Ideally, we'd like to pick the endpoints we want to use, then trim the models to only include those that are needed by those endpoints. Is anything along those lines possible?

jmerkow avatar Mar 08 '22 22:03 jmerkow

You can use directives to remove operations See docs

there is a set of built-in directives which might be useful remove-operation in particular.

timotheeguerin avatar Mar 09 '22 00:03 timotheeguerin

You can use directives to remove operations See docs

there is a set of built-in directives which might be useful remove-operation in particular.

Is it possible to automatically prune models not used in the current operations? Or is it possible to list the models used by an operation (including nested models). Or anything else that could help me safely delete a large number of models/operations?

jmerkow avatar Mar 11 '22 17:03 jmerkow

There currently isn't a way to remove unused models. One of the issue is that a spec could have unreferenced models that aren't really unused. In Swagger 2.0 as you couldn't do oneOf the workaround would just to have the definitions there(unreferenced) and mark the type as any but you do need those definitions to be in the generated SDK.

This is maybe a feature we could look into adding as a toggle but not planned right now.

timotheeguerin avatar Mar 11 '22 17:03 timotheeguerin

somewhat related: https://github.com/Azure/autorest/issues/4456

this would also help us in an API first process, because the API that the swagger defines is not necessarily implemented by a single service, so it would be great to pick and choose/ slice the operations and models to include in a generation without having to split the swagger files accordingly

serbrech avatar Mar 31 '22 04:03 serbrech