Package org.mockserver.mock
Class OpenAPIExpectation
- java.lang.Object
-
- org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
-
- org.mockserver.model.ObjectWithJsonToString
-
- org.mockserver.mock.OpenAPIExpectation
-
public class OpenAPIExpectation extends ObjectWithJsonToString
- Author:
- jamesdbloom
-
-
Constructor Summary
Constructors Constructor Description OpenAPIExpectation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)StringgetContextPathPrefix()Map<String,Object>getOperationsAndResponses()StringgetSpecUrlOrPayload()inthashCode()static OpenAPIExpectationopenAPIExpectation()static 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)OpenAPIExpectationwithContextPathPrefix(String contextPathPrefix)OpenAPIExpectationwithOperationsAndResponses(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 exampleOpenAPIExpectationwithOperationsAndStringResponses(Map<String,String> operationsAndResponses)OpenAPIExpectationwithSpecUrlOrPayload(String specUrlOrPayload)Specify the OpenAPI specification:-
Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toString
-
Methods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
-
-
-
Method Detail
-
openAPIExpectation
public static OpenAPIExpectation 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
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
-
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
-
withOperationsAndStringResponses
public OpenAPIExpectation withOperationsAndStringResponses(Map<String,String> operationsAndResponses)
-
getContextPathPrefix
public String getContextPathPrefix()
-
withContextPathPrefix
public OpenAPIExpectation withContextPathPrefix(String contextPathPrefix)
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classObjectWithReflectiveEqualsHashCodeToString
-
hashCode
public int hashCode()
- Overrides:
hashCodein classObjectWithReflectiveEqualsHashCodeToString
-
-