openapi: 3.0.3
info:
  title: StayEasy Booking API
  version: 1.0.0
  description: |
    The StayEasy Booking API lets you search room availability and manage
    reservations for a hospitality property.

    **Note:** StayEasy is a fictional product created for this documentation
    sample. All URLs, keys and data are examples.
  contact:
    name: StayEasy Developer Support
    email: developers@stayeasy.example.com
servers:
  - url: https://api.stayeasy.example.com/v1
    description: Production (example)
  - url: https://sandbox.stayeasy.example.com/v1
    description: Sandbox for testing (example)
security:
  - bearerAuth: []
tags:
  - name: Rooms
    description: Search rooms and check availability.
  - name: Bookings
    description: Create, retrieve and cancel bookings.
paths:
  /rooms:
    get:
      tags: [Rooms]
      operationId: listRooms
      summary: List available rooms
      description: |
        Returns rooms that are available for the requested dates and number of
        guests. Results are paginated.
      parameters:
        - name: check_in
          in: query
          required: true
          description: Check-in date (YYYY-MM-DD).
          schema:
            type: string
            format: date
            example: "2026-11-10"
        - name: check_out
          in: query
          required: true
          description: Check-out date (YYYY-MM-DD). Must be after `check_in`.
          schema:
            type: string
            format: date
            example: "2026-11-12"
        - name: guests
          in: query
          required: false
          description: Number of guests. Defaults to 1.
          schema:
            type: integer
            minimum: 1
            maximum: 10
            default: 1
        - name: page
          in: query
          required: false
          description: Page number, starting at 1.
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: limit
          in: query
          required: false
          description: Number of results per page (maximum 50).
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 20
      responses:
        "200":
          description: A page of available rooms.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RoomList"
              example:
                data:
                  - id: rm_1042
                    name: Deluxe Garden View
                    type: deluxe
                    max_guests: 3
                    price_per_night:
                      amount: 4500
                      currency: INR
                    amenities: [wifi, air_conditioning, breakfast]
                page: 1
                limit: 20
                total: 1
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /rooms/{room_id}:
    get:
      tags: [Rooms]
      operationId: getRoom
      summary: Retrieve a room
      parameters:
        - $ref: "#/components/parameters/RoomId"
      responses:
        "200":
          description: The requested room.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Room"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /bookings:
    post:
      tags: [Bookings]
      operationId: createBooking
      summary: Create a booking
      description: |
        Reserves a room for the given dates. Send an `Idempotency-Key` header
        to safely retry the request without creating duplicate bookings.
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: A unique string (for example, a UUID) that identifies this request.
          schema:
            type: string
            example: 3f2b8c1e-5d4a-4c1b-9a7e-2b6f0d9e1a44
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateBookingRequest"
            example:
              room_id: rm_1042
              check_in: "2026-11-10"
              check_out: "2026-11-12"
              guests: 2
              guest:
                name: Priya Raman
                email: priya.raman@example.com
      responses:
        "201":
          description: Booking created.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Booking"
              example:
                id: bk_88213
                status: confirmed
                room_id: rm_1042
                check_in: "2026-11-10"
                check_out: "2026-11-12"
                guests: 2
                guest:
                  name: Priya Raman
                  email: priya.raman@example.com
                total_price:
                  amount: 9000
                  currency: INR
                created_at: "2026-10-13T08:15:00Z"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"
        "409":
          $ref: "#/components/responses/Conflict"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /bookings/{booking_id}:
    get:
      tags: [Bookings]
      operationId: getBooking
      summary: Retrieve a booking
      parameters:
        - $ref: "#/components/parameters/BookingId"
      responses:
        "200":
          description: The requested booking.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Booking"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"
        "429":
          $ref: "#/components/responses/TooManyRequests"
    delete:
      tags: [Bookings]
      operationId: cancelBooking
      summary: Cancel a booking
      description: |
        Cancels a booking. The booking is kept and its `status` changes to
        `cancelled`. A booking that is already cancelled returns a `409` error.
      parameters:
        - $ref: "#/components/parameters/BookingId"
      responses:
        "200":
          description: The cancelled booking.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Booking"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"
        "409":
          $ref: "#/components/responses/Conflict"
        "429":
          $ref: "#/components/responses/TooManyRequests"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: "Send your API key as `Authorization: Bearer YOUR_API_KEY`."
  parameters:
    RoomId:
      name: room_id
      in: path
      required: true
      description: The room ID, for example `rm_1042`.
      schema:
        type: string
    BookingId:
      name: booking_id
      in: path
      required: true
      description: The booking ID, for example `bk_88213`.
      schema:
        type: string
  schemas:
    Money:
      type: object
      required: [amount, currency]
      properties:
        amount:
          type: integer
          description: Amount in the smallest whole unit of the currency (rupees for INR).
          example: 4500
        currency:
          type: string
          description: Three-letter ISO 4217 currency code.
          example: INR
    Room:
      type: object
      required: [id, name, type, max_guests, price_per_night]
      properties:
        id:
          type: string
          example: rm_1042
        name:
          type: string
          example: Deluxe Garden View
        type:
          type: string
          enum: [standard, deluxe, suite]
        max_guests:
          type: integer
          example: 3
        price_per_night:
          $ref: "#/components/schemas/Money"
        amenities:
          type: array
          items:
            type: string
          example: [wifi, air_conditioning, breakfast]
    RoomList:
      type: object
      required: [data, page, limit, total]
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Room"
        page:
          type: integer
        limit:
          type: integer
        total:
          type: integer
          description: Total number of rooms that match the search.
    Guest:
      type: object
      required: [name, email]
      properties:
        name:
          type: string
          example: Priya Raman
        email:
          type: string
          format: email
          example: priya.raman@example.com
    CreateBookingRequest:
      type: object
      required: [room_id, check_in, check_out, guests, guest]
      properties:
        room_id:
          type: string
          example: rm_1042
        check_in:
          type: string
          format: date
          example: "2026-11-10"
        check_out:
          type: string
          format: date
          example: "2026-11-12"
        guests:
          type: integer
          minimum: 1
          example: 2
        guest:
          $ref: "#/components/schemas/Guest"
    Booking:
      type: object
      required: [id, status, room_id, check_in, check_out, guests, guest, total_price, created_at]
      properties:
        id:
          type: string
          example: bk_88213
        status:
          type: string
          enum: [confirmed, cancelled]
        room_id:
          type: string
        check_in:
          type: string
          format: date
        check_out:
          type: string
          format: date
        guests:
          type: integer
        guest:
          $ref: "#/components/schemas/Guest"
        total_price:
          $ref: "#/components/schemas/Money"
        created_at:
          type: string
          format: date-time
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
              description: A stable, machine-readable error code.
              example: room_unavailable
            message:
              type: string
              description: A human-readable explanation.
              example: The room is not available for the selected dates.
  responses:
    BadRequest:
      description: The request is invalid, for example a missing or badly formatted field.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            error:
              code: invalid_request
              message: "check_out must be after check_in."
    Unauthorized:
      description: The API key is missing or invalid.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            error:
              code: unauthorized
              message: The API key is missing or invalid.
    NotFound:
      description: The requested resource does not exist.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            error:
              code: not_found
              message: No booking was found with that ID.
    Conflict:
      description: The request conflicts with the current state of the resource.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            error:
              code: room_unavailable
              message: The room is not available for the selected dates.
    TooManyRequests:
      description: You exceeded the rate limit. See the `Retry-After` header.
      headers:
        Retry-After:
          description: Seconds to wait before trying again.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            error:
              code: rate_limited
              message: Too many requests. Try again in 30 seconds.
