Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flederwiesel opened this issue Jul 31, 2024 · 2 comments

Comments

@flederwiesel
Copy link

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: []
@ak1394
Copy link
Collaborator

ak1394 commented Aug 6, 2024

Are you using the OpenAPI preview and sending the test requests from there, or are you using 'Try it' functionality by clicking on the code lens?

@flederwiesel
Copy link
Author

Apologies for the late response.

I was talking about the "OpenApi SwaggerUI preview" window, not the Try It functionality.

Trying a couple of endpoints with/without auth token, I always have to re-enter value for the token when I want the authentication back on, where it would be pretty nice to have the text field pre-set with an example value - just like e.g. GET parameters. Doing this via a x-example identifier like in the snipped I provided should be allowed by the OpenApi spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants