openapi: 3.0.0
info:
  title: GNUBoat Mapservice 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 to upload log files with water depth to GNUBoat server
servers:
  - url: 'https://gnuboat.engsas.com/mapservice/{version}'
    description: The production API server
    variables:
      version:
        default: v1
  - url: 'http://localhost:8080/mapservice/{version}'
    description: The local flask development url
    variables:
      version:
        default: v1
paths:
  /user:
    get:
      description: Returns information of current/authorized user
      tags:
        - users
      summary: Returns info of a user
      operationId: usersGet
      security:
        - basicAuth: []
        - apiKeyAuth: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              examples:
                User:
                  $ref: '#/components/examples/User'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
    post:
      description: Registers a new user
      tags:
        - users
      summary: Registers a new user
      operationId: usersRegister
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserCreation'
            examples:
              Water:
                $ref: '#/components/examples/UserCreation'
      responses:
        '201':
          description: Userr created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
              examples:
                Water:
                  $ref: '#/components/examples/User'
        '400':
          $ref: '#/components/responses/BadRequest'
    options:
      description: Used by CORS preflight
      tags:
        - users
      responses:
        '200':
          description: CORS prefilght requests should return 200 as status code
          content:
            application/json: {}
  /user/apikey_create:
    get:
      description: Generates and returns a new API key for current user
      tags:
        - users
      summary: Returns a new API key
      operationId: usersApiKeyCreate
      security:
        - basicAuth: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/apiKeys'
              example: NewApiKey4711
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  '/user/{api_key}':
    delete:
      description: Deletes given API key and returns remaining API keys of the user
      tags:
        - users
      summary: Deletes API key
      operationId: usersApiKeyDelete
      security:
        - basicAuth: []
      parameters:
        - name: api_key
          in: path
          description: API key
          required: true
          schema:
            $ref: '#/components/schemas/apiKey'
          example: DelApiKey4711
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/apiKeys'
              example: ApiKey4711
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  '/user/activate/{activation_code}':
    get:
      description: Activates a user account
      tags:
        - users
      summary: Activates a user account
      operationId: usersActivate
      parameters:
        - name: activation_code
          in: path
          description: Activation code
          required: true
          schema:
            $ref: '#/components/schemas/activationCode'
          example: dac9630aec642a428cd73f4be0a03569
      responses:
        '302':
          description: OK or not OK
          headers:
            Location:
              schema:
                type: string
              description: 'URL to the website, showing the result of the activation'
  /waters:
    get:
      description: Returns all waters
      tags:
        - waters
      summary: Find waters by id
      operationId: watersGet
      parameters:
        - name: name
          in: query
          schema:
            $ref: '#/components/schemas/itemName'
          example: Missi
        - name: manager
          in: query
          schema:
            $ref: '#/components/schemas/username'
          example: jane
        - $ref: '#/components/parameters/orderBy'
        - $ref: '#/components/parameters/offset'
        - $ref: '#/components/parameters/limit'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/waters'
              examples:
                Waters:
                  $ref: '#/components/examples/waters'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      description: Adds a new water to the database
      tags:
        - waters
      summary: Add a new water
      operationId: watersCreate
      security:
        - basicAuth: []
        - apiKeyAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WaterCreation'
            example:
              name: Rhein
              osmId: 1756854
              osmType: Relation
      responses:
        '201':
          description: Water created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Water'
              examples:
                Water:
                  $ref: '#/components/examples/Water'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  '/waters/{id}':
    get:
      description: Returns the water identified by id
      tags:
        - waters
      summary: Represents a water
      operationId: watersGetById
      parameters:
        - name: id
          in: path
          description: Item ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Water'
              examples:
                Water:
                  $ref: '#/components/examples/Water'
        '404':
          $ref: '#/components/responses/NotFound'
  '/waters/{water_id}/gauges':
    get:
      description: Returns all gauges of water waterId
      tags:
        - waters
      summary: Find gauges of water waterId by gaugeId
      operationId: watersGaugesGet
      parameters:
        - name: water_id
          in: path
          description: Water ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
        - name: name
          in: query
          schema:
            $ref: '#/components/schemas/itemName'
          example: Missi
        - name: manager
          in: query
          schema:
            $ref: '#/components/schemas/username'
          example: jane
        - $ref: '#/components/parameters/orderBy'
        - $ref: '#/components/parameters/offset'
        - $ref: '#/components/parameters/limit'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Gauges'
              examples:
                Gauges:
                  $ref: '#/components/examples/Gauges'
            application/geo+json:
              schema:
                $ref: '#/components/schemas/GaugesGeoJson'
              examples:
                Gauge:
                  $ref: '#/components/examples/GaugesGeoJson'
    post:
      description: Adds a new gauge for water waterId to the database
      tags:
        - waters
      summary: Add a new water
      operationId: watersGaugeCreate
      parameters:
        - name: water_id
          in: path
          description: Water ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
      security:
        - basicAuth: []
        - apiKeyAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GaugeCreation'
            example:
              name: New Orleans
              location:
                - 90.136111
                - 29.934722
      responses:
        '201':
          description: Gauge created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Gauge'
              examples:
                Gauge:
                  $ref: '#/components/examples/Gauge'
            application/geo+json:
              schema:
                $ref: '#/components/schemas/GaugeGeoJson'
              examples:
                Gauge:
                  $ref: '#/components/examples/GaugeGeoJson'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  '/waters/{water_id}/gauges/{gauge_id}':
    get:
      description: Returns the gauge identified by id
      tags:
        - waters
      summary: Represents a gauge
      operationId: watersGaugeGetById
      parameters:
        - name: water_id
          in: path
          description: Water ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
        - name: gauge_id
          in: path
          description: Gauge ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Gauge'
              examples:
                Gauge:
                  $ref: '#/components/examples/Gauge'
            application/geo+json:
              schema:
                $ref: '#/components/schemas/GaugeGeoJson'
              examples:
                Gauge:
                  $ref: '#/components/examples/GaugeGeoJson'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
  /devices:
    get:
      description: Returns all devices of user
      tags:
        - devices
      summary: Find devices by id
      operationId: devicesGet
      security:
        - basicAuth: []
        - apiKeyAuth: []
      parameters:
        - name: name
          in: query
          schema:
            $ref: '#/components/schemas/itemName'
          example: Love
        - $ref: '#/components/parameters/orderBy'
        - $ref: '#/components/parameters/offset'
        - $ref: '#/components/parameters/limit'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/devices'
              examples:
                Devices:
                  $ref: '#/components/examples/devices'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      description: Adds a new device to the database
      tags:
        - devices
      summary: Add a new device
      operationId: devicesCreate
      security:
        - basicAuth: []
        - apiKeyAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeviceCreation'
            example:
              name: Lovely Boat
              sensorDepth: 2
      responses:
        '201':
          description: Device created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Device'
              examples:
                Device:
                  $ref: '#/components/examples/Device'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  '/devices/{id}':
    get:
      description: Returns the device identified by id
      tags:
        - devices
      summary: Represents a device
      operationId: devicesGetById
      security:
        - basicAuth: []
        - apiKeyAuth: []
      parameters:
        - name: id
          in: path
          description: Item ID
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Device'
              examples:
                Water:
                  $ref: '#/components/examples/Device'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      description: Deletes given device and returns remaining devices of the user
      tags:
        - devices
      summary: Deletes device
      operationId: devicesDeviceDelete
      security:
        - basicAuth: []
        - apiKeyAuth: []
      parameters:
        - name: id
          in: path
          description: Item id
          required: true
          schema:
            $ref: '#/components/schemas/itemId'
          example: 1
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/devices'
              example:
                Devices:
                  $ref: '#/components/examples/devices'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      x-basicInfoFunc: openapi_server.server_impl.security.Security.auth_basic
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
      x-apikeyInfoFunc: openapi_server.server_impl.security.Security.auth_api
  schemas:
    username:
      title: Username
      type: string
    apiKey:
      title: API Key
      type: string
    apiKeys:
      title: Array of API keys
      type: array
      items:
        $ref: '#/components/schemas/apiKey'
    activationCode:
      title: Activation code for a User
      type: string
    itemId:
      title: Item ID
      type: integer
      format: int32
    itemName:
      title: Item Name
      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
    osmType:
      title: OSM type of item (N|W|R)
      type: string
      enum:
        - Node
        - Way
        - Relation
    comment:
      title: Comment of an item
      type: string
    point:
      title: 'Point of type [longitude, latitude]'
      type: array
      maxItems: 2
      minItems: 2
      items:
        type: number
    geoJsonType:
      title: Type of GeoJSON objects
      type: string
      enum:
        - Feature
        - Point
    geoJsonPoint:
      type: object
      description: GeoJSon geometry
      externalDocs:
        url: 'http://geojson.org/geojson-spec.html#id2'
      properties:
        type:
          type: string
        coordinates:
          $ref: '#/components/schemas/point'
    sensorDepth:
      type: number
      title: Depth of sensor beneath water level in cm (positive means below water)
      minimum: 0
    User:
      title: User
      type: object
      properties:
        username:
          $ref: '#/components/schemas/username'
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        activated:
          type: boolean
        apiKeys:
          $ref: '#/components/schemas/apiKeys'
    UserCreation:
      title: User
      type: object
      properties:
        username:
          $ref: '#/components/schemas/username'
        email:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        password:
          type: string
      required:
        - username
        - email
        - firstName
        - lastName
        - password
    Water:
      title: Water
      type: object
      properties:
        waterId:
          $ref: '#/components/schemas/itemId'
        name:
          $ref: '#/components/schemas/itemName'
        manager:
          $ref: '#/components/schemas/username'
        osmId:
          $ref: '#/components/schemas/itemId'
        osmType:
          $ref: '#/components/schemas/osmType'
        gauges:
          $ref: '#/components/schemas/Gauges'
      required:
        - waterId
        - name
    WaterCreation:
      title: Water for Creation
      type: object
      properties:
        name:
          $ref: '#/components/schemas/itemName'
        osmId:
          $ref: '#/components/schemas/itemId'
        osmType:
          $ref: '#/components/schemas/osmType'
      required:
        - name
    waters:
      title: waters
      type: array
      items:
        $ref: '#/components/schemas/Water'
    Gauge:
      title: Gauge
      type: object
      properties:
        gaugeId:
          $ref: '#/components/schemas/itemId'
        name:
          $ref: '#/components/schemas/itemName'
        manager:
          $ref: '#/components/schemas/username'
        location:
          $ref: '#/components/schemas/point'
        comment:
          $ref: '#/components/schemas/comment'
      required:
        - gaugeId
        - name
        - location
    GaugeCreation:
      title: Gauge for Creation
      type: object
      properties:
        name:
          $ref: '#/components/schemas/itemName'
        location:
          $ref: '#/components/schemas/point'
        comment:
          $ref: '#/components/schemas/comment'
      required:
        - name
        - location
    Gauges:
      title: Gauges
      type: array
      items:
        $ref: '#/components/schemas/Gauge'
    GaugeGeoJson:
      title: Gauge
      type: object
      properties:
        type:
          $ref: '#/components/schemas/geoJsonType'
        geometry:
          $ref: '#/components/schemas/geoJsonPoint'
        properties:
          type: object
          properties:
            name:
              $ref: '#/components/schemas/itemName'
            manager:
              $ref: '#/components/schemas/username'
            comment:
              $ref: '#/components/schemas/comment'
          required:
            - name
      required:
        - type
        - geometry
        - properties
    GaugesGeoJson:
      title: Gauges in GeoJson format
      type: array
      items:
        $ref: '#/components/schemas/GaugeGeoJson'
    Device:
      title: Device
      type: object
      properties:
        deviceId:
          $ref: '#/components/schemas/itemId'
        name:
          $ref: '#/components/schemas/itemName'
        sensorDepth:
          $ref: '#/components/schemas/sensorDepth'
        comment:
          $ref: '#/components/schemas/comment'
      required:
        - deviceId
        - name
        - sensorDepth
    DeviceCreation:
      title: Device for Creation
      type: object
      properties:
        name:
          $ref: '#/components/schemas/itemName'
        sensorDepth:
          $ref: '#/components/schemas/sensorDepth'
        comment:
          $ref: '#/components/schemas/comment'
      required:
        - name
        - sensorDepth
    devices:
      title: Devices
      type: array
      items:
        $ref: '#/components/schemas/Device'
    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
  parameters:
    orderBy:
      name: orderBy
      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
  examples:
    User:
      value:
        username: jane
        email: jane@example.org
        firstName: Jane
        lastName: Doe
        activated: true
        apiKeys:
          - ApiKey4701
    UserCreation:
      value:
        username: richard
        email: richard@examle.org
        firstName: Richard
        lastName: Roe
        password: sdfl.1238_ASDkeil?
    Water:
      value:
        waterId: 1
        name: Mississippi
        osmId: 1756854
        osmType: R
      summary: A water example object
    WaterCreation:
      value:
        name: Mississippi
        osmId: 1756854
        osmType: Relation
      summary: A water example object for creation of a water
    waters:
      value:
        - waterId: 1
          name: Mississippi
          osmId: 1756854
          osmType: Relation
        - waterId: 2
          name: Bodensee
      summary: A sample list with waters
    Gauge:
      value:
        gaugeId: 1
        name: New Orleans
        manager: jane
        location:
          - 90.136111
          - 29.934722
        comment: Gauge for Mississippi in New Orleans
    Gauges:
      value:
        - gaugeId: 1
          name: New Orleans
          manager: jane
          location:
            - 90.136111
            - 29.934722
      summary: A sample list of gauges
    GaugeGeoJson:
      value:
        type: Feature
        geometry:
          type: Point
          coordinates:
            - 90.136111
            - 29.934722
          properties:
            name: New Orleans
            manager: jane
            comment: Gauge for Mississippi in New Orleans
    GaugesGeoJson:
      value:
        - type: Feature
          geometry:
            type: Point
            coordinates:
              - 90.136111
              - 29.934722
            properties:
              name: New Orleans
              manager: jane
              comment: Gauge for Mississippi in New Orleans
      summary: A sample list of gauges in GeoJson format
    Device:
      value:
        deviceId: 1
        name: Lovely Boat
        sensorDepth: 0.2
        comment: Really a pleasure to measure
      summary: A sample device
    devices:
      value:
        - deviceId: 1
          name: Lovely Boat
          sensorDepth: 0.2
          comment: Really a pleasure to measure
    HttpError:
      value:
        type: "http://example.com/waters/not-found"
        title: "Water 1 not found"
        detail: "There is no water with id 1 in database"
        instance: "http://example.net/waters/1"
  responses:
    BadRequest:
      description: Bad Request (400)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
          examples:
            HttpError:
              $ref: '#/components/examples/HttpError'
    Unauthorized:
      description: Unauthorized (401) acces to resource
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
          examples:
            HttpError:
              $ref: '#/components/examples/HttpError'
    NotFound:
      description: Water with given Id not found
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/HttpError'
          examples:
            HttpError:
              $ref: '#/components/examples/HttpError'
tags:
  - name: waters
    description: >-
      A water is a river (like Mississippi, lake (Lake Ontario), or a sea (North
      Sea)
  - name: users
    description: All actions used to manage users and api keys
  - name: devices
    description: All actions used to manage devices of an user
