swagger-api / swagger-api/swagger-ui
Is requestInterceptor is apply once when use in react?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied React component and compare requestInterceptor behavior in Swagger UI v3/v4 versus v5 using the reported headers setup. Review the v5 migration and request-interceptor history to identify why API requests retain initialized headers while the click handler sees current headers. Done means a documented explanation of the behavior change and its intended usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100