autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Code-generation-friendly names

Open NiklasGustafsson opened this issue 10 years ago • 3 comments

Much can, and is, done through convention to make named used in Swagger specifications “code friendly” when they need to be exposed in generated client code. For example, a parameter name like ‘blobType’ can easily be generated as ‘BlobType’ for C# or PHP, ‘blobType’ for Java, Go, or JavaScript, or as ‘blob_type’ for Ruby or C++.

However, there are also situations, particularly for header parameters, where it is harder to do so. For example, what convention tells the code generator how to handle a name like ‘x-ms-lease-id,’ a value that the storage APIs require the caller to explicitly pass in when it is needed. How does the code generator know not just to replace the dashes, but also to remove the ‘x-ms-‘ prefix? And is ‘leaseId’ the best client name? It would make sense to give developers some control over the “code friendly” name used for code generation through a vendor extension.

Something like:

"ApiVersionParameter": { "name": "x-ms-version", "x-ms-client-name": "version", "in": "header", "required": false, "type": "string", "enum": [ "2015-04-05", "2014-02-14", "2013-08-15", "2012-02-12", "2011-08-18", "2009-09-19", "2009-07-17", "2009-04-14" ], "default": "2015-04-05" }

NiklasGustafsson avatar Mar 03 '16 16:03 NiklasGustafsson

Duplicate https://github.com/Azure/autorest/issues/316

bitsforthought avatar Mar 05 '16 22:03 bitsforthought

This is a good example of enums that should also be supported by x-ms-client-name.

stankovski avatar Mar 14 '16 19:03 stankovski

The PR https://github.com/Azure/autorest/pull/801 has been merged.

amarzavery avatar Mar 15 '16 02:03 amarzavery