swagger-api / swagger-api/swagger-editor

Code samples ignore global security when multiple security schemes are defined (ApiKey + Bearer)

Open
#5,699 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
9.5k
Forks
2.4k
Avg merge
17h 15m
Merged PRs (30d)
18

Description

When using multiple security schemes (ApiKey + Bearer) defined globally in OpenAPI 3.0, the Try it out request correctly sends both headers, but the Code samples generated by Swagger UI include only one of them (typically the first one).

This is inconsistent with the OpenAPI spec and leads to misleading code samples.

To Reproduce

Use Swagger UI 5.22.0

Define global security in your OpenAPI spec with both ApiKey and BearerAuth:

openapi: 3.0.1
info:
  title: Test API
  version: 1.0.0

servers:
  - url: https://example.com/api

security:
  - ApiKeyAuth: []
    BearerAuth: []

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: apiKey
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

paths:
  /models:
    get:
      summary: List models
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object

Open Swagger UI, authorize with both apiKey and Bearer token.
Click Try it out → Execute → curl request shows both headers correctly.
Check the Code samples section → curl / PHP / other languages

Expected behavior
The generated Code samples should include both headers, matching the executed request and the OpenAPI specification.

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 reproducing the issue in Swagger UI 5.22.0 with the supplied OpenAPI document and compare the executed curl request with the generated curl, PHP, and other samples. Done means code samples include both the ApiKeyAuth and BearerAuth headers, matching the specification and Try it out request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.