Class ExampleBuilder

java.lang.Object
org.mockserver.openapi.examples.ExampleBuilder

public class ExampleBuilder extends Object
See: https://github.com/swagger-api/swagger-inflector
  • Field Details

  • Constructor Details

    • ExampleBuilder

      public ExampleBuilder()
  • Method Details

    • fromSchema

      public static Example fromSchema(io.swagger.v3.oas.models.media.Schema<?> property, Map<String,io.swagger.v3.oas.models.media.Schema> definitions)
    • fromSchema

      public static Example fromSchema(io.swagger.v3.oas.models.media.Schema<?> property, Map<String,io.swagger.v3.oas.models.media.Schema> definitions, GenerationOptions generationOptions)
    • fromSchema

      public static Example fromSchema(io.swagger.v3.oas.models.media.Schema<?> property, Map<String,io.swagger.v3.oas.models.media.Schema> definitions, GenerationOptions generationOptions, ExampleBuilder.Direction direction)
      Builds an example from a schema, optionally honouring per-run GenerationOptions (a caller-chosen seed for reproducible realistic values and per-field value overrides) and a ExampleBuilder.Direction that drives readOnly/writeOnly property filtering. When generationOptions is null behaviour is identical to the historic two-arg overload (fixed seed 42, no overrides); when direction is ExampleBuilder.Direction.UNSPECIFIED no readOnly/writeOnly filtering is applied.
    • fromSchema

      public static Example fromSchema(io.swagger.v3.oas.models.media.Schema<?> property, Map<String,io.swagger.v3.oas.models.media.Schema> definitions, GenerationOptions generationOptions, ExampleBuilder.Direction direction, Configuration configuration)
      As fromSchema(Schema, Map, GenerationOptions, Direction) but resolving the generateRealisticExampleValues default from a caller-supplied Configuration instance rather than the static ConfigurationProperties store.

      This matters because PUT /mockserver/configuration (and any programmatic configuration.generateRealisticExampleValues(...)) writes only the Configuration instance — it never writes the static store. A null configuration keeps the historic static-store behaviour, and Configuration itself falls back to the static store when the property is unset, so a value set via system property / ConfigurationProperties is still honoured either way.

    • fromProperty

      public static Example fromProperty(String name, io.swagger.v3.oas.models.media.Schema<?> property, Map<String,io.swagger.v3.oas.models.media.Schema> definitions, Map<String,Example> processedModels, Set<String> modelsStartedProcessing, StringBuilder location)
    • alreadyProcessedRefExample

      public static Example alreadyProcessedRefExample(String name, Map<String,io.swagger.v3.oas.models.media.Schema> definitions, Map<String,Example> processedModels)
    • mergeTo

      public static void mergeTo(ObjectExample output, List<Example> examples)
    • normalizeFlattenedExample

      public static Object normalizeFlattenedExample(Object example, io.swagger.v3.oas.models.media.Schema<?> schema)
      Undoes the swagger-parser resolveFully/resolveCombinators artefact whereby a scalar schema flattened from allOf: [ $ref to a scalar ] ends up with its example wrapped in a single-element Collection (a Set or List). For a scalar-typed schema such a collection is never a valid example, so it is unwrapped to the contained value. Non-scalar schemas (objects, arrays) and multi-element collections are returned unchanged. See #2357.