如何正确定义swagger中的可重用链接?

时间:2018-11-12 08:51:48

标签: hyperlink swagger openapi

我正在使用Open API 3.0.0摇摇欲坠

以下是我的Api定义:

paths:
  /offerers:
    get:
      summary: give all offerers back
      operationId: allOfferers
      description: give you all offerers back
      responses:
        '200':
          description: oferers results
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/OfferersId'
          links:
            GetSingleOffererById:
              $ref: '#/components/links/GetSingleOffererById'
        '400':
          description: something went terribly wrong
  /offerers/{offererId}:
    parameters:
      - in: path
        name: offererId
        schema:
          $ref: '#/components/schemas/OfferersId'
        required: true
    get: 
      parameters:
        - $ref: '#/components/schemas/OfferersId'
      summary: give one specified offerer back
      operationId: singleOfferer
      description: give one offerer back. Specified by its id
      responses:
        '200':
          description: offerers results
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Offerers'
        '400':
          description: something went terribly wrong

components:
  schemas:
    OfferersId:
      type: number
      example: 123
    Offerers:
      type: object
      required:
        - offererId
        - name
      properties:
        id:
          $ref: '#/components/schemas/OfferersId'
        name: 
          type: string
          example: "Mark Mustermann"
        location:
          type: string
          example: "90449 Nürnberg"
        experience:
          type: string
          example: "8 Jahre"
        openingHours:
          type: string
          example: "Werktags: 10:15-18:30/tWochenende: geschlossen."

  links:
    GetSingleOffererById:
      operationId: singleOfferer
      description: the offererId in the response will be used as offererId in the request
      paramters:
        offererId: $reponse.body#/OfferersId

此定义中的大多数没有错误。但是最后一部分的组件/链接在“ operationId:singleOfferer”行给了我一个错误:

  

不应具有其他属性extraProperty:operationId,   参数

所以我的问题是: 我该如何纠正我的定义,以便可重复使用的链接有效?

1 个答案:

答案 0 :(得分:1)

Swagger编辑器中的

“不应具有其他属性”错误通常表示以下情况之一:

  1. 关键字拼写错误,
  2. 语法/结构不正确。

在您的示例中,该数字为(1)-paraMTers应该为paraMETers