swagger-api / swagger-api/swagger-ui
API versioning using custom header
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: Windows
- Browser: Chrome
- Version: [e.g. 22]
- Method of installation: nuget (packaged with Swashbuckle.AspNetCore)
- Swagger-UI version: 3.32.5
- Swagger/OpenAPI version: OpenAPI 3.0
How can we help?
I can't find any information on this for supporting multiple versions of an API. If I want to version my API using a custom header (ie. x-api-version), is it possible to get the "Try it Out" feature of Swagger-UI to pass the correct version header and number based on the selected definition?
I already have my server outputting the two separate swagger.json files for the versions. And I can select between them in the UI and see the correct documentation. But I can't see how to send the version number with the try it out requests.
I assume I will have to use the requestInterceptor but I couldn't find any documentation on how to retrieve the currently selected api definition so I know which version number to add to the header.
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 by examining Swagger UI's Try it Out request flow, requestInterceptor, and the selected API definition state. Determine how the selected definition exposes its version, then verify that requests from each definition include the matching x-api-version header; completion should be demonstrated through the UI's version selector and Try it Out requests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100