# Copyright 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
swagger: '2.0'
info:
  title: "Matrix Client-Server Directory API"
  version: "1.0.0"
host: localhost:8008
schemes:
  - https
  - http
basePath: /_matrix/client/%CLIENT_MAJOR_VERSION%/directory
consumes:
  - application/json
produces:
  - application/json
securityDefinitions:
  $ref: definitions/security.yaml
paths:
  "/room/{roomAlias}":
    put:
      summary: Create a new mapping from room alias to room ID.
      security:
        - accessToken: []
      parameters:
        - in: path
          type: string
          name: roomAlias
          description: The room alias to set.
          required: true
          x-example: "#monkeys:matrix.org"
        - in: body
          name: roomInfo
          description: Information about this room alias.
          required: true
          schema:
            type: object
            properties:
              room_id:
                type: string
                description: The room ID to set.
            example: |-
              {
                "room_id": "!abnjk1jdasj98:capuchins.com"
              }
      responses:
        200:
          description: The mapping was created.
          examples:
            application/json: |-
              {}
          schema:
            type: object
        409:
          description: A room alias with that name already exists.
          examples:
            application/json: |-
              {
                "errcode": "M_UNKNOWN",
                "error": "Room alias #monkeys:matrix.org already exists."
              }
      tags:
        - Room directory
    get:
      summary: Get the room ID corresponding to this room alias.
      description: |-
        Requests that the server resolve a room alias to a room ID.

        The server will use the federation API to resolve the alias if the
        domain part of the alias does not correspond to the server's own
        domain.

      parameters:
        - in: path
          type: string
          name: roomAlias
          description: The room alias.
          required: true
          x-example: "#monkeys:matrix.org"
      responses:
        200:
          description: The room ID and other information for this alias.
          schema:
            type: object
            properties:
              room_id:
                type: string
                description: The room ID for this room alias.
              servers:
                type: array
                description: A list of servers that are aware of this room ID.
                items:
                  type: string
                  description: A server which is aware of this room ID.
          examples:
            application/json: |-
              {
                "room_id": "!abnjk1jdasj98:capuchins.com",
                "servers": [
                  "capuchins.com",
                  "matrix.org",
                  "another.com"
                ]
              }
        404:
          description: There is no mapped room ID for this room alias.
          examples:
            application/json: |-
              {
                "errcode": "M_NOT_FOUND",
                "error": "Room ID !abnjk1jdasj98:capuchins.com not found."
              }
      tags:
        - Room directory
    delete:
      summary: Remove a mapping of room alias to room ID.
      description: |-
        Remove a mapping of room alias to room ID.

        Servers may choose to implement additional access control checks here, for instance that room aliases can only be deleted by their creator or a server administrator.
      security:
        - accessToken: []
      parameters:
        - in: path
          type: string
          name: roomAlias
          description: The room alias to remove.
          required: true
          x-example: "#monkeys:matrix.org"
      responses:
        200:
          description: The mapping was deleted.
          examples:
            application/json: |-
              {}
          schema:
            type: object
      tags:
        - Room directory