Class OpenApiParameterExamples

java.lang.Object
org.mockserver.openapi.OpenApiParameterExamples

public final class OpenApiParameterExamples extends Object
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:

  1. the parameter's explicit example;
  2. the first entry in the parameter's examples map;
  3. the schema's default;
  4. the first enum value;
  5. 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>);
  6. for required parameters only, the literal "example" so the request is well-formed.
Used by OpenApiContractTest, OpenApiResiliencyTest (indirectly via the contract test), and OpenAPIConverter so the logic lives in exactly one place.
  • Method Summary

    Modifier and Type
    Method
    Description
    applyExampleParameters(HttpRequest request, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions)
    Applies example query, header, and cookie parameter values declared on the operation to the given request.
    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, or null when no value can be derived and the parameter is not required.
    static String
    getParameterExampleValue(io.swagger.v3.oas.models.parameters.Parameter param, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions)
     
    static String
    resolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI)
    Substitutes example values for any path parameters declared on the operation into the path template.
    static String
    resolvePath(String pathTemplate, io.swagger.v3.oas.models.Operation operation, io.swagger.v3.oas.models.OpenAPI openAPI, GenerationOptions generationOptions)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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, or null when 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 any path parameters 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 example query, header, and cookie parameter values declared on the operation to the given request. Path parameters are resolved separately via resolvePath(java.lang.String, io.swagger.v3.oas.models.Operation, io.swagger.v3.oas.models.OpenAPI). Mutates and returns request for fluent chaining.