# Copyright 2019 New Vector 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.
openapi: 3.1.0
info:
  title: Matrix Client-Server Room Upgrades API
  version: 1.0.0
paths:
  "/rooms/{roomId}/upgrade":
    post:
      summary: Upgrades a room to a new room version.
      description: Upgrades the given room to a particular room version.
      operationId: upgradeRoom
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      parameters:
        - in: path
          name: roomId
          required: true
          description: The ID of the room to upgrade.
          example: "!oldroom:example.org"
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                new_version:
                  type: string
                  description: The new version for the room.
              example: {
                "new_version": "2"
              }
              required:
                - new_version
        required: true
      responses:
        "200":
          description: The room was successfully upgraded.
          content:
            application/json:
              schema:
                type: object
                properties:
                  replacement_room:
                    type: string
                    description: The ID of the new room.
                required:
                  - replacement_room
              examples:
                response:
                  value: {
                    "replacement_room": "!newroom:example.org"
                  }
        "400":
          description: |-
            The request was invalid. One way this can happen is if the room version
            requested is not supported by the homeserver.
          content:
            application/json:
              schema:
                $ref: definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_UNSUPPORTED_ROOM_VERSION",
                    "error": "This server does not support that room version"
                  }
        "403":
          description: The user is not permitted to upgrade the room.
          content:
            application/json:
              schema:
                $ref: definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_FORBIDDEN",
                    "error": "You cannot upgrade this room"
                  }
      tags:
        - Room upgrades
servers:
  - url: "{protocol}://{hostname}{basePath}"
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      hostname:
        default: localhost:8008
      basePath:
        default: /_matrix/client/v3
components:
  securitySchemes:
    accessTokenQuery:
      $ref: definitions/security.yaml#/accessTokenQuery
    accessTokenBearer:
      $ref: definitions/security.yaml#/accessTokenBearer
