There is no way to specify a mapping from REST API property names to client names
Sometimes the names we use in the REST API are not really ideal for the client libraries. Consider the case of Boolean properties. In .NET client libraries, the convention is to start Boolean property names with a prefix like "Is" or "Has". However, you wouldn't really want to clutter up a JSON REST API with these prefixes. For example, a property named "searchable" in the REST API ought to be named "IsSearchable" in the .NET client.
As another example, consider the OData V4 parameter $count. It's a Boolean parameter that indicates whether to include the total count of results of an OData query in each page of results. However, the name is not very suggestive. In a client library a more descriptive name like "IncludeTotalCount" might be more appropriate. In this case, the choice of name in the REST API is imposed by the OData protocol, so renaming it for the sake of a better client SDK experience is not an option (for a REST API with non-trivial production usage, renaming things is rarely a realistic option).
I believe this is an opinion which could be taken by the .Net code generator. It certainly seems more idiomatic to approach naming booleans in this way.
To recap our offline discussion: It's difficult in general to do the right thing for Boolean prefixes (sometimes you want "is", sometimes "has", sometimes "should", etc.). The most robust solution is to allow mapping source names to target names. Since Swagger doesn't support this today, this is not a quick fix. However, I would argue that this makes Swagger substantially less useful for mapping existing REST APIs (i.e. -- APIs that weren't designed with Swagger in mind) to a client programming model.
Can we at least make sure that workarounds exist in each of the target languages? For example, generated C# code uses partial classes so I can always omit properties from the Swagger spec that I want to rename, and rename them in the C# code. This isn't great, but it's better than making a bunch of pointless breaking changes to our client library.
To add one more example of where re-naming properties would be useful: Consider a "List" operation like GET /indexes. We're required by OData to return JSON that looks like this:
{
value: [
{ "name": "abc", ... },
...
]
}
But now we end up with a method that returns an object with a property named "Value" instead of something more semantically meaningful like "Indexes".
One more real-world example: A part of our API is going to be a pass-through for part of another REST API that we don't control. It has property names that use underscores, max_length and word_list. We can't change this API, but we'd still like to be able to generate model classes for it and map the names to PascalCase/camelCase (depending on target language).
Proposal to add "x-ms-client-name" extension
@devigned @stankovski is there any update/ETA on this functionality being incorporated into the generator? Some of our customers are starting to complain about the large amount of refactoring they are needing to do from our existing Hydra clients to the new Swagger clients due to all the property renaming from our swagger specs since we can't define a friendly name.
x-ms-client-name extension has been added to the master branch. Please take a look at the documentation over here: https://github.com/Azure/autorest/blob/master/Documentation/swagger-extensions.md#x-ms-client-name
@begoldsm this was merged recently https://github.com/Azure/autorest/pull/801 and described here: https://github.com/Azure/autorest/blob/master/Documentation/swagger-extensions.md#x-ms-client-name. Does this solve the issue @begoldsm and @brjohnstmsft?
Awesome thanks @amarzavery and @devigned! I am trying it out now and will let you know if it works.
@devigned please change the milestone for this issue to reflect the release it will go into and close if this has already been implemented
I won't have a chance to try it out for a while, but from the docs it looks like exactly what we need. Thanks!
x-ms-client-name works as advertised. Closing this issue. Thanks!
Agreed with @brjohnstmsft this is working and a great addition! Thank you very much!