Skip to content

Add support for x-example in OpenAPI (Swagger) Editor apiKey authentication to pre-set authorization value #278

@flederwiesel

Description

@flederwiesel

In the OpenAPI (Swagger) Editor it is tedious to fill out apiKey authorizations with long key values, especially when doing this multiple times during testing. Having a pre-set value in the "Available authorizations" dialog, taken from a x-example key in the #/components/securitySchemes/* apiKey definitions would be nice.

I tried a couple of approaches, but did not succeed. The closest I could get was to embed an example key in the apiKey description, which could be copy/pasted into the value field. But still I find this cumbersome...

As the Security Scheme Object object may be extended with Specification Extensions, however, for this feature, the $ref would need to be evaluated in the x-example.

API looks like this:

openapi: "3.1.0"
info:
  version: "0.0.1"
  title: Minimal example
servers:
   - url: https://localhost/minimal/api
paths:
  /foo:
    get:
      security:
        - token: []
      responses:
        "200":
          description: "OK"
    post:
      requestBody:
        required: true
        content:
          text/plain:
            schema:
              $ref: "#/components/schemas/token"
      responses:
        "200":
          description: "OK"
components:
  securitySchemes:
    token:
      type: apiKey
      in: header
      name: X-API-Token
      description: >-
        API key. Example: `CtjMYIQTYkKeX2L2ze+plMXMGxtsZCP08/fXam740Uk=`
      x-example:
        $ref: "#/components/schemas/token"
  schemas:
    token:
      type: string
      example: "CtjMYIQTYkKeX2L2ze+plMXMGxtsZCP08/fXam740Uk="
security:
  - token: []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions