Class SchemaReferenceCompositionSupport

java.lang.Object
io.micronaut.jsonschema.generator.SchemaReferenceCompositionSupport

@Internal public final class SchemaReferenceCompositionSupport extends Object
Shared support for same-document JSON Schema references and composition that changes Java type shape.
Since:
2.2.0
  • Method Details

    • prepareLocalCompositionReferences

      public static void prepareLocalCompositionReferences(Schema schema)
      Prepare a schema tree for the record-generation path by materializing supported local references before the schema is handed to SourceGenerator.

      This method mutates the supplied schema. It resolves same-document definition references (#/$defs/... and #/definitions/...) when they appear as root references or inside compatible allOf branches, then flattens object-compatible allOf branches into the composed schema. Definitions are prepared as well because they can be emitted as generated Java types.

      This is deliberately not a general JSON Schema resolver. It does not fetch remote references, resolve arbitrary JSON Pointers, canonicalize schemas, or sort Java members. Unsupported or ambiguous composition is left detectable by hasUnsupportedAllOf(Schema) so the record-generation pipeline can fail, skip, or fall back according to context.

      Parameters:
      schema - The schema to prepare
    • hasUnsupportedAllOf

      public static boolean hasUnsupportedAllOf(Schema schema)
      Check whether a schema has unsupported or ambiguous allOf composition after supported local references have been prepared.

      The check accepts only object-compatible branches that can be represented as one Java type. It rejects unresolved references, union-style branches, non-object typed branches, incompatible duplicate properties, and contradictory additionalProperties rules.

      Parameters:
      schema - The schema
      Returns:
      True when allOf cannot be flattened deterministically
    • isExternalRef

      public static boolean isExternalRef(String ref)
      Check whether a reference points outside the current schema document.

      External references are not resolved by this support class or by the record-generation pipeline.

      Parameters:
      ref - The reference value
      Returns:
      True for external references
    • isSupportedLocalRef

      public static boolean isSupportedLocalRef(String ref)
      Check whether a reference points to a supported local target.

      The supported local targets are the current document (#) and definitions under #/$defs/... or legacy #/definitions/.... Other same-document JSON Pointers are intentionally unsupported here.

      Parameters:
      ref - The reference value
      Returns:
      True for supported local references