openapi: 3.0.0
info:
  title: GNUBoat Device API
  contact:
    name: EngSaS - Engineering Solutions and Services Langenbach
    url: 'http://www.engsas.com'
    email: info@engsas.de
  license:
    name: GPL 3
    url: 'https://www.gnu.org/licenses/gpl-3.0.en.html'
  version: v1
  description: API for GNUBoat devices
servers:
  - url: 'http://gnuboat/deviceservice/{version}'
    description: The production API server
    variables:
      version:
        default: v1
  - url: 'http://localhost:8090/deviceservice/{version}'
    description: The local flask development url
    variables:
      version:
        default: v1
paths:
  '/instrumentdata':
    get:
      description: The current dates like speed, water depth, ...
      tags:
        - device
      operationId: instrumentDataGet
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InstrumentData'
        '404':
          description: Returned, if there is no current, valid dataset
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/track':
    get:
      description: The track with dates like speed, water depth, ...
      tags:
        - device
      operationId: trackGet
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Track'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/shutdown':
    get:
      description: Shutdown the device
      tags:
        - device
      operationId: shutdown
      responses:
        '204':
          description: Shutdown initiated
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/logfiles':
    get:
      description: List of local logfiles
      tags:
        - deviceLogs
      operationId: logfilesGet
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Logfiles'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/logfiles/{name}':
    get:
      description: Download local logfiles
      tags:
        - deviceLogs
      operationId: logsGet
      parameters:
        - name: name
          in: path
          description: Logfiles to download
          required: true
          schema:
            type: string
          style: simple
          explode: true
          example: 'test-1.log,test-2.log'
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string
            application/zip:
              schema:
                type: string
                format: byte
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/logfiles/{name}/track':
    get:
      description: Get the logfile as a track
      tags:
        - deviceLogs
      operationId: logsTrackGet
      parameters:
        - name: name
          in: path
          description: Logfiles to download
          required: true
          schema:
            type: string
          example: 'test-1.log'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Track'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/maps':
    get:
      description: Get a list of currently installed maps
      tags:
        - deviceMaps
      operationId: mapsGet
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Maps'
        '500':
          $ref: '#/components/responses/InternalServerError'
    post:
      description: Upload a new mbtiles file as a new map
      tags:
        - deviceMaps
      operationId: mapsUpload
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema:
              type: string
              format: byte
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Maps'
        '400':
          $ref: '#/components/responses/BadRequest'
        '413':
          $ref: '#/components/responses/PayloadToLarge'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/maps/{mapname}/{zoom}/{x_tile}/{y_tile}.png':
    get:
      description: Get tiles of a map with help of it's tiles urls
      tags:
        - deviceMaps
      operationId: mapsTileGet
      parameters:
        - name: mapname
          in: path
          description: Map basename
          required: true
          schema:
            type: string
          example: '7f92508911d84ff957acc862fd38bdafddbaae14ce508dda2aa6857e73863318'
        - name: zoom
          in: path
          description: Zoomlevel
          required: true
          schema:
            type: integer
          example: 15
        - name: x_tile
          in: path
          description: Number of the tile in x dimension
          required: true
          schema:
            type: integer
          example: 17298
        - name: y_tile
          in: path
          description: Number of the tile in y dimension
          required: true
          schema:
            type: integer
          example: 21435
      responses:
        '200':
          description: OK
          content:
            image/*:
              schema:
                type: string
                format: binary
                #contentEncoding: base64
                #contentMediaType: image/png
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/mapservice':
    get:
      description: The status of the mapservice connection
      tags:
        - mapservice
      operationId: mapserviceStatus
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MapserviceStatus'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '502':
          $ref: '#/components/responses/BadGatewayError'
        '504':
          description: Mapservice has not answered and connection timed out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MapserviceStatus'
  '/mapservice/waters':
    get:
      description: Search waters on mapservice
      tags:
        - mapservice
      summary: Find own waters
      operationId: watersGet
      parameters:
        - name: name
          in: query
          schema:
            $ref: '#/components/schemas/itemName'
          example: Test
        - $ref: '#/components/parameters/orderBy'
        - $ref: '#/components/parameters/offset'
        - $ref: '#/components/parameters/limit'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Waters'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '502':
          $ref: '#/components/responses/BadGatewayError'
        '504':
          description: Mapservice has not answered and connection timed out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MapserviceStatus'
  '/mapservice/log':
    post:
      description: Upload log to the mapservice
      tags:
        - mapservice
      summary: Add a new log
      operationId: logCreate
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LogCreation'
      responses:
        '204':
          description: Log created
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '502':
          $ref: '#/components/responses/BadGatewayError'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    point:
      title: 'Point of type [longitude, latitude] in decimal degrees'
      type: array
      maxItems: 2
      minItems: 2
      items:
        type: number
    speedOverGround:
      title: Speed over Ground in m/s
      type: number
      format: float
    speedThroughWater:
      title: Speed through the water in m/s
      type: number
      format: float
    courseOverGround:
      title: Course over the ground in degree
      type: number
      format: float
      minimum: 0
      maximum: 360
    waterDepth:
      title: Water depth in m
      type: number
      format: float
    waterTemperature:
      title: Water temperature in degree celsius
      type: number
      format: float
    gpsFix:
      title: Status of GPS fix
      type: string
      enum:
        - '-'
        - '2D'
        - '3D'
    InstrumentData:
      title: Data displayed in the instrument section
      type: object
      properties:
        speedThroughWater:
          $ref: '#/components/schemas/speedThroughWater'
        speedOverGround:
          $ref: '#/components/schemas/speedOverGround'
        courseOverGround:
          $ref: '#/components/schemas/courseOverGround'
        waterDepth:
          $ref: '#/components/schemas/waterDepth'
        waterTemperature:
          $ref: '#/components/schemas/waterTemperature'
        position:
          $ref: '#/components/schemas/point'
        gpsFix:
          $ref: '#/components/schemas/gpsFix'
      required:
        - speedOverGround
        - courseOverGround
        - waterDepth
        - position
        - gpsFix
    Track:
      title: List of InstrumentData sorted by time
      type: object
      additionalProperties:
        type: object
        properties:
          code:
            type: integer
            format: int64
          text:
            $ref: '#/components/schemas/InstrumentData'
    Logfile:
      title: A logfile
      type: string
    Logfiles:
      title: Array of logfiles
      type: array
      items:
        $ref: '#/components/schemas/Logfile'
    map:
      title: Represents a Map
      description: Following the tilejson specification https://github.com/mapbox Version 2.0.0
      type: object
      properties:
        tilejson:
          description: Version number of the tilejson spec (semver.org style)
          type: string
        name:
          description: Name describing the tileset
          type: string
        description:
          type: string
        version:
          description: semver.org style version number of the map
          type: string
        attribution:
          description: Attribution label of the map (could be interprated as HTML or literal text)
          type: string
        template:
          description: Mustache tamplate for format data from grids
          type: string
        legend:
          description: Legend to be displayed (could be treated as HTML or literal text)
          type: string
        schema:
          description: The map tile scheme (xyz or tms). If missing xyz
          type: string
          enum:
            - 'xyz'
            - 'tms'
          default: 'xyz'
        tiles:
          description: Url to get the tiles from. It must be at least one endpoint. If more than one endpoints given, all must return the same information for the same url. {z}, {y}, {x} should be replaced by zoomleve, y tile number and x tile number.
          type: array
          items:
            type: string
            minItems: 1
        grids:
          description: An array of interactivity endpoints
          type: array
          items:
            type: string
        data:
          description: An array of data files in GeoJSON format
          type: array
          items:
            type: string
        minzoom:
          type: integer
          minimum: 0
          maximum: 30
          default: 0
        maxzoom:
          type: integer
          minimum: 0
          maximum: 30
          default: 30
        bounds:
          description: The maximum extent of available map tiles at any zoomlevel, in WGS84 reference system. The bounds are given in the order left, bottom, right, top
          type: array
          items:
            type: number
            format: float
            minItems: 4
            maxItems: 4
        center:
          description: Initial values of longitude, latitude and zoomlevel
          type: array
          items:
            type: number
            format: float
            minItems: 3
            maxItems: 3
      required:
        - tilejson
        - tiles
    Maps:
      title: List of Map
      type: array
      items:
        $ref: '#/components/schemas/map'
    MapserviceStatus:
      type: string
      enum:
        - 'NO_API_KEY'
        - 'NO_DEVICE'
        - 'DEVICE_NOT_FOUND'
        - 'NO_CONNECTION'
        - 'OK'
    itemName:
      title: Item Name
      type: string
    itemId:
      title: Item ID
      type: integer
      format: int64
    comment:
      title: Comment of an item
      type: string
    order:
      title: order
      enum:
        - desc
        - asc
      type: string
      default: asc
      description: |
        Sort order:
          * `asc` - Ascending, from A to Z
          * `desc` - Descending, from Z to A
      example: asc
    Water:
      title: Water
      type: object
      properties:
        waterId:
          $ref: '#/components/schemas/itemId'
        name:
          $ref: '#/components/schemas/itemName'
        gauges:
          $ref: '#/components/schemas/Gauges'
      required:
        - waterId
        - name
    Waters:
      title: A list of Water
      type: array
      items:
        $ref: '#/components/schemas/Water'
    ReferenceWaterLevelGaugeHeight:
      title: Gauge Height of reference water level of a Gauge
      description: The gauge height (stage) for reference water level. The reference water level is the water level, the depth on the map is shown at. Therefore, the water depth of a LogEntry is transformed to this referenceWaterLevel, with help of the gaugeHeight of the Log related to the LogEntry.
      type: number
      format: float
    GaugeHeight:
      title: 'Gauge height (stage) of the gauge, at the time of measuring'
      type: number
      format: float
    Gauge:
      title: Gauge
      type: object
      properties:
        gaugeId:
          $ref: '#/components/schemas/itemId'
        name:
          $ref: '#/components/schemas/itemName'
        location:
          $ref: '#/components/schemas/point'
        referenceWaterLevelGaugeHeight:
          $ref: '#/components/schemas/ReferenceWaterLevelGaugeHeight'
        comment:
          $ref: '#/components/schemas/comment'
      required:
        - gaugeId
        - name
        - location
        - referenceWaterLevelGaugeHeight
    Gauges:
      title: Gauges
      type: array
      items:
        $ref: '#/components/schemas/Gauge'
    LogCreation:
      title: Log for Creation
      type: object
      properties:
        water:
          $ref: '#/components/schemas/itemId'
        gauge:
          $ref: '#/components/schemas/itemId'
        gaugeHeight:
          $ref: '#/components/schemas/GaugeHeight'
        comment:
          $ref: '#/components/schemas/comment'
        logfile:
          $ref: '#/components/schemas/Logfile'
        delete:
          description: Delete the logfile locally after successfull upload
          type: boolean
          default: True
      required:
        - water
        - gauge
        - gaugeHeight
        - logfile
      example:
        water: 1
        gauge: 1
        gaugeHeight: 66
        logfile: test-1.log
        comment: 'LogCreation for auto generated tests'
    HttpError:
      title: HTTP Error Response Object
      type: object
      properties:
        type:
          type: string
        title:
          type: string
        detail:
          type: string
        instance:
          type: string
      required:
        - type
        - title
        - detail
        - instance
  responses:
    BadRequest:
      description: Bad Request (400)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
    Unauthorized:
      description: Unauthorized (401) acces to resource
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
    NotFound:
      description: Item with given Id not found
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
    PayloadToLarge:
      description: Uploaded file is to large (413)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
    InternalServerError:
      description: Internal Server Error (HTTP Code 500)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
    BadGatewayError:
      description: Bad Gateway (HTTP Code 502)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
  parameters:
    orderBy:
      name: order_by
      in: query
      description: 'Order by field: name'
      schema:
        type: string
        default: name
        example: name
    order:
      name: order
      in: query
      description: Order
      schema:
        $ref: '#/components/schemas/order'
      example: ''
    offset:
      name: offset
      in: query
      description: >-
        Skip over a number of elements by specifying an offset value for the
        query
      schema:
        type: integer
        format: int32
        default: 0
        example: 0
    limit:
      name: limit
      in: query
      description: Limit the number of elements on the response
      style: form
      explode: true
      schema:
        type: integer
        format: int32
        default: 10
        example: 10
tags:
  - name: device
    description: All actions related to the device functionality
  - name: deviceLogs
    description: All actions for handling logs on the local device
  - name: deviceMaps
    description: All actions for handlings maps on the local device
  - name: mapservice
    description: All actions used to interact with a GNUBoat mapservice
