Package org.mockserver.mock
Class OpenAPIExpectation
java.lang.Object
org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
org.mockserver.model.ObjectWithJsonToString
org.mockserver.mock.OpenAPIExpectation
- Author:
- jamesdbloom
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()static OpenAPIExpectationstatic OpenAPIExpectationopenAPIExpectation(String specUrlOrPayload) Specify the OpenAPI to create matchers and example responses for:static OpenAPIExpectationopenAPIExpectation(String specUrlOrPayload, Map<String, Object> operationsAndResponses) Specify the OpenAPI and operations and responses to create matchers and example responses for:static OpenAPIExpectationopenAPIExpectationWithStringResponses(String specUrlOrPayload, Map<String, String> operationsAndResponses) withContextPathPrefix(String contextPathPrefix) 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 examplewithOperationsAndStringResponses(Map<String, String> operationsAndResponses) withSpecUrlOrPayload(String specUrlOrPayload) Specify the OpenAPI specification:Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
OpenAPIExpectation
public OpenAPIExpectation()
-
-
Method Details
-
openAPIExpectation
-
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 payloadoperationsAndResponses- 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
-
openAPIExpectationWithStringResponses
public static OpenAPIExpectation openAPIExpectationWithStringResponses(String specUrlOrPayload, Map<String, String> operationsAndResponses) -
openAPIExpectation
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
-
withSpecUrlOrPayload
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
-
withOperationsAndResponses
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
-
withOperationsAndStringResponses
public OpenAPIExpectation withOperationsAndStringResponses(Map<String, String> operationsAndResponses) -
getContextPathPrefix
-
withContextPathPrefix
-
equals
- Overrides:
equalsin classObjectWithReflectiveEqualsHashCodeToString
-
hashCode
public int hashCode()- Overrides:
hashCodein classObjectWithReflectiveEqualsHashCodeToString
-