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

Can not use components/securitySchemes in swagger-ui #3705

Closed
lvonk opened this issue Sep 25, 2017 · 4 comments
Closed

Can not use components/securitySchemes in swagger-ui #3705

lvonk opened this issue Sep 25, 2017 · 4 comments

Comments

@lvonk
Copy link

lvonk commented Sep 25, 2017

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? Open API 3.0.0
Which Swagger-UI version? version: "3.2.2", gitRevision: "g45e7a541", gitDirty: true, buildTimestamp: "Sat, 23 Sep 2017 20:06:42 GMT", machine: "Kyles-MacBook-Air.local"
How did you install Swagger-UI? git pull && open dist/index.html
Which browser & version? Chrome Version 61.0.3163.91 (Official Build) (64-bit)
Which operating system? Mac 10.12.6

Defining security as follows works:

securityDefinitions:
  apikey_auth:
    type: apiKey
    in: header
    name: api_key

However this does not seem OpenAPI 3.0.0 compliant (or I can't find the definition of securityDefinitions anywhere in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md).

Defining security according to the docs in OpenAPI 3.0.0 using securitySchemes and clicking the lock icon in the operation does not work and result in the following error in de ui:

components:
  securitySchemes:
    apikey_auth:
      type: apiKey
      in: header
      name: api_key

screen shot 2017-09-25 at 19 32 52

Complete openapi.yaml:

openapi: 3.0.0
info:
  title: Jortt API
  description: Api description jortt
  version: 2.0.0

servers:
  - url: http://localhost:9292/api/v2
    description: Development server

security:
  - apikey_auth: []

paths:
  /customers:
    get:
      summary: Customers
      description: The customers endpoint returns all customers known in Jortt
      operationId: getCustomers
      parameters:
        - name: query
          in: query
          description: A search string for customers
          required: false
          schema:
            type: string
      responses:
        '200':
          description: An array of customers
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CustomerList"

components:
  securitySchemes:
    apikey_auth:
      type: apiKey
      in: header
      name: api_key
  schemas:
    Paging:
      properties:
        total_items:
          type: integer
        total_pages:
          type: integer
        page_size:
          type: integer
        current_page:
          type: integer
    Customer:
      properties:
        customer_id:
          type: string
          description: Unique id
        name:
          type: string
          description: Name of the customer
    CustomerList:
      allOf:
        - properties:
            customers:
              description: Contains list of customers
              type: array
              items:
                $ref: "#/components/schemas/Customer"
        - $ref: "#/components/schemas/Paging"
@webron
Copy link
Contributor

webron commented Sep 25, 2017

@shockey is this related to the try it out functionality or something else?

@shockey
Copy link
Contributor

shockey commented Sep 25, 2017

Looks like this is coming from the authorization feature itself, here's where the error is throwing from:

let definition = securityDefinitions.get(name)

Adding securityDefinitions to a 3.0 document works, because the authorization feature is not OpenAPI-aware at the moment. It looks for the same structures, regardless of the swagger or openapi value in the document.

Obviously, the real fix is to implement OpenAPI authorization support, but in the meantime, disabling authorization features when an OpenAPI document is present will prevent this sort of issue.

@hkosova
Copy link
Contributor

hkosova commented Sep 26, 2017

Support for OAS 3.0 securitySchemes is covered by #3641 and #3665.

@shockey
Copy link
Contributor

shockey commented Oct 5, 2017

Closing this, as the ambiguous Swagger2-in-OAS3 behavior has been solved and the OAS3 securitySchemes functionality is covered in other tickets 😄

@shockey shockey closed this as completed Oct 5, 2017
@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants