Class OpenAPIExpectation

    • Constructor Detail

      • OpenAPIExpectation

        public OpenAPIExpectation()
    • Method Detail

      • openAPIExpectation

        public static OpenAPIExpectation openAPIExpectation​(String specUrlOrPayload,
                                                            Map<String,​Object> operationsAndResponses)
        Specify the OpenAPI and operations and responses to create matchers and example responses for:

         // Create from a publicly hosted HTTP location (json or yaml)
         openAPIExpectation("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from a file on the local filesystem (json or yaml)
         openAPIExpectation("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/openapi/openapi_petstore_example.json", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from a classpath resource in the /api package (json or yaml)
         openAPIExpectation("org/mockserver/openapi/openapi_petstore_example.json", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from an OpenAPI payload (json or yaml)
         openAPIExpectation("{\"openapi\": \"3.0.0\", \"info\": { ...", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
         
        Parameters:
        specUrlOrPayload - the OpenAPI to match against by URL or payload
        operationsAndResponses - operations and responses to use for each example response where the key is the operationId in the OpenAPI and the value is either a status code string (e.g. "200") or an object with "statusCode" and optional "exampleName"
        Returns:
        the OpenAPIExpectation
      • openAPIExpectation

        public static OpenAPIExpectation openAPIExpectation​(String specUrlOrPayload)
        Specify the OpenAPI to create matchers and example responses for:

         // Create from a publicly hosted HTTP location (json or yaml)
         openAPIExpectation("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from a file on the local filesystem (json or yaml)
         openAPIExpectation("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/openapi/openapi_petstore_example.json", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from a classpath resource in the /api package (json or yaml)
         openAPIExpectation("org/mockserver/openapi/openapi_petstore_example.json", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
        
         // Create from an OpenAPI payload (json or yaml)
         openAPIExpectation("{\"openapi\": \"3.0.0\", \"info\": { ...", ImmutableMap.of(
             "listPets", "500",
             "createPets", "default",
             "showPetById", "200"
         ));
         
        Parameters:
        specUrlOrPayload - the OpenAPI to match against by URL or payload
        Returns:
        the OpenAPIExpectation
      • getSpecUrlOrPayload

        public String getSpecUrlOrPayload()
      • withSpecUrlOrPayload

        public OpenAPIExpectation withSpecUrlOrPayload​(String specUrlOrPayload)
        Specify the OpenAPI specification:

         // Create from a publicly hosted HTTP location (json or yaml)
         withSpecUrlOrPayload("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml");
        
         // Create from a file on the local filesystem (json or yaml)
         withSpecUrlOrPayload("file://Users/myuser/git/mockserver/mockserver-core/src/test/resources/org/mockserver/openapi/openapi_petstore_example.json");
        
         // Create from a classpath resource in the /api package (json or yaml)
         withSpecUrlOrPayload("org/mockserver/openapi/openapi_petstore_example.json");
        
         // Create from an OpenAPI payload (json or yaml)
         withSpecUrlOrPayload("{\"openapi\": \"3.0.0\", \"info\": { ...");
         
        Parameters:
        specUrlOrPayload - the OpenAPI to match against by URL or payload
        Returns:
        this OpenAPIExpectation
      • getOperationsAndResponses

        public Map<String,​Object> getOperationsAndResponses()
      • withOperationsAndResponses

        public OpenAPIExpectation withOperationsAndResponses​(Map<String,​Object> operationsAndResponses)
        The operations and responses to use for each example response where the key is the operationId in the OpenAPI and the value is either:
        • a String response status code (e.g. "200", "400", "default")
        • a Map/object with "statusCode" (required) and optional "exampleName" to select a specific named example
        Parameters:
        operationsAndResponses - operations and responses to use for each example response
        Returns:
        this OpenAPIExpectation
      • getContextPathPrefix

        public String getContextPathPrefix()