Azure / autorest.csharp

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

Support properties named "Type" #4143

Open hmmorales opened 10 months ago

hmmorales commented 10 months ago

I am receiving this error when I am trying to execute dotnet build /t:GenerateCode to generate my resource provider dotnet sdk for the first time.

fatal   | System.InvalidOperationException: ReconciliationPolicy has a property named "Type" which is not allowed. Please use "x-ms-client-name" to rename the property for the client.

This property name is already checked into azure-rest-api-specs https://github.com/Azure/azure-rest-api-specs/blob/main/specification/iotoperationsorchestrator/IoTOperationsOrchestrator.Management/common.tsp and is in public preview. Renaming this would result in a breaking change. Can the property name 'Type' be supported?

lirenhe commented 10 months ago

@hmmorales, are you using TypeSpec or Swagger to define your APIs?
The above suggestions like using "x-ms-client-name" would only change the client API signature instead of impacting service APIs.

cc @live1206

hmmorales commented 10 months ago

@lirenhe we are using TypeSpec

live1206 commented 10 months ago

For now, .NET management-plane SDK still generates from swagger files. So, even you have TypeSpec, the generated swaggers are still in place for .NET SDK generation. Please check how to rename property name in autorest.md https://github.com/Azure/autorest.csharp/blob/feature/v3/docs/mgmt/polishing.md#rename-a-property-in-a-class

hmmorales commented 10 months ago

Thank you @live1206 for the link to the doc that helped unblock me with re-naming the type. I am hitting another issue now where it seems like the .NET SDK generation tool is failing from duplicate schemas. Do you have a fix for this I can apply in the autorest.md? We currently don't have x-ms-client-name on that property image

live1206 commented 10 months ago

@hmmorales I assume you have some types sharing the same name, you can rename the type to a different name in autorest.md, refer to https://github.com/Azure/autorest.csharp/blob/feature/v3/docs/mgmt/polishing.md#rename-a-type.