swagger: '2.0'

info:
  version: "1.0.0"
  title: Broker Admin API
  description: Message Broker Management API
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
schemes:
  - https
  - http

basePath: /broker/v.1.0
paths:
  /queues:
    get:
      description: |
        Gets metadata of all the queues in the broker. This includes durable 
        and non durable queues. 
      parameters:
        - in: query
          name: durable
          type: boolean
          required: false
          description: filter queues by durability
      responses:
        200:
          description: List of queues
          schema:
            type: array
            items:
              $ref: '#/definitions/QueueMetadata'
    post:
      summary: Creates a queue
      consumes:
        - application/json
      parameters:
        - in: body
          name: body
          description: Queue create request
          required: true
          schema:
            $ref: "#/definitions/QueueCreateRequest"
      responses:
        201:
          description: |
            Queue created.
        400:
          description: Bad Request. Invalid request or validation error.
          schema:
            $ref: '#/definitions/Error'
        415:
          description: Unsupported media type. The entity of the request was 
                       in a not supported format.
          schema:
            $ref: '#/definitions/Error'
  /queues/{queueName}:
    parameters:
      - in: path
        name: queueName
        type: string
        required: true
        description: Name of the queue
    get:
      description: Gets metadata of the specified queue.
      responses:
        200:
          description: Metadata of the queue
          schema:
            $ref: '#/definitions/QueueMetadata'
        404:
          description: Queue Not found
    delete:
      summary: Delete the specified queue.
      description: Delete the specified queue if the queue exists in the broker
                   and the query param properties ifUnused and ifEmpty are 
                   satisfied.
      produces:
        - application/json
      parameters:
        - in: query
          name: ifUnused
          type: boolean
          required: false
          default: true
          description: If set to true, queue will be deleted only if the queue 
                       has no active consumers.
        - in: query
          name: ifEmpty
          type: boolean
          required: false
          default: true
          description: If set to true, queue will be deleted only if the queue
                       is empty.
      responses:
        200:
          description: Queue deleted
        400:
          description: Bad request. Invalid request or validation error.
          schema:
            $ref: '#/definitions/Error'
        404:
          description: Queue not found
  /queues/{queueName}/consumers:
    get:
      description: Retrieves all the consumers for the queue
      parameters:
      - in: path
        name: queueName
        type: string
        required: true
        description: Name of the queue
      produces:
        - application/json
      responses:
        200:
          description: Consumers of the queue
          schema:
            type: array
            items:
              $ref: '#/definitions/ConsumerMetadata'
  /queues/{queueName}/consumers/{consumerId}:
    parameters:
      - in: path
        name: queueName
        type: string
        required: true
        description: Name of the queue
      - in: path
        name: consumerId
        type: string
        required: true
        description: Unique consumer identifier
    get:
      description: Retrieves a specific consumer for a given queue
      produces:
        - application/json
      responses:
        200:
            description: Consumers of the queue
            schema:
              $ref: '#/definitions/ConsumerMetadata'
        404:
          description: Consumer not found
    delete:
      description: Delete a specific consumer from a queue
      responses:
        200:
          description: Consumer deleted
        404:
          description: Consumer not found
  /exchanges:
    get:
      description: Retrieves all the exchanges in the broker
      produces:
        - application/json
      responses:
        200:
          description: List of exchanges
          schema:
            type: array
            items: 
              $ref: '#/definitions/ExchangeMetadata'
    post:
      description: Creates an exchange
      consumes:
        - application/json
      parameters:
        - in: body
          name: body
          description: Exchange create request
          required: true
          schema:
            $ref: "#/definitions/ExchangeCreateRequest"
      responses:
        201:
          description: Exchange created
        400:
          description: Bad Request. Invalid request or validation error.
          schema:
            $ref: '#/definitions/Error'
        415:
          description: Unsupported media type. The entity of the request was 
                       in a not supported format.
          schema:
            $ref: '#/definitions/Error'
  /exchanges/{exchangeName}:
    parameters:
      - in: path
        name: exchangeName
        type: string
        required: true
        description: Name of the exchange. 
    get:
      description: Retrieves the exchange metadata for the specific exchange
      produces:
        - application/json
      responses:
        200:
          description: Metadata of the exchange
          schema:
            $ref: '#/definitions/ExchangeMetadata'
        404:
          description: Exchange not found
    delete:
      description: Delete the exchange with the specified exchange name
      responses:
        200:
          description: Exchange deleted
        400:
          description: Bad request. Invalid request or validation error.
          schema:
            $ref: '#/definitions/Error'
        404:
          description: Exchange not found
  /exchanges/{exchangeName}/bindings:
    parameters:
      - in: path
        name: exchangeName
        type: string
        required: true
        description: Name of the exchange.
    get:
      description: Retrieves the bindings set of the exchange
      produces:
        - application/json
      responses:
        200:
          description: List of Bindings
          schema:
            type: array
            items:
              $ref: '#/definitions/BindingInfo'
    post:
      description: Create a binding for a queue
      consumes:
        - application/json
      parameters:
        - in: body
          name: body
          required: true
          description: Payload of binding creation request
          schema:
            $ref: '#/definitions/BindingInfo'
      responses:
        201:
          description: Binding created
        400:
          description: Bad Request. Invalid request or validation error.
          schema:
            $ref: '#/definitions/Error'
        415:
          description: Unsupported media type. The entity of the request was 
                       in a not supported format.
          schema:
            $ref: '#/definitions/Error'  
