# NOTE: Do not upgrade past Swagger 2. zclient does not support OpenAPI 3 unless
# https://github.com/Yelp/bravado/issues/306 is resolved.
swagger: "2.0"
info:
  description: "A micro service for bom backend."
  version: "1.0.0"
  title: "bom_backend"
  contact:
    name: "ygong@zoox.com"
    email: "ygong@zoox.com"
    url: "https://git.zooxlabs.com/zooxco/driving"
# Your API spec goes here.  https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
basePath: /v1

schemes:
  - "http"
  - "https"

paths:
  "/targets":
    get:
      summary: "List all distinct targets."
      operationId: "targets"
      parameters:
        - name: "offset"
          in: "query"
          description: "The offset at which to return the results."
          required: false
          type: "integer"
          default: 0
        - name: "limit"
          in: "query"
          description: "The max number of results to return."
          required: false
          type: "integer"
          default: 10000
          minimum: 1
          maximum: 100000
        - name: "targetName"
          in: "query"
          description: "The targetName."
          required: false
          type: "string"
        - name: "teamName"
          in: "query"
          description: "The team_name. If multiple team names, the string will be separated by &."
          required: false
          type: "string"
        - name: "goal"
          in: "query"
          description: "The goal. If multiple goals, the string will be separated by &."
          required: false
          type: "string"
        - name: "hapComponent"
          in: "query"
          description: "The hapComponent. If multiple hap components, the string will be separated by &."
          required: false
          type: "string"
        - name: "author"
          in: "query"
          description: "The author. If multiple authors, the string will be separated by &."
          required: false
          type: "string"
        - name: "ticket"
          in: "query"
          description: "The ticket."
          required: false
          type: "string"
        - name: "validationPass"
          in: "query"
          description: "The validationPass."
          required: false
          type: "string"
        - name: "label"
          in: "query"
          description: "The label. If multiple labels, the string will be separated by &."
          required: false
          type: "string"
        - name: "ticketId"
          in: "query"
          description: "The ticket Id."
          required: false
          type: "string"
        - name: "ticketStatus"
          in: "query"
          description: "The ticket Status."
          required: false
          type: "string"
        - name: "sortByComponentName"
          in: "query"
          description: "The sortByComponentName."
          required: false
          type: "boolean"
        - name: "showWasRemoved"
          in: "query"
          description: "The showWasRemoved."
          required: false
          type: "boolean"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TargetList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/users":
    get:
      summary: "List all distinct users."
      operationId: "users"
      parameters:
        - name: "offset"
          in: "query"
          description: "The offset at which to return the results."
          required: false
          type: "integer"
          default: 0
        - name: "limit"
          in: "query"
          description: "The max number of results to return."
          required: false
          type: "integer"
          default: 10000
          minimum: 1
          maximum: 100000
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/UserList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_users":
    get:
      summary: "List all distinct users."
      operationId: "distinctUsers"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/UserList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_roles":
    get:
      summary: "List all distinct roles."
      operationId: "distinctRoles"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/RoleList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_goals":
    get:
      summary: "List all distinct goals."
      operationId: "distinctGoals"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/GoalList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_levels":
    get:
      summary: "List all distinct levels."
      operationId: "distinctLevels"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/LevelList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/hap_components":
    get:
      summary: "List all distinct haps."
      operationId: "hapComponents"
      parameters:
        - name: "offset"
          in: "query"
          description: "The offset at which to return the results."
          required: false
          type: "integer"
          default: 0
        - name: "limit"
          in: "query"
          description: "The max number of results to return."
          required: false
          type: "integer"
          default: 10000
          minimum: 1
          maximum: 100000
        - name: "hapComponent"
          in: "query"
          description: "The hapComponent. If multiple hap components, the string will be separated by &."
          required: false
          type: "string"
        - name: "teamName"
          in: "query"
          description: "The team. If multiple teams, the string will be separated by &."
          required: false
          type: "string"
        - name: "level"
          in: "query"
          description: "ZHAP level."
          required: false
          type: "string"
        - name: "validationPass"
          in: "query"
          description: "The validationPass."
          required: false
          type: "string"
        - name: "label"
          in: "query"
          description: "The label. If multiple labels, the string will be separated by &."
          required: false
          type: "string"
        - name: "ticketId"
          in: "query"
          description: "The ticket Id."
          required: false
          type: "string"
        - name: "ticketStatus"
          in: "query"
          description: "The ticket Status."
          required: false
          type: "string"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/HapList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_teams":
    get:
      summary: "List all distinct teams."
      operationId: "distinctTeams"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TeamList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_labels":
    get:
      summary: "List all distinct labels."
      operationId: "distinctLabels"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/LabelList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_hap_labels":
    get:
      summary: "List all distinct hap labels."
      operationId: "distinctHapLabels"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/LabelList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/distinct_hap_components":
    get:
      summary: "List all distinct haps."
      operationId: "distinctHapComponents"
      parameters:
        - name: "teamName"
          in: "query"
          description: "The team_name. If multiple team names, the string will be separated by &."
          required: false
          type: "string"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/HapList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/get_all_distinct_hap_components_for_team":
    get:
      summary: "List all distinct haps."
      operationId: "getAllDistinctHapComponentsForTeam"
      parameters:
        - name: "teamName"
          in: "query"
          description: "The team_name. If multiple team names, the string will be separated by &."
          required: false
          type: "string"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/TargetList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/update_target_by_id":
    post:
      summary: "Update target values."
      operationId: "updateTargetById"
      parameters:
        - name: "id"
          in: "query"
          description: "Query id."
          required: true
          type: "string"
        - name: "target"
          in: "body"
          description: "target results."
          required: true
          schema:
            $ref: "#/definitions/Target"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/update_hap_component_by_id":
    post:
      summary: "Update hap values."
      operationId: "updateHapComponentById"
      parameters:
        - name: "hapName"
          in: "query"
          description: "hap_name."
          required: true
          type: "string"
        - name: "hap"
          in: "body"
          description: "hap results."
          required: true
          schema:
            $ref: "#/definitions/Hap"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/update_user_by_id":
    post:
      summary: "Update user values."
      operationId: "updateUserById"
      parameters:
        - name: "userName"
          in: "query"
          description: "userName."
          required: true
          type: "string"
        - name: "user"
          in: "body"
          description: "user."
          required: true
          schema:
            $ref: "#/definitions/User"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/update_team_by_id":
    post:
      summary: "Update team values."
      operationId: "updateTeamById"
      parameters:
        - name: "teamName"
          in: "query"
          description: "teamName."
          required: true
          type: "string"
        - name: "team"
          in: "body"
          description: "team."
          required: true
          schema:
            $ref: "#/definitions/Team"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/create_user_by_id":
    post:
      summary: "Update user values."
      operationId: "createUserById"
      parameters:
        - name: "userName"
          in: "query"
          description: "userName."
          required: true
          type: "string"
        - name: "teamName"
          in: "query"
          description: "user."
          required: true
          type: "string"
        - name: "role"
          in: "query"
          description: "role."
          required: true
          type: "string"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/generate_metrics":
    get:
      summary: "list all metrics."
      operationId: "generateMetrics"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/metrics":
    get:
      summary: "Get all metrics."
      operationId: "metrics"
      parameters:
        - name: "dateStr"
          in: "query"
          description: "The date string."
          required: false
          type: "string"
        - name: "offset"
          in: "query"
          description: "The offset at which to return the results."
          required: false
          type: "integer"
          default: 0
        - name: "limit"
          in: "query"
          description: "The max number of results to return."
          required: false
          type: "integer"
          default: 10000
          minimum: 1
          maximum: 100000
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/MetricsList"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/add_hap_component":
    post:
      summary: "Add new hap component"
      operationId: "addHapComponent"
      parameters:
        - name: "componentName"
          in: "query"
          description: "componentName."
          required: true
          type: "string"
        - name: "level"
          in: "query"
          description: "ZHAP level"
          required: true
          type: "string"
        - name: "teamName"
          in: "query"
          description: "teamName."
          required: true
          type: "string"
        - name: "status"
          in: "query"
          description: "status."
          required: false
          type: "string"
        - name: "ticket"
          in: "query"
          description: "ticket."
          required: false
          type: "string"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/add_team":
    post:
      summary: "Add new team."
      operationId: "addTeam"
      parameters:
        - name: "teamName"
          in: "query"
          description: "teamName."
          required: true
          type: "string"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "200":
          description: "Successful operation."
          schema:
            $ref: "#/definitions/SuccessResponse"
        "400":
          description: "Invalid parameter."
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error."
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/migrate_labels":
    post:
      summary: "Convert label from string to list."
      operationId: "migrateLabels"
      responses:
          "200":
            description: "Successfully migrated"
          "500":
            description: "Internal Server Error"
            schema:
              $ref: "#/definitions/ErrorResponse"


definitions:
  ErrorResponse:
    type: "object"
    properties:
      message:
        description: "A message describing the error."
        type: "string"

  SuccessResponse:
    type: "object"
    properties:
      message:
        description: "A message describing the success."
        type: "string"

  StringObject:
    type: "object"
    properties:
      message:
        description: "A message describing the error."
        type: "string"

  ArrayObject:
    type: "array"
    items:
          type: "string"

  MetricExperimentState:
    description: "The state of the MetricExperimentState."
    type: "string"
    enum:
      - "SUBMITTED"
      - "PENDING"
      - "RUNNING"
      - "FAILED"
      - "CANCELLED"
      - "DONE"

  Target:
    type: "object"
    properties:
      id:
        description: "The id of event"
        type: "string"
      target_name:
        description: "The target_name"
        type: "string"
      team_name:
        description: "The team"
        type: "string"
      goal:
        description: "The goal"
        type: "string"
      hap_component:
        description: "The hap_component"
        type: "string"
      example_path:
        description: "The example_path"
        type: "string"
      author:
        description: "The author"
        type: "string"
      ticket:
        description: "The ticket"
        type: "string"
      validation_pass:
        description: "The validation_pass"
        type: "boolean"
      validation_reason:
        description: "The validation_reason"
        type: "string"
      notes:
        description: "The notes"
        type: "string"
      is_removed:
        description: "The is_removed"
        type: "boolean"
      labels:
        description: "The label. If multiple labels, the string will be separated by &."
        type: "string"
  Hap:
    type: "object"
    properties:
      component_name:
        description: "The component_name"
        type: "string"
      target_str:
        description: "The target_str"
        type: "string"
      level:
        description: "ZHAP level"
        type: "string"
      team_name:
        description: "The team_name"
        type: "string"
  User:
    type: "object"
    properties:
      user_name:
        description: "The user_name"
        type: "string"
      team_name:
        description: "team_name"
        type: "string"
      role:
        description: "The role"
        type: "string"
  Team:
    type: "object"
    properties:
      team_name:
        description: "The team_name"
        type: "string"
  Metrics:
    type: "object"
    properties:
      total_count:
        description: "The total_count"
        type: "string"
      total_count_non_hap:
        description: "The total_count_non_hap"
        type: "string"
      total_count_non_hap_with_ticket:
        description: "The total_count_non_hap_with_ticket"
        type: "string"
      total_count_no_goal:
        description: "The total_count_no_goal"
        type: "string"
      total_count_with_hap_component:
        description: "The total_count_with_hap_component"
        type: "string"
      total_count_with_hap_component_without_ticket:
        description: "The total_count_with_hap_component_without_ticket"
        type: "string"
  TargetList:
    type: "object"
    properties:
      data:
        description: "The list of targets."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
  UserList:
    type: "object"
    properties:
      data:
        description: "The list of users."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
  RoleList:
    type: "object"
    properties:
      data:
        description: "The list of roles."
        type: "array"
        items:
          type: "string"
  GoalList:
    type: "object"
    properties:
      data:
        description: "The list of goals."
        type: "array"
        items:
          type: "string"
  LevelList:
    type: "object"
    properties:
      data:
        description: "The list of levels."
        type: "array"
        items:
          type: "string"
  TeamList:
    type: "object"
    properties:
      data:
        description: "The list of teams."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
  LabelList:
    type: "object"
    properties:
      data:
        description: "The list of labels."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
  HapList:
    type: "object"
    properties:
      data:
        description: "The list of haps."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
  MetricsList:
    type: "object"
    properties:
      data:
        description: "The list of metrics."
        type: "array"
        items:
          type: "object"
      total_count:
        description: "The total number of examples."
        type: "integer"
