Package org.mockserver.openapi
Class OpenApiParameterExamples
java.lang.Object
org.mockserver.openapi.OpenApiParameterExamples
Shared, side-effect-free helper for deriving concrete example parameter values from an OpenAPI
Operation and applying them to an example HttpRequest.
The value-resolution order mirrors the OpenAPI specification's example precedence:
- the parameter's explicit
example; - the first entry in the parameter's
examplesmap; - the schema's
default; - the first
enumvalue; - a value generated from the schema via
ExampleBuilder.fromSchema(io.swagger.v3.oas.models.media.Schema<?>, java.util.Map<java.lang.String, io.swagger.v3.oas.models.media.Schema>); - for required parameters only, the literal
"example"so the request is well-formed.
OpenApiContractTest, OpenApiResiliencyTest (indirectly via the contract
test), and OpenAPIConverter so the logic lives in exactly one place.-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequestapplyExampleParameters(HttpRequest request, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions) Applies examplequery,header, andcookieparameter values declared on the operation to the given request.static StringgetParameterExampleValue(io.swagger.v3.oas.models.parameters.Parameter param, io.swagger.v3.oas.models.OpenAPI openAPI) Resolves an example string value for a single parameter, ornullwhen no value can be derived and the parameter is not required.static StringgetParameterExampleValue(io.swagger.v3.oas.models.parameters.Parameter param, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions) static StringresolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI) Substitutes example values for anypathparameters declared on the operation into the path template.static StringresolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions)
-
Method Details
-
getParameterExampleValue
public static String getParameterExampleValue(io.swagger.v3.oas.models.parameters.Parameter param, io.swagger.v3.oas.models.OpenAPI openAPI) Resolves an example string value for a single parameter, ornullwhen no value can be derived and the parameter is not required. -
getParameterExampleValue
public static String getParameterExampleValue(io.swagger.v3.oas.models.parameters.Parameter param, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions) -
resolvePath
public static String resolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI) Substitutes example values for anypathparameters declared on the operation into the path template. Any path placeholder left unresolved (declared implicitly or with no derivable value) is replaced with the literal"example"so the resulting path is well-formed. -
resolvePath
public static String resolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions) -
applyExampleParameters
public static HttpRequest applyExampleParameters(HttpRequest request, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions) Applies examplequery,header, andcookieparameter values declared on the operation to the given request. Path parameters are resolved separately viaresolvePath(java.lang.String, io.swagger.v3.oas.models.Operation, io.swagger.v3.oas.models.OpenAPI). Mutates and returnsrequestfor fluent chaining.
-