swagger: "2.0"
info:
  description: "Capability service for the SSA Workspaces project"
  version: "1.0.0"
  title: "Capability Service"
  contact:
    email: "dms-ssa@nrao.edu"
host: "shipman.aoc.nrao.edu"
tags:
  - name: "capabilities"
    description: "Access capabilities and create requests"
  - name: "requests"
    description: "Access and submit capability requests"
  - name: "workflows"
    description: "Access and submit workflow requests"
schemes:
  - "http"
paths:
  /capability/{name}:
    get:
      tags:
        - "capabilities"
      summary: "View the named capability"
      description: ""
      operationId: "view_capability"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability to view"
          required: true
          type: "string"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Capability"
    post:
      tags:
        - "capabilities"
      summary: "Update an existing capability"
      description: ""
      operationId: "edit_capability"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability to update"
          required: true
          type: "string"
        - in: "body"
          name: "body"
          description: "Capability object that needs to be added to the system"
          required: true
          schema:
            $ref: "#/definitions/Capability"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Capability"
  /capability/{name}/enable:
    post:
      tags:
        - "capabilities"
      summary: "Enable a capability"
      operationId: "enable_capability"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability to enable"
          required: true
          type: "string"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
  /capability/{name}/disable:
    post:
      tags:
        - "capabilities"
      summary: "Disable a capability"
      operationId: "disable_capability"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability to disable"
          required: true
          type: "string"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
  /capability/{name}/requests/{id}:
    get:
      tags:
        - "requests"
      summary: "View the identified capability request"
      description: ""
      operationId: "view_capability_request"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability this request belongs to"
          required: true
          type: "string"
        - name: "id"
          in: "path"
          description: "ID of capability request"
          required: true
          type: "integer"
          format: "int64"
      responses:
        "400":
          description: "Invalid capability name or request ID supplied"
        "404":
          description: "Capability request not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/CapabilityRequest"
    post:
      tags:
        - "requests"
      summary: "Update an existing capability request"
      description: ""
      operationId: "edit_capability_request"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability this request belongs to"
          required: true
          type: "string"
        - name: "id"
          in: "path"
          description: "ID of capability request"
          required: true
          type: "integer"
          format: "int64"
        - in: "body"
          name: "body"
          description: "Capability object that needs to be added to the system"
          required: true
          schema:
            $ref: "#/definitions/Capability"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
    delete:
      tags:
        - "requests"
      summary: "Delete a capability request"
      description: ""
      operationId: "delete_capability_request"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability this request belongs to"
          required: true
          type: "string"
        - name: "id"
          in: "path"
          description: "ID of capability request"
          required: true
          type: "integer"
          format: "int64"
      responses:
        "400":
          description: "Invalid name supplied"
        "403":
          description: "Permission denied; capability request already executed"
        "404":
          description: "Capability not found"
  /capability/{name}/requests/{id}/submit:
    post:
      tags:
        - "requests"
      summary: "Submit a capability request for execution"
      description: ""
      operationId: "submit_capability_request"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "name"
          in: "path"
          description: "name of capability this request belongs to"
          required: true
          type: "string"
        - name: "id"
          in: "path"
          description: "ID of capability request"
          required: true
          type: "integer"
          format: "int64"
      responses:
        "400":
          description: "Invalid name supplied"
        "404":
          description: "Capability not found"
  /workflows:
    get:
      tags:
        - "workflows"
      summary: "View the list of workflows"
      description: ""
      operationId: "Workflows.list_workflows"
      produces:
        - "application/json"
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/WorkflowList"
  /workflows/{name}:
    get:
      tags:
        - "workflows"
      summary: "View the named workflow"
      description: ""
      operationId: "Workflows.get_workflow"
      parameters:
        - name: "name"
          in: "path"
          description: "name of workflow to view"
          required: true
          type: "string"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "404":
          description:
            "Workflow not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/Workflow"
  /workflows/{name}/create:
    post:
      tags:
        - "workflows"
      summary: "Create a workflow request"
      description: ""
      operationId: "WorkflowRequestRestService.create_workflow_request"
      parameters:
        - name: "name"
          in: "path"
          description: "name of workflow to create a request for"
          required: true
          type: "string"
        - name: "body"
          in: "body"
          description: "Argument to the workflow"
          schema:
            type: "object"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "404":
          description:
            "Workflow not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/WorkflowRequest"
  /workflows/{name}/requests/{request_id}:
    get:
      tags:
        - "workflows"
      summary: "View the workflow request with this ID"
      description: ""
      operationId: "WorkflowRequestRestService.get_workflow_request"
      parameters:
        - name: "name"
          in: "path"
          description: "name of workflow this request belongs to"
          required: true
          type: "string"
        - name: "request_id"
          in: "path"
          description: "ID of the request"
          type: "integer"
          required: true
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "404":
          description:
            "Workflow request not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/WorkflowRequest"
  /workflows/{name}/requests/{request_id}/submit:
    post:
      tags:
        - "workflows"
      summary: "Submit the workflow request for execution"
      description: ""
      operationId: "WorkflowRequestRestService.submit_workflow"
      parameters:
        - name: "name"
          in: "path"
          description: "name of workflow this request belongs to"
          required: true
          type: "string"
        - name: "request_id"
          in: "path"
          description: "ID of the request"
          type: "integer"
          required: true
      consumes:
        - "application/json"
      produces:
        - "application/json"
      responses:
        "404":
          description:
            "Workflow request not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/WorkflowRequest"

  /workflows/{name}/requests/{request_id}/files/{filename}:
    put:
      tags:
        - "workflows"
      summary: "Add a file to this workflow request"
      description: ""
      operationId: "WorkflowFilesRestService.add_file"
      parameters:
        - name: "name"
          in: "path"
          description: "name of workflow the request belongs to"
          required: true
          type: "string"
        - name: "request_id"
          in: "path"
          description: "ID of the request"
          type: "integer"
          required: true
        - name: "filename"
          in: "path"
          description: "filename to add"
          type: "string"
          required: true
      consumes:
        - "application/octet-stream"
      produces:
        - "application/json"
      responses:
        "400":
          description: "File already exists"
        "404":
          description:
            "Workflow request not found"
        "200":
          description: "successful operation"
          schema:
            $ref: "#/definitions/WorkflowRequestFile"

definitions:
  Capability:
    type: "object"
    properties:
      name:
        type: "string"
      steps:
        type: "string"
      max_jobs:
        type: "integer"
        format: "int64"
  CapabilityRequest:
    type: "object"
    properties:
      body:
        type: "object"
  WorkflowList:
    type: "array"
    items:
      $ref: "#/definitions/Workflow"
  Workflow:
    type: "object"
    properties:
      name:
        type: "string"
  WorkflowRequest:
    type: "object"
    properties:
      workflow_request_id:
        type: "integer"
        format: "int64"
      workflow_name:
        type: "string"
      argument:
        type: "object"
      state:
        type: "string"
      results_dir:
        type: "string"
  WorkflowRequestFile:
    type: "object"
    properties:
      workflow_request_id:
        type: "integer"
        format: "int64"
      filename:
        type: "string"
      content:
        type: "string"
externalDocs:
  description: "More about the capability service"
  url: "http://builder.aoc.nrao.edu/ssa/architecture/workspaces"