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

Is requestInterceptor is apply once when use in react? #9733

Open
shimika opened this issue Mar 22, 2024 · 0 comments
Open

Is requestInterceptor is apply once when use in react? #9733

shimika opened this issue Mar 22, 2024 · 0 comments

Comments

@shimika
Copy link

shimika commented Mar 22, 2024

Q&A (please complete the following information)

  • OS: [e.g. macOS]
  • Browser: [e.g. chrome, safari]
  • Version: [e.g. 22]
  • Method of installation: [e.g. npm, dist assets]
  • Swagger-UI version: v3.24.0, v4.19.0, v5.0.0, v5.12.0
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Content & configuration

Swagger/OpenAPI definition:

# your YAML here

Swagger-UI configuration options:

<SwaggerUI
  url={endPointUrl}
  requestInterceptor={requestInterceptor}
  docExpansion="none"
/>
?yourQueryStringConfig

Screenshots

How can we help?

I am using swagger-ui in my react project.
when I update swagger-ui v3 to v5, requestInterceptor is something wrong
This is my code

function component() {
    const [headers,] = useContext(HeaderContext)

    const requestInterceptor = useCallback((request: Request): Request => {
        console.log('on request: ', headers)

        return request
    }, [headers])

    return (
        <>
            <div onClick={() => requestInterceptor({})}>Show header</div>
            <SwaggerUI
                url={endPointUrl}
                requestInterceptor={requestInterceptor}
                docExpansion="none"
            />
        </>
    )
}

When I use swagger-ui v3 and v4, both clicking Show header and api request trigger requestInterceptor with latest headers information.
But when I update to v5, Click show header shows latest headers but api request only shows initialized headers.

When I find information for these situation?

Of course I can solve this using useRef. However, I am curious about the history and reason for the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant