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 for a 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: []
        - apiKeyAuth: []
      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: []
        - apiKeyAuth: []
      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'
  '/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'
    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: waterGetById
      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'
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
    osmType:
      title: OSM type of item (N|W|R)
      type: string
      enum:
        - Node
        - Way
        - Relation
    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'
      required:
        - waterId
        - name
    WaterCreation:
      title: Water
      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'
    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
    HttpError:
      title: HTTP Error Response Object
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
      required:
        - code
        - message
  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
    HttpError:
      value:
        code: 404
        message: Water with id 999999 not found
  responses:
    BadRequest:
      description: Bad Request (400)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HttpError'
          examples:
            HttpError:
              $ref: '#/components/examples/HttpError'
    Unauthorized:
      description: Unauthorized (401) acces to resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HttpError'
          examples:
            HttpError:
              $ref: '#/components/examples/HttpError'
    NotFound:
      description: Water with given Id not found
      content:
        application/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
