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 Summary
Constructors Constructor Description SchemaGenerationContextImpl(SchemaGeneratorConfig generatorConfig, TypeContext typeContext)
Constructor initialising type resolution context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsDefinition(com.fasterxml.classmate.ResolvedType javaType)
Whether this context (already) contains a definition for the specified type.com.fasterxml.jackson.databind.node.ObjectNode
createDefinition(com.fasterxml.classmate.ResolvedType targetType)
Create an inline definition for the given targetType.com.fasterxml.jackson.databind.node.ObjectNode
createStandardDefinition(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)
Create an inline definition for the given targetType.Set<com.fasterxml.classmate.ResolvedType>
getDefinedTypes()
Retrieve the set of all types for which a definition has been remembered in this context.com.fasterxml.jackson.databind.node.ObjectNode
getDefinition(com.fasterxml.classmate.ResolvedType javaType)
Retrieve the previously added definition for the specified type.List<com.fasterxml.jackson.databind.node.ObjectNode>
getNullableReferences(com.fasterxml.classmate.ResolvedType javaType)
Getter for the nodes representing nullable references to the given type.List<com.fasterxml.jackson.databind.node.ObjectNode>
getReferences(com.fasterxml.classmate.ResolvedType javaType)
Getter for the nodes representing not-nullable references to the given type.TypeContext
getTypeContext()
Getter for the type resolution/introspection context in use.com.fasterxml.jackson.databind.node.ObjectNode
makeNullable(com.fasterxml.jackson.databind.node.ObjectNode node)
Ensure that the JSON schema represented by the given node allows for it to be of "type" "null".void
parseType(com.fasterxml.classmate.ResolvedType type)
Parse the given (possibly generic) type and populate this context.
-
-
-
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
-
getTypeContext
public TypeContext getTypeContext()
Description copied from interface:SchemaGenerationContext
Getter for the type resolution/introspection context in use.- Specified by:
getTypeContext
in interfaceSchemaGenerationContext
- Returns:
- type resolution/introspection context
-
parseType
public void 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
-
containsDefinition
public boolean containsDefinition(com.fasterxml.classmate.ResolvedType javaType)
Whether this context (already) contains a definition for the specified type.- Parameters:
javaType
- type to check for- Returns:
- whether a definition for the given type is already present
-
getDefinition
public com.fasterxml.jackson.databind.node.ObjectNode getDefinition(com.fasterxml.classmate.ResolvedType javaType)
Retrieve the previously added definition for the specified type.- Parameters:
javaType
- type for which to retrieve the stored definition- Returns:
- JSON schema definition (or null if none is present)
- See Also:
putDefinition(ResolvedType, ObjectNode)
-
getDefinedTypes
public Set<com.fasterxml.classmate.ResolvedType> 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
-
getReferences
public List<com.fasterxml.jackson.databind.node.ObjectNode> getReferences(com.fasterxml.classmate.ResolvedType javaType)
Getter for the nodes representing not-nullable references to the given type.- Parameters:
javaType
- target type- Returns:
- not-nullable nodes to be populated with the schema of the given type
-
getNullableReferences
public List<com.fasterxml.jackson.databind.node.ObjectNode> getNullableReferences(com.fasterxml.classmate.ResolvedType javaType)
Getter for the nodes representing nullable references to the given type.- Parameters:
javaType
- target type- Returns:
- nullable nodes to be populated with the schema of the given type
-
createDefinition
public com.fasterxml.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.- Specified by:
createDefinition
in interfaceSchemaGenerationContext
- Parameters:
targetType
- type to create definition (reference) node for- Returns:
- designated definition (reference) node for the targetType
- See Also:
SchemaGenerationContext.createStandardDefinition(ResolvedType, CustomDefinitionProviderV2)
-
createStandardDefinition
public com.fasterxml.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 interfaceSchemaGenerationContext
- Parameters:
targetType
- type to create definition (reference) node forignoredDefinitionProvider
- custom definition provider to ignore- Returns:
- designated definition (reference) node for the targetType
- See Also:
SchemaGenerationContext.createDefinition(ResolvedType)
-
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 interfaceSchemaGenerationContext
- Parameters:
node
- representation of a JSON schema (part) that should allow a value of "type" "null"- Returns:
- reference to the given parameter node
-
-