Skip to content
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

$refs failed to resolve with such error: "Could not resolve reference: Failed to execute 'delete' on 'Headers': Headers are immutable" #8532

Closed
PatchRanger opened this issue Mar 30, 2023 · 10 comments

Comments

@PatchRanger
Copy link

OS: Ubuntu 22.04.1
Browser: Chromium-based
Version 108.0.0.0
Method of installation: via docker image swaggerapi/swagger-ui
Swagger-UI version: v5.0.0-alpha.4
Swagger/OpenAPI version: 3.1.0

The installation is the same as in #8525 (comment).

After I successfully applied the workaround about absolute paths for $ref, I see in the browser console that requests for schemas began to go to the correct host - and even return with a 200 response.
But I found another problem: $ref inside uploaded documents refuse to load, I see a lot of red error messages with the following text:

Resolver error at $ref
Could not resolve reference: Failed to execute 'delete' on 'Headers': Headers are immutable

I see nor errors in the browser console neither non-ok requests in its Network tab.

In addition, when I click on the dropdown arrow next to each operation, the operation dropdown does not drop out - just the dropdown arrow changes to "open" and that's it. I believe this is related: apparently due to the fact that $ref has not loaded, there is nothing to show in the operation dropdown.

Perhaps the reason for this is the same as in the previous issue: incorrect resolution of relative paths. I hope that after fixing that problem, this problem will also go away. But perhaps this is not related, I do not have enough SwaggerUI context to judge with complete confidence - therefore, I am creating this issue in order to inform the development team about the difficulties that arise.

@PatchRanger
Copy link
Author

Снимок экрана от 2023-03-30 18-12-09

@char0n
Copy link
Member

char0n commented Mar 30, 2023

#8525 was resolved in #8533 and is unrelated to this issue.

@char0n
Copy link
Member

char0n commented Mar 30, 2023

The issue is in again in swagger-client on this line.

@char0n
Copy link
Member

char0n commented Mar 30, 2023

Headers are immutable and thus we cannot remove headers from it. This works in node-fetch but doesn't work in browsers.

To fix this, we have to clone the response in order to mutate it.

More info in https://developer.mozilla.org/en-US/docs/Web/API/Headers

@char0n
Copy link
Member

char0n commented Mar 30, 2023

Further context: we're removing Content-Type header from the HttpSwaggerClient ApiDOM resolver plugin to avoid serialization into JSON/YAML. HttpSwaggerClient needs to return buffer and serializing into JSON/YAML and then returning buffer would only make the resolution slower.

char0n added a commit to swagger-api/swagger-js that referenced this issue Mar 30, 2023
Fetch API doesn't allow to mutate Response
or any associated objects like Headers.
Removing the Content-Type header allows us
to skip the JSON/YAML serialization.
To skip the serialization we have clone
the Response and Headers objects and remove
the Content-Type header in clones.

This doesn't apply to node-fetch@2 which
API allows to mutate Response and all
associated objects.

Refs swagger-api/swagger-ui#8532
@char0n
Copy link
Member

char0n commented Mar 30, 2023

Addressed in upstream: swagger-api/swagger-js@1df6b38

@PatchRanger
Copy link
Author

@char0n Wow, I am impressed, blazingly fast debug & fix, thank you! I am going to check whether it fixes this issue (I am prettty sure it should).

char0n added a commit that referenced this issue Mar 31, 2023
This bug fix comes via swagger-client@3.19.5.

Refs #8532
@char0n
Copy link
Member

char0n commented Mar 31, 2023

Addressed for swagger-ui@5 in #8536

@char0n
Copy link
Member

char0n commented Mar 31, 2023

@char0n Wow, I am impressed, blazingly fast debug & fix, thank you! I am going to check whether it fixes this issue (I am prettty sure it should).

Release will be comming in an half an hour. Please keep the issues related to OpenAPI 3.1.0 comming. OpenAPI 3.1.0 support in swagger-ui@5 is current priority and I appreciate any early feedback that you provide.

char0n added a commit that referenced this issue Mar 31, 2023
This bug fix comes via swagger-client@3.19.5.

Refs #8532
@char0n
Copy link
Member

char0n commented Mar 31, 2023

@char0n char0n closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants