openapi: 3.1.0
info:
  title: 'Basic single file API'
  license:
    name: MIT
    identifier: MIT
  version: 1.0.0
servers:
  -
    url: 'https://localhost/api'
    description: 'API server'
  -
    url: 'https://example.localhost'
    description: 'The local environment.'
  -
    url: 'https://example.com'
    description: 'The production server.'
paths:
  '/products/{product_id}':
    get:
      tags:
        - products
      operationId: getProducts
      parameters:
        -
          name: product_id
          in: path
          description: 'The product id.'
          required: true
          schema:
            type: int
      responses:
        '200':
          description: 'successful operation'
          headers:
            X-Rate-Limit:
              description: 'calls per hour allowed by the user'
              schema:
                type: integer
                format: int32
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
        '401':
          description: oops
  /products:
    get:
      tags:
        - products
        - catalog
      operationId: getAll
      responses:
        '200':
          description: 'successful operation'
          content:
            application/json:
              schema:
                required:
                  - data
                properties:
                  data: { type: array, items: { $ref: '#/components/schemas/Product' } }
                type: object
        '401':
          description: oops
    post:
      tags:
        - products
      summary: 'Add products'
      operationId: addProducts
      requestBody:
        description: 'New product'
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Product'
      responses:
        '200':
          description: 'successful operation'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
components:
  schemas:
    Colour:
      type: string
      enum:
        - GREEN
        - BLUE
        - RED
    NameTrait:
      properties:
        name:
          description: 'The name.'
      type: object
    Product:
      title: Product
      description: Product
      allOf:
        -
          $ref: '#/components/schemas/NameTrait'
        -
          properties:
            quantity:
              type: integer
            brand:
              type: string
            colour:
              $ref: '#/components/schemas/Colour'
            id:
              description: 'The id.'
              format: int64
              example: 1
            releasedAt:
              type: string
tags:
  -
    name: products
    description: 'All about products'
  -
    name: catalog
    description: 'Catalog API'
