openapi: 3.0.3
info:
  title: Simple Test Calculator API
  description: |-
    This is a simple calculator API for testing.
  version: "1.0"
servers:
  - url: https://testpages.eviltester.com
  - url: http://localhost:4567
paths:
  /apps/api/calculator/calculate:
    post:
      summary: Calculate the result of an arithmetic operation
      description: Calculate a result for an operation for either a left and right operand, or a list of operands.
      operationId: calculateOperand
      requestBody:
        description: Calculate a value
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Operation'
            examples:
              add-example:
                summary: Simple addition
                value:
                  operation: "plus"
                  left: "1"
                  right: "2"
              operands-example:
                summary: Use of Operands
                value:
                  operation: "plus"
                  operands: [1, 2, 3, 4]
              text-example:
                summary: Use of Sentences
                value:
                  operation: "plus"
                  left: "one thousand"
                  right: "one hundred and three"
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/LeftRightOperation'
            example:
              function: "plus"
              number1: 1
              number2: 22
        required: true
      responses:
        '200':
          description: Successful Calculation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationResult'          
        '400':
          description: Invalid input
        '415':
          description: Invalid content type
    get:
      summary: get the result of an arithmetic operation
      description: get a result for an operation for either a left and right operand, or a list of operands.
      operationId: calculateOperandGet
      parameters:
        - name: operation
          in: query
          description: Type of arithmetic operation.  Use one of the values in the enum.
          required: true
          schema:
            type: string
            enum: [plus, minus, multiply, divide]
          example: plus

        - name: left
          in: query
          description: The left operand (can be sentence string, but typically a number)
          required: false
          schema:
            type: string
          example: "1"

        - name: right
          in: query
          description: The right operand (can be sentence string, but typically a number)
          required: false
          schema:
            type: string
          example: "2"
        - name: operands
          in: query
          description: The list of operands (can be sentence string, but typically a number)
          required: false
          schema:
            type: string
          example: "[2,3,4]"

      responses:
        '200':
          description: Successful Calculation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationResult'          
        '400':
          description: Invalid input
        '415':
          description: Invalid content type          
    options:
      summary: What verbs are allowed for calculate
      responses:
        '204':
          description: Allowed methods
          headers:
            Allow:
              description: |
                Shows the HTTP methods supported by the resource.
              schema:
                type: string
              example: GET, OPTIONS, POST
  /apps/api/calculator/sequence:
    post:
      summary: Calculate the result of a sequence of arithmetic operations
      description: Calculate a result of a sequence of operations. There should be no left operand because the left operand is the result of the previous operation.
      operationId: sequenceOfOperations
      requestBody:
        description: Calculate a value
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OperationList'
        required: true
      responses:
        '200':
          description: Successful Calculation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OperationResult'          
        '400':
          description: Invalid input
        '415':
          description: Invalid content type
    options:
      summary: What verbs are allowed for sequence
      responses:
        '204':
          description: Allowed methods
          headers:
            Allow:
              description: |
                Shows the HTTP methods supported by the resource.
              schema:
                type: string
              example: OPTIONS, POST
components:
  schemas:
    Operation:
      type: object
      properties:
        operation:
          type: string
          enum: [plus, minus, times, divide]
          example: plus
          description: The arithmetic operation to perform.
        left:
          type: string
          format: int32
          example: 1
          description: The left operand e.g. left + x
        right:
          type: string
          format: int32
          example: 7
          description: The right operand e.g. x + right
        operands:
          type: array
          items:
            type: string
          example: ['1', 3, 4, 'five']
          description: A list of operands to use e.g. x1 + x2 + x3 + x4
    LeftRightOperation:
      type: object
      properties:
        function:
          type: string
          enum: [plus, minus, times, divide]
          example: plus
          description: The arithmetic operation to perform.
        number1:
          type: integer
          format: int32
          example: 1, 'one'
          description: The left operand e.g. left + x
        number2:
          type: integer
          format: int32
          example: 7
          description: The right operand e.g. x + right
    OperationResult:
      type: object
      properties:
        type:
          type: string
          enum: [VALUE, ERROR, INPUT_ERROR]
          example: VALUE
        value:
          type: string
          format: int32
          example: 1
          description: The arithmetic value calculated, or the error message.
    OperationList:
      description: List of Operation objects e.g. {"operations":[{ob1},{obj2}]}
      type: array
      items:
        $ref: '#/components/schemas/Operation'