Class ChenileJsonSchemaGenerator

java.lang.Object
org.chenile.core.schema.ChenileJsonSchemaGenerator

public class ChenileJsonSchemaGenerator extends Object
Generates the JSON Schema (Draft 2020-12, the dialect of OpenAPI 3.1) of a Java type. It is the one schema generator for Chenile's published contracts, so MCP tools, OpenAPI and the service registry describe a type the same way.

The schema follows Jackson's view of the type (property names, @JsonProperty(required = true)) and carries no $schema keyword, because it is usually embedded in a larger document. Referenced types are placed under $defs, keyed by their simple class names.

For documents with shared schemas (OpenAPI, the service registry), generateReference(Type, ObjectNode) and withComponents(ObjectNode, ObjectNode) move definitions into a components map and point references at #/components/schemas/, so every contract names and shares types the same way.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Where shared schemas live in an OpenAPI-style document.
    private static final String
     
    private final com.github.victools.jsonschema.generator.SchemaGenerator
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    tools.jackson.databind.node.ObjectNode
    generate(Type type)
    The JSON Schema of a type, which may be generic (for example List<Order>).
    tools.jackson.databind.node.ObjectNode
    generateReference(Type type, tools.jackson.databind.node.ObjectNode components)
    The schema of a type for a document with shared components.
    private void
    rewriteChildReferences(tools.jackson.databind.JsonNode node)
     
    private tools.jackson.databind.node.ObjectNode
    rewriteReferences(tools.jackson.databind.node.ObjectNode node)
     
    tools.jackson.databind.node.ObjectNode
    withComponents(tools.jackson.databind.node.ObjectNode schema, tools.jackson.databind.node.ObjectNode components)
    Moves a schema's $defs into components and points its references (and theirs) at #/components/schemas/.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • COMPONENTS_REF

      public static final String COMPONENTS_REF
      Where shared schemas live in an OpenAPI-style document.
      See Also:
    • DEFS_REF

      private static final String DEFS_REF
      See Also:
    • generator

      private final com.github.victools.jsonschema.generator.SchemaGenerator generator
  • Constructor Details

    • ChenileJsonSchemaGenerator

      public ChenileJsonSchemaGenerator()
  • Method Details

    • generate

      public tools.jackson.databind.node.ObjectNode generate(Type type)
      The JSON Schema of a type, which may be generic (for example List<Order>).
    • generateReference

      public tools.jackson.databind.node.ObjectNode generateReference(Type type, tools.jackson.databind.node.ObjectNode components)
      The schema of a type for a document with shared components. Referenced types go into components; a named object type goes there too, under its simple class name, and a $ref to it is returned. Other types (scalars, collections, generics) are returned inline.
      Parameters:
      components - the document's components (name to schema); added to
    • withComponents

      public tools.jackson.databind.node.ObjectNode withComponents(tools.jackson.databind.node.ObjectNode schema, tools.jackson.databind.node.ObjectNode components)
      Moves a schema's $defs into components and points its references (and theirs) at #/components/schemas/. Changes and returns the given schema.
    • rewriteReferences

      private tools.jackson.databind.node.ObjectNode rewriteReferences(tools.jackson.databind.node.ObjectNode node)
    • rewriteChildReferences

      private void rewriteChildReferences(tools.jackson.databind.JsonNode node)