swagger: '2.0'

info:
  version: "0.1.0"
  title: Project Service
  description: |
    Service for project alignment data management.

host: haleconnect.com
schemes:
  - https
basePath: /projects

produces:
  - application/json

security:
  - bearer: []

securityDefinitions:
  bearer:
    type: apiKey
    name: Authorization
    in: header

paths:
  /health:
    get:
      tags:
        - Smoke Tests
      summary: Checks if the service is alive and in a good state
      responses:
        200:
          $ref: '#/responses/HealthCheckResult'
        default:
          $ref: '#/responses/Error'

  /mapping/{ownerType}/{ownerId}/{resourceId}/{cellId}:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'
        - $ref: '#/parameters/cellId'

      get:
        summary: Get a mapping cell
        tags:
          - Cells
        responses:
          200:
            description: Mapping cell information
            schema:
              $ref: '#/definitions/Cell'
          default:
            $ref: '#/responses/Error'

      delete:
        summary: Delete a mapping cell
        tags:
          - Cells
        responses:
          200:
            description: Cell note deleted
            schema:
              $ref: '#/definitions/SuccessWithMessage'
          default:
            $ref: '#/responses/Error'

  /mapping/note/{ownerType}/{ownerId}/{resourceId}/{cellId}:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'
        - $ref: '#/parameters/cellId'

      post:
        summary: Create a new bucket in the current context
        tags:
          - Cells
        consumes:
          - application/json
        parameters:
          - $ref: '#/parameters/bodyParam'

        responses:
          200:
            description: Cell note updated
            schema:
              $ref: '#/definitions/SuccessWithMessage'
          default:
            description: Error updating cell
            schema:
              $ref: '#/definitions/Feedback'

      delete:
        summary: Delete a documentation note from a project alignment
        tags:
          - Cells
        responses:
          200:
            description: Cell note updated
            schema:
              $ref: '#/definitions/SuccessWithMessage'
          default:
            $ref: '#/responses/Error'

  /project/{ownerType}/{ownerId}:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'

      delete:
        summary: Delete all project data from an specific organisation
        tags:
          - Project

        responses:
          200:
            description: Project data was deleted successfully
            schema:
              $ref: '#/definitions/IdentifierArray'
          default:
            description: Error deleting project data
            schema:
              $ref: '#/definitions/Feedback'

  /project/{ownerType}/{ownerId}/{resourceId}/basic:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'

      get:
        summary: Get basic information about a project
        tags:
          - Project

        responses:
          200:
            description: Basic project information
            schema:
              $ref: '#/definitions/BasicProjectInfo'
          default:
            description: Error retrieving project information
            schema:
              $ref: '#/definitions/Feedback'

  /project/{ownerType}/{ownerId}/{resourceId}/config:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'

      get:
        summary: Get configuration options for a project
        tags:
          - Project

        responses:
          200:
            description: Project configuration options
            schema:
              $ref: '#/definitions/ConfigInfo'
          default:
            description: Error retrieving project configuration options
            schema:
              $ref: '#/definitions/Feedback'


  /project/{ownerType}/{ownerId}/{resourceId}/property/{propertyName}:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'
        - $ref: '#/parameters/propertyName'

      put:
        summary: Updates the value of a property of the project
        tags:
          - Project
        consumes:
          - application/json
        parameters:
          - $ref: '#/parameters/propertyValue'

        responses:
          200:
            description: Project property updated
            schema:
              $ref: '#/definitions/SuccessWithMessage'
          default:
            description: Error updating property
            schema:
              $ref: '#/definitions/Feedback'

  /alignment/{ownerType}/{ownerId}/{resourceId}:
      parameters:
        - $ref: '#/parameters/ownerType'
        - $ref: '#/parameters/ownerId'
        - $ref: '#/parameters/resourceId'
      get:
        summary: Get detailed alignment information on a project
        tags:
          - Alignment
        responses:
          200:
            $ref: '#/responses/AlignmentInfo'
          default:
            $ref: '#/responses/Error'
      put:
        summary: Replace the project's alignment
        tags:
          - Alignment
        consumes:
          - application/xml
        parameters:
          - name: body
            in: body
            required: true
            description: The alignment as XML
            type: string
        responses:
          200:
            description: Alignment was successfully updated
            schema:
              $ref: '#/definitions/Feedback'
          default:
            $ref: '#/responses/Error'


  /projects:
      post:
        summary: Create/generate a new project
        tags:
          - Project
        consumes:
          - application/json
        parameters:
          - $ref: '#/parameters/context'
          - $ref: '#/parameters/CreateProjectBody'
        responses:
          200:
            description: Identifier of created project
            schema:
              $ref: '#/definitions/BucketID'
          default:
            description: Creation of the project failed
            schema:
              $ref: '#/definitions/Feedback'

