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

"Unable to render this definition" on refreshing the page #158

Open
2 tasks done
blue86321 opened this issue Jul 3, 2024 · 2 comments
Open
2 tasks done

"Unable to render this definition" on refreshing the page #158

blue86321 opened this issue Jul 3, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@blue86321
Copy link

blue86321 commented Jul 3, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.26.1

Plugin version

4.0.0

Node.js version

20.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.5

Description

In swagger docs, when unfolding the api difinitions, browser location (url) will change.

At this point, if we refresh the page, we will get error Unable to render this definition

It is because we find the difinition by using the current url and attach ./json, e.g. http://127.0.0.1:3000/api/docs#/auth/post_v1_auth_login/./json

image

To resolve this bug, the most straightforward way is to modify the swagger-initialzer.js
(but this solution doesn't handle the corner case where the user's url contains #)

function resolveUrl(url) {
      var currentHref = window.location.href;
>     currentHref = currentHref.split('#')[0];
      currentHref = currentHref.endsWith('/') ? currentHref : currentHref + '/';
      var anchor = document.createElement('a');
      anchor.href = currentHref + url;
      return anchor.href
    }

A better way is to make it unchanged even we refresh the page, not sure if it is a big change or not.
What do you think?

Link to code that reproduces the bug

No response

Expected Behavior

unfolding the API difinition, then refresh the browser, the docs stay the same instead of showing Unable to render this definition

@mcollina
Copy link
Member

mcollina commented Jul 3, 2024

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina mcollina added bug Something isn't working good first issue Good for newcomers labels Jul 3, 2024
@blue86321
Copy link
Author

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Done. I use the initial suggestion to solve it.
Seems like a hash # won't show up in a normal domain / url since it represents an anchor.

The PR is attached #160. Let me know if there is anything I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants