Haskell-OpenAPI-Client-Code-Generator icon indicating copy to clipboard operation
Haskell-OpenAPI-Client-Code-Generator copied to clipboard

Allow custom record field prefix

Open turion opened this issue 9 months ago • 4 comments

It would be great if one could prefix the generated record field names. I wrote some template haskell to call makeLenses (from the lens package) for all record types, but a typical naming scheme is data MyRecord = MyRecord { _myRecordFieldName :: T }, which would generate a lens myRecordFieldName :: Lens' MyRecord T. This naming scheme is not possible with the generated code here.

turion avatar May 05 '25 10:05 turion

I don't mind not supporting this because I think lenses are not a good idea, but if you really want to make this possible then I'll review the PR.

NorfairKing avatar May 05 '25 12:05 NorfairKing

I don't mind not supporting this because I think lenses are not a good idea

Ah, that's interesting, can you elaborate? Maybe I'm on the wrong track design-wise. My use case is a deeply nested complex JSON structure that I retrieve via an API, where I need to query many different parts a few levels deep. Lenses seem like the natural choice for this. In particular, traversals over Nullable fields, and arrays.

but if you really want to make this possible then I'll review the PR.

Thanks!

turion avatar May 12 '25 07:05 turion

Ah, that's interesting, can you elaborate? Maybe I'm on the wrong track design-wise. My use case is a deeply nested complex JSON structure that I retrieve via an API, where I need to query many different parts a few levels deep. Lenses seem like the natural choice for this. In particular, traversals over Nullable fields, and arrays.

Lenses are for getting AND setting. If you are only getting, just use selector functions, map, etc.

NorfairKing avatar May 12 '25 09:05 NorfairKing

Fair point, for the receiving side of the request. I forgot to mention though that the POST request is also a deeply nested JSON structure that I need to edit before sending. Since the types are also generated, lenses would be really helpful.

turion avatar May 30 '25 09:05 turion