swagger: "2.0"
info:
  description: ""
  version: "0.0.0"
  title: ""
basePath: "/faap/v1/"
tags:
  - name: "collection"
    description: "Mongodb operations"
  - name: "user"
    description: "Inner auth, used if USE_INNER_AUTH option set to true (default: false)"
  - name: "upload"
    description: "Uploading files, used if ENABLE_UPLOADS option set to true (default: false)"
  - name: "tools"
    description: "used if ENABLE_TOOLS option set to true (default: false)"
paths:
  /{collection}:
    post:
      tags:
        - "collection"
      summary: "Insert data to collection"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "body"
          in: "body"
          description: "Data that needs to be added to the store"
          required: true
          schema:
            $ref: "#/definitions/ItemForm"
      responses:
        201:
          description: "Success"
          schema:
            $ref: "#/definitions/Item"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
    get:
      tags:
        - "collection"
      summary: "Get saved data's from collection as list"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "sort"
          in: "query"
          description: "Sorted field name, -fieldName descending, fieldName ascending"
          type: "string"
        - name: "per-page"
          in: "query"
          description: "items on page"
          type: "string"
        - name: "page"
          in: "query"
          description: "pagination page"
          type: "string"
        - name: "q"
          in: "query"
          description: "insensitive search in searchBody field"
          type: "string"
        - name: "filter"
          in: "query"
          type: "string"
          description: "See filter model"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Items"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /{collection}/{id}:
    patch:
      tags:
        - "collection"
      summary: "Update data in collection"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "id"
          in: "path"
          required: true
          description: "Id of data"
          type: "string"
        - name: "body"
          in: "body"
          description: "Data that needs to be added to the store"
          required: true
          schema:
            $ref: "#/definitions/ItemForm"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Item"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
    delete:
      tags:
        - "collection"
      summary: "Delete data in collection"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "id"
          in: "path"
          required: true
          description: "Id of data"
          type: "string"
      responses:
        200:
          description: "Success"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
    get:
      tags:
        - "collection"
      summary: "Get data from collection"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "id"
          in: "path"
          required: true
          description: "Id of data"
          type: "string"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Item"
        404:
          description: "Not found"
          schema:
            $ref: "#/definitions/Error"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /user/register:
    post:
      tags:
        - "user"
      summary: "Create new user"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "body"
          in: "body"
          required: true
          schema:
            $ref: "#/definitions/UserRegForm"
      responses:
        201:
          description: "Success"
          schema:
            $ref: "#/definitions/User"
        422:
          description: "Wrong Validation"
          schema:
            $ref: "#/definitions/ErrorValidation"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
  /user/login:
    post:
      tags:
        - "user"
      summary: "Login"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "body"
          in: "body"
          required: true
          schema:
            $ref: "#/definitions/UserAuthForm"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/User"
        422:
          description: "Wrong login or pass"
          schema:
            $ref: "#/definitions/ErrorValidation"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
  /user/{id}:
    patch:
      tags:
        - "user"
      summary: "Update user profile"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "id"
          in: "path"
          required: true
          description: "Id of user"
          type: "string"
        - name: "body"
          in: "body"
          required: true
          schema:
            $ref: "#/definitions/UserEditForm"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/User"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
    get:
      tags:
        - "user"
      summary: "View user profile"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "id"
          in: "path"
          required: true
          description: "Id of user"
          type: "string"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/User"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /user:
    get:
      tags:
        - "user"
      summary: "Get saved data's from user as list"
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "sort"
          in: "query"
          description: "Sorted field name, -fieldName descending, fieldName ascending"
          type: "string"
        - name: "per-page"
          in: "query"
          description: "items on page"
          type: "string"
        - name: "page"
          in: "query"
          description: "pagination page"
          type: "string"
        - name: "q"
          in: "query"
          description: "insensitive search in searchBody field"
          type: "string"
        - name: "filter"
          in: "query"
          type: "string"
          description: "See filter model"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Items"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /upload/file:
    post:
      tags:
        - "upload"
      summary: "Uploading file"
      description: "You can upload any count of files"
      consumes:
        - "multipart/form-data"
      produces:
        - "application/json"
      parameters:
        - in: "formData"
          name: "image"
          type: "file"
        - in: "formData"
          name: "otherFile"
          type: "file"
      responses:
        201:
          description: "Success"
          schema:
            $ref: "#/definitions/UploadedItems"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        422:
          description: "Declined file ext, size"
          schema:
            $ref: "#/definitions/ErrorValidation"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /uploads/{pathToFile}:
    get:
      tags:
        - "upload"
      summary: "Show file"
      description: ""
      produces:
        - "application/octet-stream"
      parameters:
        - name: "pathToFile"
          in: "path"
          required: true
          type: "string"
      responses:
        200:
          description: "Success"
        404:
          description: "Not found"

  /tools/list-collections:
    get:
      tags:
        - "tools"
      summary: "Retrieve information about the collections and views in a database"
      description: ""
      produces:
        - "application/json"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Items"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /tools/generate-fake-data/{collection}:
    post:
      tags:
        - "tools"
      summary: ""
      description: ""
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
        - name: "body"
          in: "body"
          required: true
          schema:
            $ref: "#/definitions/GenerateFakeDataForm"
      responses:
        200:
          description: "Success"
          schema:
            $ref: "#/definitions/Items"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []
  /tools/truncate/{collection}:
    delete:
      tags:
        - "tools"
      summary: ""
      description: ""
      consumes:
        - "application/json"
      parameters:
        - name: "collection"
          in: "path"
          required: true
          description: "Name of collection"
          type: "string"
      responses:
        204:
          description: "Success"
        401:
          description: "Need auth"
          schema:
            $ref: "#/definitions/Error"
        500:
          description: "Error"
          schema:
            $ref: "#/definitions/Error"
      security:
        - api_key: []

