openapi: 3.0.3

info:
  title: Piratský zkracovač
  description:  Piratský zkracovač API
  version: 2.6.4
  license:
    name: Artistic License 2.0
    url: https://www.perlfoundation.org/artistic-license-20.html
  contact:
    name: Andrej Ramašeuski
    email: andrej@x2.cz
    url: https://pardubicky.pirati.cz/lide/andrej-ramaseuski/

servers:
    - url: https://z.pirati.cz/api
      description: Production server
    - url: http://127.0.0.1:3000/api
      description: Test server

components:
  schemas:
    Shortcut:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
          maxLength: 32
        created:
          type: string
          description: Datum přidání
        shortcut:
          type: string
          description: Zkratka
        url:
          type: string
          description: URL pro přesměrování
          maxLength: 1024
        title:
          type: string
          description: Titulek stránky
          maxLength: 4096
        code:
          type: integer
          description: Kód přesměrování
          enum: [301, 302]
        counter:
          type: integer
          readOnly: true
    StatisticItem:
      type: object
      properties:
        period:
          type: string
          description: Období
        count:
          type: integer
          description: Počet
    LogItem:
      type: object
      properties:
        timestamp:
          type: string
          description: Datum a čas
        ip:
          type: string
          description: IP adresa
        ua:
          type: string
          description: User Agent
        referrer:
          type: string
          description: HTTP Referrer

  securitySchemes:
    Token:
      type: apiKey
      in: header
      name: X-Auth-Token

paths:
  /shortcuts:
    post:
      tags:
      - shortcuts
      security:
        - Token: []
      summary: "Pridat zkratku"
      operationId: ShortcutCreate
      x-mojo-to: shortcut#create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Shortcut'
      responses:
        201:
          description: Shortcut created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Shortcut'
    get:
      tags:
      - shortcuts
      security:
        - Token: []
      summary: "Seznam zkratek"
      operationId: ShortcutList
      x-mojo-to: shortcut#list
      responses:
        200:
          description: Seznam zkratek
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Shortcut'

  /shortcuts/{id}:
    get:
      tags:
      - shortcuts
      security:
        - Token: []
      summary: "Zkratka"
      operationId: ShortcutGet
      x-mojo-to: shortcut#get
      responses:
        204:
          description: Shortcut
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Shortcut'
    put:
      tags:
      - shortcuts
      security:
        - Token: []
      summary: "Aktualizovat zkratku"
      operationId: ShortcutUpdate
      x-mojo-to: shortcut#update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Shortcut'
      responses:
        204:
          description: Shortcut updated
    delete:
      tags:
      - shortcuts
      security:
        - Token: []
      summary: "Smazat zkratku"
      operationId: ShortcutDelete
      x-mojo-to: shortcut#delete
      responses:
        204:
          description: Shortcut deleted

  /shortcuts/{id}/stat/:
    get:
      tags:
      - statistic
      security:
        - Token: []
      summary: "Statistika pro zkratku"
      operationId: ShortcutStatistic
      x-mojo-to: Stat#main
      parameters:
      - name: id
        in: path
        required: true
        example: 100345
        description: "Identifikator zkratky"
        schema:
          type: integer
      - name: begin
        in: query
        required: true
        description: "Zacatek"
        schema:
          type: integer
      - name: end
        in: query
        required: true
        description: "Konec"
        schema:
          type: integer
      responses:
        200:
          description: Statistika
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatisticItem'

  /shortcuts/{id}/log:
    get:
      tags:
      - statistic
      security:
        - Token: []
      summary: "Log pro zkratku"
      operationId: ShortcutLog
      x-mojo-to: Log#main
      parameters:
      - name: id
        in: path
        required: true
        example: 100345
        description: "Identifikator zkratky"
        schema:
          type: integer
      - name: page_size
        in: query
        example: 100
        description: "Počet zaznamu na strance"
        schema:
          type: integer
          default: 1000
      - name: page_index
        in: query
        example: 1
        description: "Stranka"
        schema:
          type: integer
          default: 1
      responses:
        200:
          description: Log navstev pro zkratku
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/LogItem'
