openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

operationFetcherFnName naming

Open mhaagens opened this issue 3 years ago • 2 comments

Great library! Is there any way to change the operationFetcherFnName? Ideally I'd like to export getMyDataType as a fetch component and useGetMyDataType as a react-query component.

mhaagens avatar Oct 03 '22 11:10 mhaagens

hi @mhaagens it is currently hardcoded

https://github.com/fabien0102/openapi-codegen/blob/13ca9b35ab0bbd363946baf4a015b3e6d317f728/plugins/typescript/src/generators/generateReactQueryComponents.ts#L146

but, I think we can expose it to configuration for better DX. Something like fetchFnPrefix

This is also kinda related with https://github.com/fabien0102/openapi-codegen/issues/80

needim avatar Oct 06 '22 21:10 needim

But, I can offer you an ugly trick to do that without waiting for the implementation.

on openapi-codegen.config.ts file after all the generation has done.

You can read the generated file with

let content = fs.readFileSync('___actualPathOfTheSchemas___/xxxSchemas.ts').toString()

do some regex replacement on it. (you have 2 places to replace) ***put some regex magic here***

and write it back.

fs.writeFileSync('___actualPathOfTheSchemas___/xxxSchemas.ts', ___replacedContent___);

needim avatar Oct 06 '22 21:10 needim