responses:

  AlignmentInfo:
    description: Object with the alignment info related to a transformation project
    schema:
      $ref: '#/definitions/AlignmentInfo'


  HealthCheckResult:
    description: Object describing if the service is in good condition
    schema:
      $ref: '#/definitions/HealthCheckResult'

  Error:
    description: Internal error processing request
    schema:
      $ref: '#/definitions/Feedback'

parameters:

  ownerType:
    name: ownerType
    in: path
    description: The type of owner the project belongs to
    required: true
    type: string
    enum:
      - user
      - org

  ownerId:
    name: ownerId
    in: path
    description: The ID of the owner
    required: true
    type: string

  resourceId:
    name: resourceId
    in: path
    description: The ID of the transformation project
    required: true
    type: string

  cellId:
    name: cellId
    in: path
    description: The ID of the cell within a project alignment
    required: true
    type: string

  propertyName:
    name: propertyName
    in: path
    description: The name of a project property
    required: true
    type: string

  bodyParam:
    name: body
    in: body
    required: true
    description: The note content
    schema:
      type: string

  propertyValue:
    name: body
    in: body
    required: true
    description: The new value of the property
    schema:
      type: string

  context:
    name: WETF-Context-Organisation
    in: header
    description: The organisation context
    required: false
    type: string

  CreateProjectBody:
    name: body
    in: body
    required: true
    description: The configuration for creating a new project
    schema:
      $ref: '#/definitions/CreateProject'

definitions:

  Feedback:
    type: object
    required:
      - code
      - message
      - error
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      error:
        type: boolean

  SuccessWithMessage:
    type: object
    required:
      - message
    properties:
      message:
        type: string

  AlignmentInfo:
    type: object
    required:
      - projectIdentifier
      - projectAlignment
    properties:
      projectIdentifier:
        type: string
        description: The identifier of the transformation project
      projectAlignment:
        type: object
        description: The alignment data about this transformation project

  BasicProjectInfo:
    type: object
    properties:
      projectIdentifier:
        type: string
        description: The identifier of the transformation project
      projectAlignment:
        type: object
        description: The alignment data about this transformation project
      lastUpdated:
        type: number

  IdentifierArray:
    type: array
    items:
      type: string
      description: ID of a deleted project
    description: Array with the identifier of the deleted projects

  ConfigInfo:
    type: object
    properties:
      variables:
        type: object
        description: Supported project variables

  HealthCheckResult:
    type: object
    required:
      - result
    properties:
      result:
        type: string

  BucketID:
    type: object
    properties:
      transformationproject:
        type: string
        description: The identifier of the transformation project (in context of its owner)
      userId:
        type: string
        description: The owner of the project if it is a user
      orgId:
        type: string
        description: The owner of the project if it is an organisation

  CreateProject:
    type: object
    properties:
      author:
        type: string
        description: The author of the project
      description:
        type: string
        description: The description of the project
      name:
        type: string
        description: The name of the project
      source:
        type: object
        schema:
          $ref: '#/definitions/ModelReference'
      target:
        type: object
        schema:
          $ref: '#/definitions/ModelReference'

  ModelReference:
    type: object
    properties:
      schema:
        type: string
        description: The identifier of the schema

  Cell:
    type: object
    properties:
      functionName:
        type: string
        description: The mapping function name
      functionId:
       type: string
       description: The mapping function identifier
      typeRelation:
        type: boolean
        description: True if this cell describes a type mapping
      functionParameters:
        type: object
        description: Mapping function parameters
      sources:
        type: array
        items:
          type: object
        description: Mapping sources
      targets:
        type: array
        items:
          type: object
        description: Mapping targets
      explanations:
        type: object
        description: Mapping cell explanation in different languages
      cellId:
        type: string
        description: The cell identifier
      parentCells:
        type: array
        items:
          type: string
        description: The parent cell(s) of this mapping cells
      priority:
        type: string
        description: The execution priority of the cell
      configurable:
        type: boolean
        description: True if the mapping cell is configurable
