MockServer expectation API

Create or update expectations - updates if the id matches an existing expectations (only supported by MockServer)

OpenAPI Specification

mockserver-expectation-api-openapi.yml Raw ↑
openapi: 3.0.0
info:
  title: MockServer control expectation API
  version: 5.15.x
  description: 'MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below).


    MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).


    Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.'
  license:
    url: https://github.com/mock-server/mockserver/blob/master/LICENSE.md
    name: Apache 2.0
servers:
- url: http://localhost:1080/
- url: https://localhost:1080/
tags:
- name: expectation
  description: Create or update expectations - updates if the id matches an existing expectations (only supported by MockServer)
paths:
  /mockserver/expectation:
    put:
      tags:
      - expectation
      summary: create expectation
      responses:
        '201':
          description: expectations created
          content:
            application/json:
              schema:
                description: list of upserted expectations
                type: array
                additionalProperties: false
                items:
                  $ref: '#/components/schemas/Expectation'
        '400':
          description: incorrect request format
        '406':
          description: invalid expectation
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Expectations'
        description: expectation(s) to create
        required: true
  /mockserver/openapi:
    put:
      tags:
      - expectation
      summary: create expectations from OpenAPI or Swagger
      responses:
        '201':
          description: expectations created
          content:
            application/json:
              schema:
                description: list of upserted expectations
                type: array
                additionalProperties: false
                items:
                  $ref: '#/components/schemas/Expectation'
        '400':
          description: incorrect request format
        '406':
          description: invalid expectation
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAPIExpectations'
        description: expectation(s) to create
        required: true
components:
  schemas:
    HttpError:
      description: error behaviour
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        dropConnection:
          type: boolean
        responseBytes:
          type: string
    OpenAPIExpectations:
      description: list of open api expectations
      oneOf:
      - $ref: '#/components/schemas/OpenAPIExpectation'
      - type: array
        additionalProperties: false
        items:
          $ref: '#/components/schemas/OpenAPIExpectation'
    StringOrJsonSchema:
      description: string value that can be support nottable, optional or a json schema
      oneOf:
      - type: string
      - type: object
        additionalProperties: false
        properties:
          not:
            type: boolean
          optional:
            type: boolean
          value:
            type: string
          schema:
            $ref: http://json-schema.org/draft-04/schema
          parameterStyle:
            type: string
            enum:
            - SIMPLE
            - SIMPLE_EXPLODED
            - LABEL
            - LABEL_EXPLODED
            - MATRIX
            - MATRIX_EXPLODED
            - FORM_EXPLODED
            - FORM
            - SPACE_DELIMITED_EXPLODED
            - SPACE_DELIMITED
            - PIPE_DELIMITED_EXPLODED
            - PIPE_DELIMITED
            - DEEP_OBJECT
    Delay:
      description: response delay
      type: object
      additionalProperties: false
      properties:
        timeUnit:
          type: string
        value:
          type: integer
    HttpTemplate:
      description: template to generate response / request
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        templateType:
          enum:
          - VELOCITY
          - JAVASCRIPT
          - MUSTACHE
        template:
          type: string
    HttpOverrideForwardedRequest:
      description: override forwarded request
      oneOf:
      - type: object
        additionalProperties: false
        properties:
          delay:
            $ref: '#/components/schemas/Delay'
          requestOverride:
            $ref: '#/components/schemas/HttpRequest'
          requestModifier:
            type: object
            additionalProperties: false
            properties:
              path:
                type: object
                additionalProperties: false
                properties:
                  regex:
                    type: string
                  substitution:
                    type: string
              queryStringParameters:
                type: object
                additionalProperties: false
                properties:
                  add:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  replace:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  remove:
                    type: array
                    additionalProperties: false
                    items:
                      type: string
              headers:
                type: object
                additionalProperties: false
                properties:
                  add:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  replace:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  remove:
                    type: array
                    additionalProperties: false
                    items:
                      type: string
              cookies:
                type: object
                additionalProperties: false
                properties:
                  add:
                    $ref: '#/components/schemas/KeyToValue'
                  replace:
                    $ref: '#/components/schemas/KeyToValue'
                  remove:
                    type: array
                    additionalProperties: false
                    items:
                      type: string
          responseOverride:
            $ref: '#/components/schemas/HttpResponse'
          responseModifier:
            type: object
            additionalProperties: false
            properties:
              headers:
                type: object
                additionalProperties: false
                properties:
                  add:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  replace:
                    $ref: '#/components/schemas/KeyToMultiValue'
                  remove:
                    type: array
                    additionalProperties: false
                    items:
                      type: string
              cookies:
                type: object
                additionalProperties: false
                properties:
                  add:
                    $ref: '#/components/schemas/KeyToValue'
                  replace:
                    $ref: '#/components/schemas/KeyToValue'
                  remove:
                    type: array
                    additionalProperties: false
                    items:
                      type: string
      - type: object
        additionalProperties: false
        properties:
          delay:
            $ref: '#/components/schemas/Delay'
          httpRequest:
            $ref: '#/components/schemas/HttpRequest'
          httpResponse:
            $ref: '#/components/schemas/HttpResponse'
    HttpForward:
      description: host and port to forward to
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        host:
          type: string
        port:
          type: integer
        scheme:
          enum:
          - HTTP
          - HTTPS
    OpenAPIDefinition:
      description: open api or swagger request matcher
      type: object
      additionalProperties: false
      properties:
        specUrlOrPayload:
          type: string
        operationId:
          type: string
    KeyToValue:
      oneOf:
      - type: array
        additionalProperties: false
        items:
          type: object
          properties:
            name:
              type: string
            value:
              type: string
      - type: object
        additionalProperties: true
    BodyWithContentType:
      description: response body
      anyOf:
      - type: object
        description: binary response body
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - BINARY
          base64Bytes:
            type: string
          contentType:
            type: string
      - type: object
        description: json response body
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - JSON
          json:
            type: string
          contentType:
            type: string
      - type: object
        description: json response body
        additionalProperties: true
      - type: object
        description: string response body
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - STRING
          string:
            type: string
          contentType:
            type: string
      - type: string
        description: string response body
      - type: object
        description: xml response body
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - XML
          xml:
            type: string
          contentType:
            type: string
    Body:
      description: request body matcher
      anyOf:
      - type: object
        description: binary body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - BINARY
          base64Bytes:
            type: string
          contentType:
            type: string
      - type: object
        description: json body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - JSON
          json:
            type: string
          contentType:
            type: string
          matchType:
            enum:
            - STRICT
            - ONLY_MATCHING_FIELDS
      - type: object
        description: json matching fields body matcher
        additionalProperties: true
      - type: object
        description: json schema body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - JSON_SCHEMA
          jsonSchema:
            $ref: http://json-schema.org/draft-04/schema
      - type: object
        description: JSON path body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - JSON_PATH
          jsonPath:
            type: string
      - type: object
        description: parameter body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - PARAMETERS
          parameters:
            $ref: '#/components/schemas/KeyToMultiValue'
      - type: object
        description: regex body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - REGEX
          regex:
            type: string
      - type: object
        description: string body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - STRING
          string:
            type: string
          contentType:
            type: string
          subString:
            type: boolean
      - type: string
        description: substring body matcher
      - type: object
        description: xml body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - XML
          xml:
            type: string
          contentType:
            type: string
      - type: object
        description: xml schema body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - XML_SCHEMA
          xmlSchema:
            type: string
      - type: object
        description: xpath body matcher
        additionalProperties: false
        properties:
          not:
            type: boolean
          type:
            enum:
            - XPATH
          xpath:
            type: string
    TimeToLive:
      description: time expectation is valid for
      type: object
      additionalProperties: false
      properties:
        timeUnit:
          enum:
          - DAYS
          - HOURS
          - MINUTES
          - SECONDS
          - MILLISECONDS
          - MICROSECONDS
          - NANOSECONDS
        timeToLive:
          type: integer
        unlimited:
          type: boolean
    Times:
      description: number of responses
      type: object
      additionalProperties: false
      properties:
        remainingTimes:
          type: integer
        unlimited:
          type: boolean
    ConnectionOptions:
      description: connection options
      type: object
      additionalProperties: false
      properties:
        suppressContentLengthHeader:
          type: boolean
        contentLengthHeaderOverride:
          type: integer
        suppressConnectionHeader:
          type: boolean
        chunkSize:
          type: integer
        keepAliveOverride:
          type: boolean
        closeSocket:
          type: boolean
        closeSocketDelay:
          $ref: '#/components/schemas/Delay'
    HttpObjectCallback:
      description: object / method callback
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        clientId:
          type: string
        responseCallback:
          type: boolean
    Expectations:
      description: list of expectations
      oneOf:
      - $ref: '#/components/schemas/Expectation'
      - type: array
        additionalProperties: false
        items:
          $ref: '#/components/schemas/Expectation'
    SocketAddress:
      description: remote address to send request to, only used for request overrides
      type: object
      additionalProperties: false
      properties:
        host:
          type: string
        port:
          type: integer
        scheme:
          enum:
          - HTTP
          - HTTPS
    KeyToMultiValue:
      oneOf:
      - type: array
        additionalProperties: false
        items:
          type: object
          additionalProperties: false
          properties:
            name:
              type: string
            values:
              type: array
              additionalProperties: false
              items:
                type: string
      - type: object
        additionalProperties: true
        properties:
          keyMatchStyle:
            type: string
            enum:
            - MATCHING_KEY
            - SUB_SET
            default: SUB_SET
    HttpResponse:
      description: response to return
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        body:
          $ref: '#/components/schemas/BodyWithContentType'
        cookies:
          $ref: '#/components/schemas/KeyToValue'
        connectionOptions:
          $ref: '#/components/schemas/ConnectionOptions'
        headers:
          $ref: '#/components/schemas/KeyToMultiValue'
        statusCode:
          type: integer
        reasonPhrase:
          type: string
    HttpClassCallback:
      description: class callback
      type: object
      additionalProperties: false
      properties:
        delay:
          $ref: '#/components/schemas/Delay'
        callbackClass:
          type: string
    OpenAPIExpectation:
      description: open api or swagger expectation
      type: object
      additionalProperties: false
      properties:
        specUrlOrPayload:
          anyOf:
          - type: string
          - type: object
        operationsAndResponses:
          type: object
          additionalProperties:
            type: string
      required:
      - specUrlOrPayload
    RequestDefinition:
      description: request definition
      oneOf:
      - $ref: '#/components/schemas/HttpRequest'
      - $ref: '#/components/schemas/OpenAPIDefinition'
    HttpRequest:
      description: request properties matcher
      type: object
      additionalProperties: false
      properties:
        secure:
          type: boolean
        keepAlive:
          type: boolean
        method:
          $ref: '#/components/schemas/StringOrJsonSchema'
        path:
          $ref: '#/components/schemas/StringOrJsonSchema'
        pathParameters:
          $ref: '#/components/schemas/KeyToMultiValue'
        queryStringParameters:
          $ref: '#/components/schemas/KeyToMultiValue'
        body:
          $ref: '#/components/schemas/Body'
        headers:
          $ref: '#/components/schemas/KeyToMultiValue'
        cookies:
          $ref: '#/components/schemas/KeyToValue'
        socketAddress:
          $ref: '#/components/schemas/SocketAddress'
        protocol:
          $ref: '#/components/schemas/Protocol'
    Protocol:
      description: protocol matcher
      enum:
      - HTTP_1_1
      - HTTP_2
    Expectation:
      description: expectation
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        priority:
          type: integer
        httpRequest:
          $ref: '#/components/schemas/RequestDefinition'
        httpResponse:
          $ref: '#/components/schemas/HttpResponse'
        httpResponseTemplate:
          $ref: '#/components/schemas/HttpTemplate'
        httpResponseClassCallback:
          $ref: '#/components/schemas/HttpClassCallback'
        httpResponseObjectCallback:
          $ref: '#/components/schemas/HttpObjectCallback'
        httpForward:
          $ref: '#/components/schemas/HttpForward'
        httpForwardTemplate:
          $ref: '#/components/schemas/HttpTemplate'
        httpForwardClassCallback:
          $ref: '#/components/schemas/HttpClassCallback'
        httpForwardObjectCallback:
          $ref: '#/components/schemas/HttpObjectCallback'
        httpOverrideForwardedRequest:
          $ref: '#/components/schemas/HttpOverrideForwardedRequest'
        httpError:
          $ref: '#/components/schemas/HttpError'
        times:
          $ref: '#/components/schemas/Times'
        timeToLive:
          $ref: '#/components/schemas/TimeToLive'
      oneOf:
      - required:
        - httpResponse
      - required:
        - httpResponseTemplate
      - required:
        - httpResponseClassCallback
      - required:
        - httpResponseObjectCallback
      - required:
        - httpForward
      - required:
        - httpForwardTemplate
      - required:
        - httpForwardClassCallback
      - required:
        - httpForwardObjectCallback
      - required:
        - httpOverrideForwardedRequest
      - required:
        - httpError