openapi: 3.0.0
info:
  version: '1'
  title: 'Perl Async::Microservice::Time'
  description: 'demo time service for Async::Microservice, supports jsonp with _cb parameter'
  termsOfService: "http://toterms/"
  contact:
    name: Jozef
    email: some@email
  license:
    name: Perl Licence
    url: https://perldoc.perl.org/index-licence.html
servers:
  - url: /v1/
paths:
  '/datetime':
    get:
      description: 'Returns detailed date-time'
      parameters:
        - name: time_zone
          in: query
          description: timezone string
          required: false
          schema:
            type: string
            default: UTC
      responses:
        200:
          description: 'current time'
          content:
            'application/json':
              schema:
                  $ref: '#/components/schemas/Detailed-DateTime'
        405:
          $ref: '#/components/responses/Input-Processing-Error'
        500:
          $ref: '#/components/responses/Internal-Server-Error'
    post:
      description: "get datetime from epoch"
      requestBody:
        content:
          'application/json':
            schema:
              type: object
              properties:
                epoch:
                  type: integer
                  example: 1586355387
      responses:
        200:
          description: 'current time'
          content:
            'application/json':
              schema:
                  $ref: '#/components/schemas/Detailed-DateTime'
        405:
          $ref: '#/components/responses/Input-Processing-Error'
        500:
          $ref: '#/components/responses/Internal-Server-Error'
  '/datetime/{time_zone_part1}/{time_zone_part2}':
    get:
      description: 'Returns detailed date-time'
      parameters:
        - name: time_zone_part1
          in: path
          description: timezone part1 string
          required: true
          schema:
            type: string
            example: Europe
        - name: time_zone_part2
          in: path
          description: timezone part2 string
          required: true
          schema:
            type: string
            example: Vienna
      responses:
        200:
          description: 'current time'
          content:
            'application/json':
              schema:
                  $ref: '#/components/schemas/Detailed-DateTime'
        405:
          $ref: '#/components/responses/Input-Processing-Error'
        500:
          $ref: '#/components/responses/Internal-Server-Error'
  '/datetime/span/{s_date}':
    get:
      description: 'Returns time span between now and start date + years period in different units'
      parameters:
        - name: s_date
          in: path
          description: start date in format YYYYMMDD or "now"
          required: true
          schema:
            type: string
            example: 20010924
        - name: r_age
          in: query
          description: date span in years
          required: false
          schema:
            type: number
            default: 65
            minimum: 1
            maximum: 200
        - name: m_income
          in: query
          description: monthly increase to sum-up
          required: false
          schema:
            type: number
            minimum: 1
      responses:
        200:
          description: 'weeks left'
          content:
            'application/json':
              schema:
                  $ref: '#/components/schemas/Detailed-Weeks-Left'
        405:
          $ref: '#/components/responses/Input-Processing-Error'
        500:
          $ref: '#/components/responses/Internal-Server-Error'
  '/epoch':
    get:
      description: 'get number of seconds since 1970-01-01T00:00:00'
      responses:
        200:
          description: 'epoch seconds'
          content:
            'application/json':
              schema:
                type: object
                properties:
                  epoch:
                    type: integer
                    example: 1586355387
        500:
          $ref: '#/components/responses/Internal-Server-Error'
  '/sleep':
    get:
      description: 'Sleep request'
      parameters:
        - name: duration
          in: query
          description: sleep length in seconds
          required: false
          schema:
            type: number
            default: 'random number < 10 && > 0'
            minimum: 0
            exclusiveMinimum: true
      responses:
        200:
          description: 'return ok after sleep time'
          content:
            'application/json':
              schema:
                  type: object
                  properties:
                    duration:
                      type: number
                      example: 3.23
                    start:
                      type: number
                      example: 1586453521.4604
                    stop:
                      type: number
                      example: 1586453524.69395
        405:
          $ref: '#/components/responses/Input-Processing-Error'
        500:
          $ref: '#/components/responses/Internal-Server-Error'
  '/hcheck':
    get:
      description: 'Returns 200 response and Perl package name as text when service available'
      responses:
        200:
          description: 'healthy'
          content:
            'text/plain':
              example: 'CRS::Somed::Att::Service'
            'application/json':
              example: '{"data": "Service-name: async-microservice-time\nAPI-version: 1\nOK\n"}'
        503:
          description: 'unhealthy'
          content:
            'text/plain':
              example: 'shutting down'
            'application/json':
              example: '{"data": "shutting down"}'
components:
  responses:
    'Internal-Server-Error':
      description: 'Internal server error.'
      content:
        'text/plain':
          example: 'Some exception at lib/Async/Microservice/Time.pm line 42.'
    'Input-Processing-Error':
      description: 'Input processing error'
      content:
        'application/json':
          schema:
            $ref: '#/components/schemas/Error-Response'
        'text/plain':
          example: 'requires application/json data'
  schemas:
    'Detailed-DateTime':
      type: object
      properties:
        datetime:
          type: string
          description: "%Y-%m-%d %H:%M:%S %z"
          example: '2020-04-08 16:06:12 +0200'
        date:
          type: string
          description: "%Y-%m-%d"
          example: '2020-04-08'
        time:
          type: string
          description: "%H:%M:%S"
          example: '16:06:12'
        time_zone:
          type: string
          description: "%z"
          example: '+0200'
        time_zone_name:
          type: string
          description: "%Z"
          example: 'CEST'
        day:
          type: string
          description: "%d"
          example: '08'
        month:
          type: string
          description: "%m"
          example: '04'
        year:
          type: string
          description: "%Y"
          example: '2020'
        hour:
          type: string
          description: "%H"
          example: '16'
        minute:
          type: string
          description: "%M"
          example: '06'
        second:
          type: string
          description: "%S"
          example: '12'
        epoch:
          type: integer
          description: "seconds since 1970-01-01T00:00:00"
          example: 1586355387
    'Detailed-Weeks-Left':
      type: object
      properties:
        msg:
          type: string
          description: 'text message'
          example: 'you have 105 weeks left'
        weeks:
          type: number
          description: 'number of weeks left'
          example: 105
    'Error-Response':
      description: 'Error object definition'
      type: object
      properties:
        err_status:
          type: integer
          description: error number
          example: 405
        err_msg:
          type: string
          description: error message
          example: 'input format error'
      required:
        - err_status