-
Notifications
You must be signed in to change notification settings - Fork 761
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
OpenAPI 3.1.0 support: changing server url #2967
Comments
Hi @transfluxus, Unfortunately the info you provided about the issue is very limited and not really actionable. |
Hi char0n, thanks for getting back.
which works 🥳. However in my application I am forced to use version 3.16.1 |
All right, closing.
Can you elaborate on this? What in #2187 is forcing you to use 3.16.1? I've already provided fix for the regression introduced there in v3.18.1...v3.18.2 |
I cannot tell now, cuz when just again updating the package to 3.19.8, it does not use the right server even if the spec looks ok It is not making the request to the right url (but the local server, since the server array is empty intially) I went into it with the debugger and in the buildRequest function the url is not set from the spec... the problem with lodash was, ... that it was basically not imported, so "get" would be null and it would say something like "schema not found" because it was supposed to get the security schema with lodash get |
@transfluxus thanks for more info. Does it only fail for |
I went deeper with the debugger. It seems that this problem is also related to lodash. Interesting! changing the openapi version to 3.0.3 works! |
All right, thanks for investigation. So it's OpenAPI 3.1.0 related regression. |
After deep investigation, here are my observations: TODO:
Observation 1The reason why it works for you for OpenAPI 3.0.x definition and doesn't for OpenAPI 3.1.0 definition, is that for OpenAPI 3.1.0 swagger-client uses ApiDOM to facilitate URI resolution and dereferencing mechanism. For OpenAPI 2.0 and OpenAPI 3.0.x internal swagger-client specmap mechanism is used for URI resolution and dereferencing. Part of OpenAPI 3.1.0 dereferencing is using something called normalization. For servers specifically it normalizes overrides defined by the OpenAPI 3.1.0 spec:
Now legacy Observation 2Your async function make_client() {
return await SwaggerClient("http://localhost:9999/localcontextshub_openapi.json");
} SwaggerClient fetches the definition for you and resolve it. Unless your definition is behind some authentication, this is all you need to do. Observation 3You're mutating the resolved spec, to achieve sending requests to proper server. swaggerClient.spec.servers = [
{
"url": "https://localcontextshub.org"
}
] You shouldn't do this. Rather when making request you should use swaggerClient.execute({
operationId: "projects_list",
server: "https://localcontextshub.org",
}).then(response => {
console.log(response)
}, error => {
console.error(error)
}) Now with this assumes that the URL In your particular case, assuming you want to send request against any arbitrary server, not just one defined in {
"servers": [
{"url": "https://ridagop.net"},
{"url": "/"}
]
} Now this allows you to perform making request against arbitrary URL: swaggerClient.execute({
operationId: "projects_list",
server: '/',
contextUrl: "https://httpbin.org",
}).then(response => {
console.log(response)
}, error => {
console.error(error)
})
Created an issue with OpenAPI spec authors to clarify how I'll be adding observations as I move forward with this. |
Fix for OpenAPI 2.0/3.0x released in v3.24.3. |
This change is specific to OpenAPI 3.1.0. Refs #2967
Fix for OpenAPI 3.1.0 released in v3.24.4. |
fantastic, thanks a lot. I will consider your observations and try the corresponding changes |
Q&A (please complete the following information)
How can we help?
I have noticed a difference in behaviour between version 3.16 and 3.19, and I am trying to replicate the result in 3.19.
Basically I want to change the server url dynamically.
Before I would just go into the swaggerClient.spec.servers and change the array, but now this does not seem to have any effect on the following requests. How can I achieve changing the server url in the latest version?
thanks!
The text was updated successfully, but these errors were encountered: