swagger: '2.0'

info:
  title: System Time API
  description: System Time management
  version: '1.1.0'

schemes:
- http
- https

produces:
- application/json

paths:
  /system/time:
    get:
      description: Get current time settings
      responses:
        200:
          description: success
          schema:
            $ref: '#/definitions/Time'
          examples:
            {
              "application/json": {
                $ref: '#/externalDocs/x-mocks/TimeExample'
              }
            }

    put:
      parameters:
      - name: body
        in: body
        required: true
        schema:
          $ref: '#/definitions/Time'
      description: Update time settings
      responses:
        200:
          description: success
          schema:
            $ref: '#/definitions/Time'
          examples:
            {
              "application/json": {
                $ref: '#/externalDocs/x-mocks/TimeExample'
              }
            }

  /system/zoneinfo:
    get:
      description: Get current timezone information
      responses:
        200:
          description: success
          schema:
            $ref: '#/definitions/Timezone'
          examples:
            {
              "application/json": {
                $ref: '#/externalDocs/x-mocks/TimezoneInfoExample'
              }
            }

    post:
      description: Update timezone information from internet
      responses:
        200:
          description: success

definitions:
  Time:
    description: Time configuration
    type: object
    properties:
      time:
        description: 'Current system time (format: iso 8601)'
        type: string
      timezone:
        description: Current timezone
        type: string
      ntp:
        $ref: '#/definitions/NTP'
    example:
        $ref: '#/externalDocs/x-mocks/TimeExample'

  NTP:
    description: NTP configuration
    type: object
    required:
    - enable
    - server
    - interval
    properties:
      enable:
        description: Enable NTP client
        type: boolean
      server:
        description: Target NTP server
        type: string
        minLength: 1
        maxLength: 2048
      interval:
        description: 'Time sync interval in seconds (at least: 60 seconds.)'
        type: integer
        minimum: 60
        maximum: 2592000
    example:
      $ref: '#/externalDocs/x-mocks/NTPExample'

  Timezone:
    description: Timezone information
    type: object
    required:
    - zone
    - iso3166
    properties:
      zone:
        description: TZ zone list with cca2 and TZ
        readOnly: true
        type: array
        items:
          $ref: '#/definitions/TimezoneZone'
      iso3166:
        description: ISO 3166 alpha-2 country codes
        readOnly: true
        type: array
        items:
          $ref: '#/definitions/TimezoneIso3166'
    example:
      $ref: '#/externalDocs/x-mocks/TimezoneInfoExample'

  TimezoneZone:
    description: ISO 3166 alpha-2 country code and zone name
    type: object
    required:
    - cca2
    - name
    - offset
    properties:
      cca2:
        description: ISO 3166 alpha-2 country code
        type: string
        pattern: '[A-Z]{2}'
      name:
        description: zone name
        type: string
      offset:
        description: zone offset (format should be "+0800", etc)
        type: string

  TimezoneIso3166:
    description: ISO 3166 alpha-2 country code and country name
    type: object
    required:
    - cca2
    - name
    properties:
      cca2:
        description: ISO 3166 alpha-2 country code
        type: string
        pattern: '[A-Z]{2}'
      name:
        description: The usual English name for the coded region
        type: string

externalDocs:
  url: '#'
  x-mocks:
    TimeExample:
      {
          "time": "2015-03-26T16:27:48.611441Z",
          "timezone": "Asia/Taipei",
          "ntp": {
            "enable": false,
            "server": "pool.ntp.org",
            "interval": 86400
          }
      }
    NTPExample:
      {
        "enable": false,
        "server": "pool.ntp.org",
        "interval": 86400
      }
    TimezoneInfoExample:
      {
        "zone": [
          {
            "cca2": "AD",
            "name": "Europe/Andorra",
            "offset": "+0100"
          },
          {
            "cca2": "AE",
            "name": "Asia/Taipei",
            "offset": "+0800"
          },
          {
            "cca2": "AF",
            "name": "America/New_York",
            "offset": "-0400"
          }
        ],
        "iso3166": [
          {
            "cca2": "AD",
            "name": "Andorra"
          },
          {
            "cca2": "AE",
            "name": "United Arab Emirates"
          },
          {
            "cca2": "AF",
            "name": "Afghanistan"
          }
        ]
      }