Skip to content

Code snippet shows wrong placeholder when multiple auth schemes are required #1255

@Revisto

Description

@Revisto

Describe the bug

When an endpoint requires multiple auth schemes (e.g. API Key + OAuth), the code snippet placeholders show the wrong name.

Expected behavior

OAuth token placeholder should show the OAuth scheme's name (e.g. <ACCESS_TOKEN>).

Current behavior

OAuth token placeholder shows the API Key's name (e.g. <X-API-Key>).

Possible solution

In CodeSnippets/index.tsx, change authOptions?.[0]?.name to authOptions?.find((opt) => opt.key === key)?.name.

Steps to reproduce

  1. Define two security schemes: APIKey and OAuth
  2. Create an endpoint requiring both: security: [{ "APIKey": [], "OAuth": [] }]
{
  "openapi": "3.0.0",
  "info": {
    "title": "Test API",
    "version": "1.0.0"
  },
  "paths": {
    "/test": {
      "get": {
        "summary": "Test endpoint",
        "security": [
          {
            "APIKey": [],
            "OAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "APIKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "OAuth": {
        "type": "oauth2",
        "name": "ACCESS_TOKEN",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://example.com/oauth/authorize",
            "tokenUrl": "https://example.com/oauth/token",
            "scopes": {}
          }
        }
      }
    }
  }
}
  1. View the example in docs
  2. OAuth header shows Authorization: Bearer <X-API-Key> instead of the OAuth scheme's name

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions