swagger-api / swagger-api/swagger-ui

API versioning using custom header

Open
#6,485 8 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: question type: support
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.