definitions:
  ConsumerMetadata:
    title: Consumer Metadata
    type: object
    required:
      - id
      - consumerTag
      - flowEnabled
    properties:
      id:
        type: integer
        description: unique id of the consumer
      consumerTag:
        type: string
        description: identifier given by the channel
      flowEnabled:
        type: boolean
        description: State whether the consumers is actively consuming messages
  QueueCreateRequest:
    title: Queue Create Request
    type: object
    required:
      - name
      - durable
      - autoDelete
    properties:
      name:
        type: string
        description: Name of the queue to be created
      durable:
        type: boolean
        description: True if the queue is durable, false otherwise
      autoDelete:
        type: boolean
        description: deletes the queue when there are no consumers for the
                     queue.
  QueueMetadata:
    title: Queue Metadata
    type: object
    required:
      - name
      - consumerCount
      - durable
      - capacity
      - size
      - autoDelete
    properties:
      name:
        type: string
        description: Name of the queue. This is a unique value
      consumerCount:
        type: integer
        description: number of active consumers assigned to the queue. Messages
                     will be dispatched in a round robing manner to the 
                     consumers.
      durable:
        type: boolean
        description: durability of the queue. True if the queue is durable and
                     false otherwise. Durable queues will survive node failures.
      capacity:
        type: integer
        description: Maximum number of messages the queue can hold. 
                     Durable queues are unbounded and will specify the integer
                     max value (2,147,483,647) as the capacity.
      size:
        type: integer
        description: Number of messages in the queue.
      autoDelete:
        type: boolean
        description: If set to true queue will get deleted once all the 
                     consumers of the queue get disconnected.
  ExchangeMetadata:
    title: Exchange Metadata
    type: object
    properties:
      name:
        type: string
        description: Name of the exchange
      type:
        type: string
        description: Type of exchange.  for instance amq.direct, amq.topic
      durable:
        type: boolean
        description: True if the exchange is durable and false otherwise
  ExchangeCreateRequest:
    title: Exchange Create Request
    type: object
    required:
      - name
      - type
      - durable
    properties:
      name:
        type: string
        description: Name of the exchange. This should be a unique value
      type:
        type: string
        description: Type of exchange
      durable:
        type: boolean
        description: States whether the exchange is durable or not
  BindingInfo:
    title: Binding Information
    type: object
    required:
      - routingKey
      - queueName
    properties:
      routingKey:
        type: string
        description: Routing pattern of the binding
      queueName:
        type: string
        description: Bound queue name
      filterExpression:
        type: string
        description: message filtering expression
  Error:
    title: Error Response
    required:
      - code
      - message
    properties:
      code:
        type: integer
        format: int64
      message:
        type: string
        description: Error message.
                     
                     