Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
176 stars 75 forks source link

[v6] Declarative way to avoid name case conversion #1211

Open joheredi opened 2 years ago

joheredi commented 2 years ago

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 commented 2 years ago

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

MarcErdmann commented 2 years ago

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

joheredi commented 1 year ago

Thanks for the feedback @MarcErdmann.

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