-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base url handling issue #2
Comments
The version is ^0.1.2 |
vladkens
added a commit
that referenced
this issue
Sep 3, 2024
vladkens
added a commit
that referenced
this issue
Sep 3, 2024
@gaohoward Hi. Thanks for the issues. URL resolving depends on the behavior of the new URL constructor, so I can't change at the level of current interfaces (might break backwards compatibility somewhere). Instead I added the ability to override endpoint build logic (kind of hook). class MyClient extends ApiClient {
PrepareFetchUrl(path: string) {
return new URL(`${this.Config.baseUrl}/${path}`.replace(/\/{2,}/g, "/"))
}
}
const api = new MyClient({ baseUrl: "https://example.com/v1" })
// will call: https://example.com/v1/pet/ instead of https://example.com/pet/
const pet = await api.pet.getPetById(404) I hope this helps you. Released as version |
Thank you @vladkens ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I'm trying out apigen-ts to generate the client for an api-server but I got problem running it.
The openapi def is here
https://github.com/artemiscloud/activemq-artemis-jolokia-api-server/blob/main/src/config/openapi.yml
After generation, in my code I do
Then I invoke one of the api method
I got 404 error. The reason seems to be in the generated client code the fetch url is not correctly formed
For example if my api-server listens on https://localhost:9443, the baseUrl I passed in ApiClient is
https://localhost:9443/api/v1/
, inside the client code when handling the method call, it uses URL constructorconst url = new URL('/api-info', 'https://localhost:9443/api/v1/')
It turns out the new url removed the path from base url before appending the path (
/api-info
), like this(new url) https://localhost:9443/api-info
but the correct url should be
https://localhost:9443/api/v1/api-info
.The text was updated successfully, but these errors were encountered: