# 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: "Sim Service."
  version: "1.0.0"
  title: "Sim Service"
basePath: "/v1"
schemes:
- "https"
- "http"
paths:
  /scenario:
    post:
      summary: "Run scenario with simple sim"
      description: "Run scenario with simple sim"
      operationId: "scenario_sim"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "scenario"
        in: "formData"
        description: "scenario pbtxt"
        required: true
        type: "string"
      - name: "extra_sim_args"
        in: "formData"
        description: "scenario arguments"
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario id"
          schema:
            $ref: "#/definitions/ScenarioId"
        "405":
          description: "Invalid input"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /scenario/{work_id}:
    parameters:
      - in: "path"
        required: true
        type: "string"
        name: "work_id"
    get:
      summary: ""
      description: ""
      operationId: "check_worker_results"
      produces:
      - "application/json"
      responses:
        "200":
          description: "Simulation is complete"
          schema:
            $ref: "#/definitions/WorkerResult"
        "202":
          description: "Simulation is pending"
          schema:
            $ref: "#/definitions/WorkerResult"
        "404":
          description: "invalid scenario id"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /pbtxt-to-bob:
    post:
      summary: "convert pbtxt to BOB format"
      description: "convert scenario pbtxt to BOB format"
      operationId: "pbtxt_to_bob"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "scenario"
        in: "formData"
        description: "scenario pbtxt"
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario BOB b64 encoded"
          schema:
            $ref: "#/definitions/ScenarioBob"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /load-agent-database:
    post:
      summary: "load agent database"
      description: "load remote agent database to binary format"
      operationId: "load_agent_database"
      produces:
      - "application/json"
      responses:
        "200":
          description: "agent database binary b64 encoded"
          schema:
            $ref: "#/definitions/AgentDatabaseBinary"
        "404":
          description: "Failed to open file on server"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /enum-pbtxt:
    post:
      summary: "convert pbtxt into pbtxt where enums take text form"
      description: "convert pbtxt into pbtxt where enums take text form"
      operationId: "enum_pbtxt"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "scenario"
        in: "formData"
        description: "scenario pbtxt"
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario id"
          schema:
            type: "string"
            description: "scenario pbtxt"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /git-hash:
    get:
      summary: "driving repo git hash"
      description: ""
      operationId: "git_hash"
      produces:
      - "application/json"
      responses:
        "200":
          description: "driving repo git hash"
          schema:
            $ref: "#/definitions/GitHash"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /git-branch:
    get:
      summary: "driving repo git branch"
      description: ""
      operationId: "git_branch"
      produces:
      - "application/json"
      responses:
        "200":
          description: "driving repo git branch"
          schema:
            $ref: "#/definitions/GitBranch"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /convert_to_smart_log:
    post:
      summary: "convert chum uri to synthethic scenario"
      description: "convert chum uri to synthethic scenario"
      operationId: "convert_to_smart_log"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "chum_uri"
        in: "formData"
        description: "chum uri string"
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario id"
          schema:
            type: "string"
            description: "scenario pbtxt"
        "404":
          description: "Failed to parse Chum Uri"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /server-open-file:
    post:
      summary: "open file from server"
      description: "open file from server"
      operationId: "server_open_file"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "file_name"
        in: "formData"
        description: "file name string"
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario id"
          schema:
            type: "string"
            description: "scenario pbtxt"
        "404":
          description: "Failed to open file on server"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /server-save-file:
    post:
      summary: "save file to server"
      description: "save file to server"
      operationId: "server_save_file"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "file_name"
        in: "formData"
        description: "file name string"
        required: true
        type: "string"
      - name: "scenario"
        in: "formData"
        description: "scenario pbtxt"
        required: true
        type: "string"
      responses:
        "200":
          description: "result"
          schema:
            type: "string"
            description: "result"
        "404":
          description: "Failed to save file on server"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /junction-info/ids:
    post:
      parameters:
        - name: "junction_ids"
          in: "formData"
          required: true
          type: "array"
          items:
            type: "string"
        - name: "zrn_gitsha"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_name"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_hash"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_map"
          in: "formData"
          required: false
          type: "string"

      summary: "info regarding the groups in the junctions"
      operationId: "junction_info"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      responses:
        "200":
          description: "junction info"
          schema:
            $ref: "#/definitions/JunctionInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /junction-info/position:
    post:
      parameters:
        - name: "position_x"
          in: "formData"
          required: true
          type: "number"
        - name: "position_y"
          in: "formData"
          required: true
          type: "number"
        - name: "zrn_gitsha"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_name"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_hash"
          in: "formData"
          required: false
          type: "string"
        - name: "zrn_map"
          in: "formData"
          required: false
          type: "string"
      summary: "returns the junction info of the junction closest to the position"
      operationId: "junction_from_position"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      responses:
        "200":
          description: "junction info"
          schema:
            $ref: "#/definitions/JunctionInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /build_route_position_list:
    post:
      summary: "get route points of agent"
      description: "get an agent's route position list"
      operationId: "build_route_position_list"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "zrn_gitsha"
        in: "formData"
        description: "zrn identifer"
        required: true
        type: "string"
      - name: "zrn_name"
        in: "formData"
        description: "zrn name"
        required: true
        type: "string"
      - name: "entity_route"
        in: "formData"
        description: "route"
        required: true
        type: "string"
      responses:
        "200":
          description: "success message"
          schema:
            type: "string"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /copy-chum-to-nautilus:
    post:
      summary: "copy chum to nautilus"
      description: "copy chum data to nautilus to view in Argus or share"
      operationId: "copy_chum_to_nautilus"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "chum_uri"
        in: "formData"
        description: "local chum URI"
        required: true
        type: "string"
      responses:
        "200":
          description: "nautilus chum URI"
          schema:
            type: "string"
            description: "nautilus chum URI"
        "404":
          description: "Failed to copy chum to nautilus"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /create_log_test:
    post:
      summary: "create log test"
      description: "create log test"
      operationId: "create_log_test"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "data_id"
        in: "formData"
        description: "Data ID: chum URI, TRG-XXXX, etc."
        required: true
        type: "string"
      responses:
        "200":
          description: "scenario BOB b64 encoded"
          schema:
            $ref: "#/definitions/ScenarioBob"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /zrn-archive-best-fit:
    post:
      summary: "get the best fit canonical ZRN for a given ZRN archive"
      operationId: "zrn_archive_best_fit"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "zrn_map"
        in: "formData"
        description: "zrn archive map"
        required: true
        type: "string"
      - name: "zrn_hash"
        in: "formData"
        description: "zrn archive hash"
        required: true
        type: "string"
      responses:
        "200":
          description: "best fit canonical ZRN"
          schema:
            $ref: "#/definitions/CanonicalZrnId"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /populate_trajectory_set:
    post:
      summary: "populate prediction override trajectory set"
      description: "populate prediction override trajectory set"
      operationId: "populate_trajectory_set"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "zrn_gitsha"
        in: "formData"
        description: "zrn identifer"
        required: true
        type: "string"
      - name: "zrn_name"
        in: "formData"
        description: "zrn name"
        required: true
        type: "string"
      - name: "prediction_override_proto"
        in: "formData"
        description: "prediction_override_proto"
        required: true
        type: "string"
      - name: "obstacle_type"
        in: "formData"
        description: "obstacle classification type"
        required: true
        type: "string"
      responses:
        "200":
          description: "success message"
          schema:
            type: "string"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /zrn-unique-gitsha:
    post:
      summary: "a unique (de-duplicated) gitsha from a ZRN id"
      operationId: "zrn_unique_gitsha"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "canonical_name"
        in: "formData"
        description: "zrn canonical name"
        required: true
        type: "string"
      - name: "gitsha"
        in: "formData"
        description: "zrn gitsha"
        required: true
        type: "string"
      responses:
        "200":
          description: "unique de-duplicated gitsha"
          schema:
            type: "string"
        "503":
          description: "de-duplicate service failed"
          schema:
            $ref: "#/definitions/ErrorInfo"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
  /visualize_trajectory:
    post:
      summary: "visualize trajectory from PO proto"
      description: "visualize trajectory"
      operationId: "visualize_trajectory"
      consumes:
      - "application/x-www-form-urlencoded"
      produces:
      - "application/json"
      parameters:
      - name: "zrn_gitsha"
        in: "formData"
        description: "zrn identifer"
        required: true
        type: "string"
      - name: "zrn_name"
        in: "formData"
        description: "zrn name"
        required: true
        type: "string"
      - name: "route_frame_trajectory_proto"
        in: "formData"
        description: "route frame trajectory proto"
        required: true
        type: "string"
      - name: "entity_position_proto"
        in: "formData"
        description: "entity position"
        required: true
        type: "string"
      responses:
        "200":
          description: "success message"
          schema:
            type: "string"
      x-swagger-router-controller: "sim_service.controllers.default_controller"
definitions:
  ScenarioBob:
    type: "string"
    description: "bas64 encoded scenario BOB format"
  AgentDatabaseBinary:
    type: "string"
    description: "base64 encoded binary agent database proto format"
  ScenarioId:
    type: "string"
    format: "uuid"
    description: "id for pending scenario job"
  chumURI:
    type: "string"
    description: "chum uri"
  GitHash:
    type: "string"
    description: "driving repo git hash"
  GitBranch:
    type: "string"
    description: "driving repo git branch"
  CanonicalZrnId:
    type: "object"
    properties:
      gitsha:
        type: "string"
      canonicalName:
        type: "string"
  JunctionInfoList:
    type: "array"
    items:
      $ref: "#/definitions/JunctionInfo"
  JunctionInfo:
    type: "object"
    properties:
      junctionId:
        type: "string"
      groups:
        type: "array"
        items:
          $ref: "#/definitions/GroupInfo"
  GroupInfo:
    type: "object"
    properties:
      groupId:
        type: "string"
      toRoad:
        type: "string"
      fromRoad:
        type: "string"
      fullLaneIds:
        type: "array"
        items:
          description: "in the format <roadId>/<laneId>"
          type: "string"
      signalStateMap:
        type: "object"
  WorkerResult:
    type: "object"
    description: "object containing status infomation about a simulation"
    properties:
      type:
          $ref: "#/definitions/WorkerResultType"
      chumURI:
        $ref: "#/definitions/chumURI"
      status:
        $ref: "#/definitions/StatusEnum"
      log:
        $ref: "#/definitions/SimLog"
      scenario:
        $ref: "#/definitions/ScenarioBob"
    required:
      - status
  WorkerResultType:
    type: "string"
    description: "defines which type of worker result is being returned"
  StatusEnum:
      description: "all the different status codes"
      type: "string"
      enum:
        - "WAITING"
        - "COMPLETE"
  SimLog:
    type: "string"
    description: "stdout & stderr from simulation"
  ErrorInfo:
    type: "object"
    description: "Object containing error information."
    properties:
      statusCode:
        type: "integer"
        description: "Error status code."
      message:
        type: "string"
        description: "Error message."
    required:
      - "statusCode"
      - "message"
    additionalProperties: false
