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

Multiple APIs in the same project

Open HJK181 opened this issue 1 year ago • 4 comments

Very nice lib, thank you for spending time on this.

I'm using the lib in an Expo project, where I call a Gateway application which routes requests to multiple backend services. Is it possible to create separate clients for those backends?

Atm. I have "codegen": "openapi-rq -i http://localhost:8082/v3/api-docs --base http://localhost:8080/svc/a -c axios --format prettier ", which is generating the code for the service behind port 8082, with a base URL pointing to service a. How could I add another service here? My main problem is that creating a second service will create second static OpenAPI object which I have to configure identically to the one from service a.

HJK181 avatar Jul 02 '24 07:07 HJK181

@HJK181

Is it possible to generate code for each service using the --output option?

a:

openapi-rq -i http://localhost:8082/v3/api-docs --base http://localhost:8080/svc/a -c axios --format prettier  --output openapi-a

b:

openapi-rq -i http://localhost:8082/v3/api-docs --base http://localhost:8080/svc/b -c axios --format prettier  --output openapi-b

7nohe avatar Aug 06 '24 14:08 7nohe

@HJK181

Is it possible to generate code for each service using the --output option?

a:

openapi-rq -i http://localhost:8082/v3/api-docs --base http://localhost:8080/svc/a -c axios --format prettier  --output openapi-a

b:

openapi-rq -i http://localhost:8082/v3/api-docs --base http://localhost:8080/svc/b -c axios --format prettier  --output openapi-b

But this gives me two static OpenAPI objects in two folder’s right? Than, I have to set the same bearer token and interceptors on two independent objects instead of one?

HJK181 avatar Aug 06 '24 19:08 HJK181

@HJK181 Perhaps the exportCore option from @hey-api/openapi-ts could be useful. Try generating OpenAPI.ts with exportCore=true once, and then run it with exportCore=false afterwards. OpenAPI.ts won't be overwritten. By exporting the same object, you should be able to use it across multiple services.

In this library, the exportCore option is fixed to true, so I need to fix it.

7nohe avatar Aug 07 '24 00:08 7nohe

Will this be fixed in the next major version?

bryanjtc avatar Nov 10 '24 00:11 bryanjtc