Class 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 Detail

      • 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 Detail

      • 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
      • 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,
                                                        com.fasterxml.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<com.fasterxml.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<com.fasterxml.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
      • traverseGenericType

        protected void traverseGenericType​(com.fasterxml.classmate.ResolvedType targetType,
                                           com.fasterxml.jackson.databind.node.ObjectNode targetNode,
                                           boolean isNullable)
        Preparation Step: add the given targetType.
        Parameters:
        targetType - (possibly generic) type to add
        targetNode - node in the JSON schema that should represent the targetType
        isNullable - whether the field/method's return value is allowed to be null in the declaringType in this particular scenario
      • makeNullable

        public com.fasterxml.jackson.databind.node.ObjectNode makeNullable​(com.fasterxml.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