Search code examples
swagger-editor

Swagger: multiple verbs under same path validates in editor, but prevents it from restarting


I have the swagger definition below. The editor validates it, and both the PUT and the PATCH show up in the preview window.

However, if I subsquently stop the editor and attempt to restart it, I get:
ERROR:
{ [YAMLException: duplicated mapping key at line 128, column 53: ... -controller: messagesPatchOrSend

Line 128 is the line directly above "patch:"

YAML:

    paths:
      /messages/{messageId}:
        x-swagger-router-controller: messagesUpdateOrSend
        put:
          summary: Update/send a message
          description: The `PUT` method should be used where it is desireable to submitting every property whether it changed or not (as opposed to updating discrete properties of a message).  This endpoint MUST NOT be called if a `messageId` is not available. If `send=false` the message MUST be saved as a draft, otherwise the message MUST be marked for delivery.
          operationId: messagesUpdateOrSend
          consumes: ["application/json"]
          produces: ["application/json"]
          parameters:
            - name: messageId
              in: path
              description: A UID used by the proxy to uniquely identify the message.
              required: true
              type: string
            - name: send
              in: query
              description: Send message if `query=true`, save as draft if `query=false`
              required: true
              type: boolean
            - name: token
              in: query
              description: auth token, if not included in header.  Example `token=[Token]`
              required: false
              type: string
            - name: body
              in: body
              description: ""
              required: true
              schema:
                type: object
          responses:
            "200":
              description: Success/OK
              schema:
                $ref: "#/definitions/SuccessResponse"
            default:
              description: Error
              schema:
                $ref: "#/definitions/ErrorResponse"
        x-swagger-router-controller: messagesPatchOrSend
        patch:
          summary: Update/send a message
          description: ""
          operationId: messagesPatchOrSend
          consumes: ["application/json"]
          produces: ["application/json"]
          parameters:
            - name: messageId
              in: path
              required: true
              type: string
            - name: send
              in: query
              required: true
              type: boolean
            - name: token
              in: query
              required: false
              type: string
            - name: body
              in: body
              required: true
              schema:
                type: object
          responses:
            "200":
              description: Success/OK
              schema:
                $ref: "#/definitions/SuccessResponse"
            default:
              description: Error
              schema:
                $ref: "#/definitions/ErrorResponse"
        x-swagger-router-controller: messagesDelete

definitions:
  SuccessResponse:
    required:
      - message
    properties:
      message:
        type: string


  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

Solution

  • It's because you have two x-swagger-router-controller values inside /messages/{messageId}:.