Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
140 stars 160 forks source link

Examples being generated even if operation is suppressed #4120

Closed nisha-bhatia closed 5 months ago

nisha-bhatia commented 5 months ago

Examples are still generated after the operation that they use is suppressed.

For example, in the following Swagger: I suppress the Subscription operations by doing:

Remove subscription scoped operations

directive:
  - remove-operation: MetricDefinitions_ListAtSubscriptionScope
  - remove-operation: Metrics_ListAtSubscriptionScope
  - remove-operation: Metrics_ListAtSubscriptionScopePost

But the examples using the MetricDefinitionsClient are still being generated: image If we don't have the client - we shouldn't be generating the samples. There is currently no way to not generate the examples using Autorest.

ArcturusZhang commented 5 months ago

Please open a draft PR in azure-sdk-for-net repo with all the problematic changes and put its link in this issue so that we could reproduce the issue and troubleshoot. I assume you met this issue when you are trying to migrate your HLC package to DPG because HLC packages do not generate samples like this.

nisha-bhatia commented 5 months ago

Thank you Dapeng for your response. I made a draft PR for the code, the sample file can be found here. This is an HLC client and we are not migrating to DPG - Monitor Query been an HLC for several GAs so I'm not sure where the sample files are coming from. The updated autorest files with the Swagger files can be found here. Please let me know if you need anything else. Thank you!

ArcturusZhang commented 5 months ago

Those files are generated by DPG generator only. You must have mistakenly enabled DPG and then disabled it. Because the autorest generator only cleans up files in src/Generated directory, those files in tests/Generated will not be cleaned up, which makes an illusion that the generator is always generating those files. You just need to manually remove those files, and everything should be fine. Closing the issue