securityDefinitions:
  api_key:
    type: "apiKey"
    name: "Authorization"
    in: "header"


definitions:
  ItemForm:
    type: "object"
    properties:
      any:
        description: "Any saved field or fields"
        type: "string"
  Item:
    type: "object"
    properties:
      id:
        type: "string"
      _id:
        type: "string"
      searchBody:
        description: "Data for fulltext search"
        type: "string"
      any:
        description: "Any saved field or fields"
        type: "string"
  Items:
    type: "object"
    properties:
      data:
        type: "array"
        items:
          $ref: "#/definitions/Item"
      _meta:
        type: "object"
      _links:
        type: "object"
  Filter:
    type: "object"
    properties:
      _fieldName:
        type: "string"
        description: "field name started of _ dont used in search"
      from_fieldName:
        type: "string"
        description: "search from"
      to_fieldName:
        type: "string"
        description: "search to"
      fieldName:
        type: "string"
        description: "filter by value"
  Error:
    type: "object"
    properties:
      status:
        type: "integer"
      message:
        type: "string"
  ErrorValidation:
    type: "object"
    properties:
      status:
        type: "integer"
      message:
        type: "string"
      _meta:
        type: "object"
        properties:
          fieldName:
            type: "string"
            description: "Wrong validate field msg"
          otherFieldName:
            type: "string"
            description: "Wrong validate field msg"
  User:
    type: "object"
    properties:
      id:
        type: "string"
      _id:
        type: "string"
      login:
        type: "string"
      password:
        type: "string"
      token:
        type: "string"
      any:
        description: "Any saved field or fields"
        type: "string"
  UserAuthForm:
    type: "object"
    properties:
      login:
        type: "string"
      password:
        type: "string"
  UserRegForm:
    type: "object"
    properties:
      login:
        type: "string"
      password:
        type: "string"
      any:
        description: "Any field or fields needed to store"
        type: "string"
  UserEditForm:
    type: "object"
    properties:
      password:
        description: "If send, token and passhash was changed"
        type: "string"
      any:
        description: "Any field or fields needed to store"
        type: "string"
  UploadedFile:
    type: "object"
    properties:
      name:
        type: "string"
      mimetype:
        type: "string"
      fileName:
        type: "string"
      fileMd5:
        type: "string"
      relativeFilePath:
        type: "string"
      relativeUrl:
        type: "string"
  UploadedItems:
    type: "object"
    properties:
      file1:
        type: "object"
        $ref: "#/definitions/UploadedFile"
      file2:
        type: "object"
        $ref: "#/definitions/UploadedFile"
  GenerateFakeDataForm:
    type: "object"
    properties:
      count:
        description: "Count of created collections"
        type: "number"
        example: 1
      faker.fake:
        $ref: "#/definitions/FakerFake"
  FakerFake:
    type: "object"
    properties:
      title:
        description: "in value set template for Faker.fake(), more: https://github.com/marak/Faker.js/#fakerfake"
        type: "string"
        example: "{{commerce.productName}} {{commerce.productMaterial}}"
      body:
        type: "string"
        example: "{{lorem.paragraphs}}"
      creation_date:
        type: "string"
        example: "{{date.past}}"
      is_important:
        type: "string"
        example: "{{random.boolean}}"

