autorest.typescript icon indicating copy to clipboard operation
autorest.typescript copied to clipboard

[v6] Declarative way to avoid name case conversion

Open joheredi opened this issue 4 years ago • 3 comments

Currently, if we need to keep a name as described in the swagger that doesn't conform to modeler four namer config, for example if we want a property key_ops in the generated code, to avoid the generator making it keyOps we'd need to set a complex transform (see example)

directive:
  - from: swagger-document
    where: $.definitions.JsonWebKey.properties.key_ops
    transform: >
      $["x-ms-client-name"] = "key_ops_keep_snakecase";

modelerfour:
  naming:
    override:
      key_ops_keep_snakecase: $DO_NOT_NORMALIZE$key_ops

I think this can be improved in 2 different ways

  1. Have a new extension in the Swagger x-ms-keep-name which if set to true, M4 would not pass it through the namer.
  2. Even if we don't implement the new extension, if we stop doing custom case conversion in autorest.typescript (see this comment for context) I think we could reduce the transform to the following?
modelerfour:
  naming:
    override:
      key_ops: key_ops

joheredi avatar Oct 22 '21 14:10 joheredi

I think option 1 would provide a better experience overall since it could be set in the swagger which would remove the need for any transforms at all. This would probably be interesting for other languages as well

joheredi avatar Oct 22 '21 14:10 joheredi

It took me a lot of time to arrive at this thread. It would be great if this was documented better in the official docs. My config looked like this:

modelerfour:
  lenient-model-deduplication: true
  naming: 
    override:
      _id: _id

And I was frustrated that it is not working. After reading this thread, I changed it to:

modelerfour:
  lenient-model-deduplication: true
  naming: 
    override:
      _id: $DO_NOT_NORMALIZE$_id

And it works!

https://github.com/Azure/autorest.typescript/issues/1546

MarcErdmann avatar Sep 05 '22 09:09 MarcErdmann

Thanks for the feedback @MarcErdmann.

@sarangan12, would you mind adding this to the documentation?

joheredi avatar Sep 26 '22 20:09 joheredi