openapi: 3.0.0
info:
  title: ows-vector-job-rules
  description: Microservice for job priority rules for VECTOR
  version: 1.0.0
servers:
  - url: http://qa-ows-vector-job-rules.theorchard.io
    description: QA server
  - url: http://ows-vector-job-rules.theorchard.io
    description: Production server
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                example:
                  status: 'ok'
  /rules:
    parameters:
      - $ref: '#/components/parameters/UserID'
    get:
      summary: Retrieve list of all vector job priority rules
      parameters:
        - description: Status filter
          in: query
          name: status
          required: false
          schema:
            type: string
        - description: Comma separated list to filter specific rules
          in: query
          name: rule_ids
          required: false
          schema:
            type: string
      responses:
        200:
          description: 200 Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/VectorJobRule'
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Retrieve all vector job rules
    post:
      summary: Create a new vector job priority rule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VectorJobRule'
      responses:
        201:
          description: 201 Resource Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse201'
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Create a new rule comprised of the criteria set.
    patch:
      summary: Create a new vector job priority rule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VectorJobRule'
      responses:
        201:
          description: 201 Resource Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse201'
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Create a new rule comprised of the criteria set.
  /rules/{rule_id}:
    parameters:
      - $ref: '#/components/parameters/UserID'
      - $ref: '#/components/parameters/RuleID'
    get:
      summary: Retrieve a vector job priority rule specified by rule identifier
      responses:
        200:
          description: 200 Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VectorJobRule'
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        404:
          description: 404 Resource Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse404RuleId'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Retrieve a specified vector job rule
    patch:
      summary: Edit a vector job priority rule specified by rule identifier
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VectorJobRule'
      responses:
        200:
          description: 200 Success
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        404:
          description: 404 Resource Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse404RuleId'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Edit a specified rule with the provided the criteria set.
  /rules/conditions:
    parameters:
      - $ref: '#/components/parameters/UserID'
    get:
      summary: Retrieve all condition fields for vector job priority rules
      responses:
        200:
          description: 200 Success
          content:
            application/json:
              schema:
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/VectorJobRuleConditionField'
        400:
          description: 400 Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse400'
        403:
          description: 403 Unauthorized Access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse403'
        500:
          description: 500 Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse500'
      description: Retrieve all condition fields for vector job rules
components:
  parameters:
    UserID:
      description: Orchard User Id
      in: header
      name: Orchard-User-Id
      required: true
      schema:
        type: string
    RuleID:
      description: Unique identifier of rule
      in: path
      name: rule_id
      required: true
      schema:
        type: integer
  schemas:
    ErrorResponse400:
      description: 400 error
      type: object
      properties:
        code:
          type: integer
          example: 400
        message:
          type: string
          example: Invalid request data.
    ErrorResponse403:
      description: 403 error
      type: object
      properties:
        code:
          type: integer
          example: 403
        message:
          type: string
          example: Unauthorized access.
    ErrorResponse404RuleId:
      description: 404 error for rule id
      type: object
      properties:
        code:
          type: integer
          example: 404
        message:
          type: string
          example: Rule <rule_id> not found.
    ErrorResponse500:
      description: 500 error
      type: object
      properties:
        code:
          type: integer
          example: 500
        message:
          type: string
          example: Cannot connect to database server.
    SuccessResponse201:
      description: 201 success
      type: object
      properties:
        code:
          type: integer
          example: 201
        message:
          type: string
          example: Entry successfully created.
    VectorJobRule:
      description: A single vector job rule
      type: object
      properties:
        id:
          type: integer
          example: 111
          readOnly: true
        status:
          type: string
          example: 'active'
        priority:
          type: integer
          example: 1
        description:
          type: string
          example: 'Rule #1'
        last_updated:
          type: string
          example: '2018-03-01 12:25:00'
          readOnly: true
        updated_by:
          type: integer
          example: 179
          readOnly: true
        conditions:
          type: array
          items:
            allOf:
                - $ref: '#/components/schemas/VectorJobRuleConditionField'
                - type: object
                  properties:
                    rule_condition_value:
                      type: string
                      example: '1'
    VectorJobRuleConditionField:
      description: Condition field items that compose a rule
      type: object
      properties:
        rule_condition_field_id:
          type: integer
          example: 1
        rule_condition_field_type:
          type: string
          example: 'integer'
        name:
          type: string
          example: 'order_priority'
        description:
          type: string
          example: 'Priority value for P1, P2 or P3'
