scalar / scalar

Scalar is an open-source platform with:                                       🌐 Modern Rest API Client                                        📖 Beautiful API References                                        ✨ 1st-Class OpenAPI/Swagger Support
https://scalar.com
MIT License
6.32k stars 203 forks source link

Configuration properties 'preferredSecurityScheme' and 'servers' are not working as expected #3295

Open xC0dex opened 1 week ago

xC0dex commented 1 week ago

What happens?

Using the latest api reference https://cdn.jsdelivr.net/npm/@scalar/api-reference in the Scalar.AspNetCore package, I encountered that preferredSecurityScheme and servers properties are not working as expected.

preferredSecurityScheme This bug was already reported #3264; however, it's not fixed on my end. Instead of preselecting the ApiKey scheme, its set to none. image

servers This property only sets the Base URL in the overview. But when you click the Test Request button, it ignores this property and uses the values from the OpenAPI document.

The overview: image

The api client: image

What did you expect to happen?

When using a custom CDN Url with version 1.25.10 https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.10 both properties start working again:

preferredSecurityScheme image

servers image

OpenAPI Document

{
  "openapi": "3.0.1",
  "info": {
    "title": "Scalar.AspNetCore.Playground | v1",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://localhost:7201"
    },
    {
      "url": "http://localhost:5056"
    }
  ],
  "paths": {
    "/weatherforecast": {
      "get": {
        "tags": [
          "Scalar.AspNetCore.Playground"
        ],
        "operationId": "GetWeatherForecast",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WeatherForecast"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Access token is missing or invalid."
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "WeatherForecast": {
        "required": [
          "date",
          "temperatureC",
          "summary"
        ],
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "temperatureC": {
            "type": "integer",
            "format": "int32"
          },
          "summary": {
            "type": "string",
            "nullable": true
          },
          "temperatureF": {
            "type": "integer",
            "format": "int32"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "name": "X-Api-Key",
        "in": "header"
      }
    }
  },
  "tags": [
    {
      "name": "Scalar.AspNetCore.Playground"
    }
  ]
}

This bug is reproducible in the Scalar.AspNetCore.Playground project.

xC0dex commented 3 days ago

Update:

It looks like the preferredSecurityScheme property partially started working again. Now the scheme will be selected, but I experience the same issue as described in https://github.com/scalar/scalar/issues/3377.