Class SchemaGenerationContextImpl

java.lang.Object
com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl
All Implemented Interfaces:
SchemaGenerationContext

public class SchemaGenerationContextImpl extends Object implements SchemaGenerationContext
Generation context in which to collect definitions of traversed types and remember where they are being referenced.
  • Constructor Details

    • SchemaGenerationContextImpl

      public SchemaGenerationContextImpl(SchemaGeneratorConfig generatorConfig, TypeContext typeContext)
      Constructor initialising type resolution context.
      Parameters:
      generatorConfig - applicable configuration(s)
      typeContext - type resolution/introspection context to be used
  • Method Details

    • getGeneratorConfig

      public SchemaGeneratorConfig getGeneratorConfig()
      Description copied from interface: SchemaGenerationContext
      Getter for the applicable configuration.
      Specified by:
      getGeneratorConfig in interface SchemaGenerationContext
      Returns:
      configuration defined for this context
    • getTypeContext

      public TypeContext getTypeContext()
      Description copied from interface: SchemaGenerationContext
      Getter for the type resolution/introspection context in use.
      Specified by:
      getTypeContext in interface SchemaGenerationContext
      Returns:
      type resolution/introspection context
    • parseType

      public DefinitionKey parseType(com.fasterxml.classmate.ResolvedType type)
      Parse the given (possibly generic) type and populate this context. This is intended to be used only once, for the schema's main target type.
      Parameters:
      type - (possibly generic) type to analyse and populate this context with
      Returns:
      definition key identifying the given entry point
    • containsDefinition

      public boolean containsDefinition(com.fasterxml.classmate.ResolvedType javaType, CustomDefinitionProviderV2 ignoredDefinitionProvider)
      Whether this context (already) contains a definition for the specified type, considering custom definition providers after the specified one.
      Parameters:
      javaType - type to check for
      ignoredDefinitionProvider - first custom definition provider that was ignored when creating the definition (is null in most cases)
      Returns:
      whether a definition for the given type is already present
    • getDefinition

      public tools.jackson.databind.node.ObjectNode getDefinition(DefinitionKey key)
      Retrieve the previously added definition for the specified type.
      Parameters:
      key - definition key to look-up associated definition for
      Returns:
      JSON schema definition (or null if none is present)
      See Also:
      • putDefinition(ResolvedType, ObjectNode, CustomDefinitionProviderV2)
    • getDefinedTypes

      public Set<DefinitionKey> getDefinedTypes()
      Retrieve the set of all types for which a definition has been remembered in this context.
      Returns:
      types for which a definition is present
    • addReference

      public SchemaGenerationContextImpl addReference(com.fasterxml.classmate.ResolvedType javaType, tools.jackson.databind.node.ObjectNode referencingNode, CustomDefinitionProviderV2 ignoredDefinitionProvider, boolean isNullable)
      Remember for the specified type that the given node is supposed to either include or reference the type's associated schema.
      Parameters:
      javaType - type for which to remember a reference
      referencingNode - node that should (later) include either the type's respective inline definition or a "$ref" to the definition
      ignoredDefinitionProvider - first custom definition provider that was ignored when creating the definition (is null in most cases)
      isNullable - whether the reference may be null
      Returns:
      this context (for chaining)
    • getReferences

      public List<tools.jackson.databind.node.ObjectNode> getReferences(DefinitionKey key)
      Getter for the nodes representing not-nullable references to the given type.
      Parameters:
      key - definition key to look-up collected references for
      Returns:
      not-nullable nodes to be populated with the schema of the given type
    • getNullableReferences

      public List<tools.jackson.databind.node.ObjectNode> getNullableReferences(DefinitionKey key)
      Getter for the nodes representing nullable references to the given type.
      Parameters:
      key - definition key to look-up collected references for
      Returns:
      nullable nodes to be populated with the schema of the given type
    • shouldNeverInlineDefinition

      public boolean shouldNeverInlineDefinition(DefinitionKey key)
      Determine whether the definition for the given type should always be included in the SchemaKeyword.TAG_DEFINITIONS, even if only occurring once.
      Parameters:
      key - definition key to determine desired definition behaviour for
      Returns:
      whether to always produce a referenced definition for the given type
      Since:
      4.27.0
    • createDefinition

      public tools.jackson.databind.node.ObjectNode createDefinition(com.fasterxml.classmate.ResolvedType targetType)
      Description copied from interface: SchemaGenerationContext
      Create an inline definition for the given targetType. Also respecting any custom definition for the given targetType.
      This is equivalent to calling createStandardDefinition(targetType, null)
      Specified by:
      createDefinition in interface SchemaGenerationContext
      Parameters:
      targetType - type to create definition node for
      Returns:
      designated definition node for the targetType
      See Also:
    • createDefinitionReference

      public tools.jackson.databind.node.ObjectNode createDefinitionReference(com.fasterxml.classmate.ResolvedType targetType)
      Description copied from interface: SchemaGenerationContext
      Create a definition for the given targetType. Also respecting any custom definition for the given targetType.
      The returned node will be empty, but is being remembered internally and populated later, i.e. it should not be changed!
      This is equivalent to calling createStandardDefinitionReference(targetType, null)
      Specified by:
      createDefinitionReference in interface SchemaGenerationContext
      Parameters:
      targetType - type to create definition (reference) node for
      Returns:
      (temporarily) empty reference node for the targetType that will only be populated at the very end of the schema generation
      See Also:
    • createStandardDefinition

      public tools.jackson.databind.node.ObjectNode createStandardDefinition(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create an inline definition for the given targetType. Ignoring custom definitions up to the given one, but respecting others.
      Specified by:
      createStandardDefinition in interface SchemaGenerationContext
      Parameters:
      targetType - type to create definition node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      designated definition node for the targetType
      See Also:
    • createStandardDefinition

      public tools.jackson.databind.node.ObjectNode createStandardDefinition(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
      The returned schema will be inlined and fully populated, i.e. it may be further manipulated - at the risk of an endless loop in case of a circular reference.
      Specified by:
      createStandardDefinition in interface SchemaGenerationContext
      Parameters:
      targetScope - property to create definition node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      inline definition for the given field
      See Also:
    • createStandardDefinition

      public tools.jackson.databind.JsonNode createStandardDefinition(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
      The returned schema will be inlined and fully populated, i.e. it may be further manipulated - at the risk of an endless loop in case of a circular reference.
      The returned type is always an ObjectNode unless the given method is void, which will result in a BooleanNode.FALSE.
      Specified by:
      createStandardDefinition in interface SchemaGenerationContext
      Parameters:
      targetScope - property to create definition node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      inline definition for the given method
      See Also:
    • createStandardDefinitionReference

      public tools.jackson.databind.node.ObjectNode createStandardDefinitionReference(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create a standard definition for the given targetType. Ignoring custom definitions up to the given one, but respecting others.
      The returned node will be empty, but is being remembered internally and populated later, i.e. it should not be changed!
      Specified by:
      createStandardDefinitionReference in interface SchemaGenerationContext
      Parameters:
      targetType - type to create definition (reference) node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      (temporarily) empty reference node for the targetType that will only be populated at the very end of the schema generation
      See Also:
    • createStandardDefinitionReference

      public tools.jackson.databind.node.ObjectNode createStandardDefinitionReference(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
      If a specific custom definition for this field is being applied, it will be inlined and fully populated; that may be further manipulated. Otherwise, the returned node will be empty and is populated only later, i.e. it should not be changed in that case!
      Specified by:
      createStandardDefinitionReference in interface SchemaGenerationContext
      Parameters:
      targetScope - property to create definition (reference) node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      either custom inline definition for this field or a (temporarily) empty reference node for the targetType that will only be populated at the very end of the schema generation
      See Also:
    • createStandardDefinitionReference

      public tools.jackson.databind.JsonNode createStandardDefinitionReference(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)
      Description copied from interface: SchemaGenerationContext
      Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
      If a specific custom definition for this method is being applied, it will be inlined and fully populated; that may be further manipulated. Otherwise, the returned node will be empty and is populated only later, i.e. it should not be changed in that case!
      The returned type is always an ObjectNode unless the given method is void, which will result in a BooleanNode.FALSE.
      Specified by:
      createStandardDefinitionReference in interface SchemaGenerationContext
      Parameters:
      targetScope - property to create definition (reference) node for
      ignoredDefinitionProvider - custom definition provider to ignore
      Returns:
      either custom inline definition for this method or a (temporarily) empty reference node for the targetType that will only be populated at the very end of the schema generation
      See Also:
    • traverseGenericType

      protected void traverseGenericType(com.fasterxml.classmate.ResolvedType targetType, tools.jackson.databind.node.ObjectNode targetNode)
      Preparation Step: add the given targetType.
      Parameters:
      targetType - (possibly generic) type to add
      targetNode - node in the JSON schema that should represent the targetType
    • getKeyword

      public String getKeyword(SchemaKeyword keyword)
      Description copied from interface: SchemaGenerationContext
      Look-up a given keyword's associated tag name or value for the designated JSON Schema version.
      Specified by:
      getKeyword in interface SchemaGenerationContext
      Parameters:
      keyword - reference to a tag name or value
      Returns:
      specific tag name or value in the designated JSON Schema version
      See Also:
    • makeNullable

      public tools.jackson.databind.node.ObjectNode makeNullable(tools.jackson.databind.node.ObjectNode node)
      Description copied from interface: SchemaGenerationContext
      Ensure that the JSON schema represented by the given node allows for it to be of "type" "null".
      Specified by:
      makeNullable in interface SchemaGenerationContext
      Parameters:
      node - representation of a JSON schema (part) that should allow a value of "type" "null"
      Returns:
      reference to the given parameter node