Недопустимое определение securityDefinitions — чванство для Auth0

#swagger #swagger-2.0 #swagger-editor

#чванство #swagger-2.0 #swagger-редактор

Вопрос:

У меня есть следующий файл spec.yaml

 swagger: '2.0'
info:
  title: Store API
  version: "0.3.5"
host: SELF_URL_REPLACED_BY_APP
schemes:
  - https
basePath: /
produces:
  - application/json
tags:
  - name: account
  - name: transcripts
security:
  - auth0:
    - openid
  - apiKey: []
securityDefinitions:
  auth0:
    type: oauth2
    authorizationUrl: https://store.auth0.com/authorize
    flow: implicit
    tokenName: id_token
    scopes:
      openid: Grant access to user
  apiKey:
    type: apiKey
    name: Authorization
    in: header
  

Я получаю эту ошибку, когда пытаюсь проверить ее в http://editor.swagger.io /:

 ✖ Swagger Error
Not a valid securityDefinitions definition
Jump to line 19
Details
 Object
code:  "ONE_OF_MISSING"
 params: Array [0]
message:  "Not a valid securityDefinitions definition"
 path: Array [2]
schemaId:  "http://swagger.io/v2/schema.json#"
 inner: Array [6]
level: 900
type:  "Swagger Error"
description:  "Not a valid securityDefinitions definition"
lineNumber: 19
  

Чего мне не хватает? Я могу войти в систему, используя Auth0, и, кажется, все работает нормально.

Любой совет очень ценится.

Ответ №1:

tokenName недопустимое свойство объекта SecurityDefinitions.

Однако в вашем определении Swagger есть другие ошибки, такие как no paths , которые могут привести к тому, что оно будет выдавать неправильные ошибки проверки securityDefinitions при редактировании.

Например, следующее должно быть проверено нормально:

 swagger: '2.0'
info:
  title: Store API
  version: "0.3.5"
host: SELF_URL_REPLACED_BY_APP
schemes:
  - https
basePath: /
produces:
  - application/json
tags:
  - name: account
  - name: transcripts
paths:
  /pets:
    get:
      description: Returns all pets from the system that the user has access to
      produces:
      - application/json
      responses:
        '200':
          description: A list of pets.
          schema:
            type: array
            items:
              type: string
      security:
        - auth0: 
          - openid
        - apiKey: []
securityDefinitions:
  auth0:
    type: oauth2
    authorizationUrl: https://store.auth0.com/authorize
    flow: implicit
    scopes:
      openid: Grant access to user
  apiKey:
    type: apiKey
    name: Authorization
    in: header
  

Также security раздел не относится к верхнему уровню, но должен быть размещен под каждым методом API (см. Пример определения выше), чтобы указать, какие определения безопасности следует применять к этому API.