Class JsonSchemaInferencer

java.lang.Object
com.shaft.capture.generate.api.JsonSchemaInferencer

public final class JsonSchemaInferencer extends Object
Infers a standard (draft-04-compatible) JSON Schema document from one recorded sample response body, for use with SHAFT.API's assertThatResponse().matchesSchema(path), which is backed by REST-Assured's io.restassured.module.jsv.JsonSchemaValidator.

Since a schema is inferred from exactly one recorded sample, every key observed on an object is marked required -- this is deliberately strict (a real endpoint may omit optional keys on other calls) but matches what was actually recorded; nothing here invents fields that were never observed.

  • Method Details

    • infer

      public static String infer(String sampleJson)
      Infers a JSON Schema document from a sample JSON body.
      Parameters:
      sampleJson - recorded response body text
      Returns:
      pretty-printed JSON Schema text, or an empty-object schema ("{}") if the sample is blank or not valid JSON