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 SchemaGenerationContextImpladdReference(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.booleancontainsDefinition(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.com.fasterxml.jackson.databind.node.ObjectNodecreateDefinition(com.fasterxml.classmate.ResolvedType targetType)Create an inline definition for the given targetType.com.fasterxml.jackson.databind.node.ObjectNodecreateDefinitionReference(com.fasterxml.classmate.ResolvedType targetType)Create a definition for the given targetType.com.fasterxml.jackson.databind.node.ObjectNodecreateStandardDefinition(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)Create an inline definition for the given targetType.com.fasterxml.jackson.databind.node.ObjectNodecreateStandardDefinition(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)Create a standard definition for the given property.com.fasterxml.jackson.databind.JsonNodecreateStandardDefinition(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)Create a standard definition for the given property.com.fasterxml.jackson.databind.node.ObjectNodecreateStandardDefinitionReference(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)Create a standard definition for the given targetType.com.fasterxml.jackson.databind.node.ObjectNodecreateStandardDefinitionReference(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)Create a standard definition for the given property.com.fasterxml.jackson.databind.JsonNodecreateStandardDefinitionReference(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)Create a standard definition for the given property.Set<DefinitionKey>getDefinedTypes()Retrieve the set of all types for which a definition has been remembered in this context.com.fasterxml.jackson.databind.node.ObjectNodegetDefinition(DefinitionKey key)Retrieve the previously added definition for the specified type.SchemaGeneratorConfiggetGeneratorConfig()Getter for the applicable configuration.StringgetKeyword(SchemaKeyword keyword)Look-up a given keyword's associated tag name or value for the designated JSON Schema version.List<com.fasterxml.jackson.databind.node.ObjectNode>getNullableReferences(DefinitionKey key)Getter for the nodes representing nullable references to the given type.List<com.fasterxml.jackson.databind.node.ObjectNode>getReferences(DefinitionKey key)Getter for the nodes representing not-nullable references to the given type.TypeContextgetTypeContext()Getter for the type resolution/introspection context in use.com.fasterxml.jackson.databind.node.ObjectNodemakeNullable(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".DefinitionKeyparseType(com.fasterxml.classmate.ResolvedType type)Parse the given (possibly generic) type and populate this context.protected voidtraverseGenericType(com.fasterxml.classmate.ResolvedType targetType, com.fasterxml.jackson.databind.node.ObjectNode targetNode, boolean isNullable)Preparation Step: add the given targetType.
-
-
-
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
-
getGeneratorConfig
public SchemaGeneratorConfig getGeneratorConfig()
Description copied from interface:SchemaGenerationContextGetter for the applicable configuration.- Specified by:
getGeneratorConfigin interfaceSchemaGenerationContext- Returns:
- configuration defined for this context
-
getTypeContext
public TypeContext getTypeContext()
Description copied from interface:SchemaGenerationContextGetter for the type resolution/introspection context in use.- Specified by:
getTypeContextin interfaceSchemaGenerationContext- 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 forignoredDefinitionProvider- 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 com.fasterxml.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, 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 referencereferencingNode- node that should (later) include either the type's respective inline definition or a "$ref" to the definitionignoredDefinitionProvider- 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
-
createDefinition
public com.fasterxml.jackson.databind.node.ObjectNode createDefinition(com.fasterxml.classmate.ResolvedType targetType)
Description copied from interface:SchemaGenerationContextCreate an inline definition for the given targetType. Also respecting any custom definition for the given targetType.
This is equivalent to callingcreateStandardDefinition(targetType, null)- Specified by:
createDefinitionin interfaceSchemaGenerationContext- Parameters:
targetType- type to create definition node for- Returns:
- designated definition node for the targetType
- See Also:
SchemaGenerationContext.createDefinitionReference(ResolvedType),SchemaGenerationContext.createStandardDefinition(ResolvedType, CustomDefinitionProviderV2)
-
createDefinitionReference
public com.fasterxml.jackson.databind.node.ObjectNode createDefinitionReference(com.fasterxml.classmate.ResolvedType targetType)
Description copied from interface:SchemaGenerationContextCreate 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 callingcreateStandardDefinitionReference(targetType, null)- Specified by:
createDefinitionReferencein interfaceSchemaGenerationContext- 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:
SchemaGenerationContext.createDefinition(ResolvedType),SchemaGenerationContext.createStandardDefinitionReference(ResolvedType, CustomDefinitionProviderV2)
-
createStandardDefinition
public com.fasterxml.jackson.databind.node.ObjectNode createStandardDefinition(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)Description copied from interface:SchemaGenerationContextCreate an inline definition for the given targetType. Ignoring custom definitions up to the given one, but respecting others.- Specified by:
createStandardDefinitionin interfaceSchemaGenerationContext- Parameters:
targetType- type to create definition node forignoredDefinitionProvider- custom definition provider to ignore- Returns:
- designated definition node for the targetType
- See Also:
SchemaGenerationContext.createDefinition(ResolvedType),SchemaGenerationContext.createStandardDefinitionReference(ResolvedType, CustomDefinitionProviderV2)
-
createStandardDefinition
public com.fasterxml.jackson.databind.node.ObjectNode createStandardDefinition(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)
Description copied from interface:SchemaGenerationContextCreate 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:
createStandardDefinitionin interfaceSchemaGenerationContext- Parameters:
targetScope- property to create definition node forignoredDefinitionProvider- custom definition provider to ignore- Returns:
- inline definition for the given field
- See Also:
SchemaGenerationContext.createDefinitionReference(ResolvedType),SchemaGenerationContext.createStandardDefinitionReference(FieldScope, CustomPropertyDefinitionProvider)
-
createStandardDefinition
public com.fasterxml.jackson.databind.JsonNode createStandardDefinition(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)
Description copied from interface:SchemaGenerationContextCreate 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 anObjectNodeunless the given method isvoid, which will result in aBooleanNode.FALSE.- Specified by:
createStandardDefinitionin interfaceSchemaGenerationContext- Parameters:
targetScope- property to create definition node forignoredDefinitionProvider- custom definition provider to ignore- Returns:
- inline definition for the given method
- See Also:
SchemaGenerationContext.createDefinition(ResolvedType),SchemaGenerationContext.createStandardDefinitionReference(MethodScope, CustomPropertyDefinitionProvider)
-
createStandardDefinitionReference
public com.fasterxml.jackson.databind.node.ObjectNode createStandardDefinitionReference(com.fasterxml.classmate.ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider)Description copied from interface:SchemaGenerationContextCreate 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:
createStandardDefinitionReferencein interfaceSchemaGenerationContext- Parameters:
targetType- type to create definition (reference) node forignoredDefinitionProvider- 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:
SchemaGenerationContext.createDefinitionReference(ResolvedType),SchemaGenerationContext.createStandardDefinition(ResolvedType, CustomDefinitionProviderV2)
-
createStandardDefinitionReference
public com.fasterxml.jackson.databind.node.ObjectNode createStandardDefinitionReference(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider)
Description copied from interface:SchemaGenerationContextCreate 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:
createStandardDefinitionReferencein interfaceSchemaGenerationContext- Parameters:
targetScope- property to create definition (reference) node forignoredDefinitionProvider- 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:
SchemaGenerationContext.createDefinitionReference(ResolvedType),SchemaGenerationContext.createStandardDefinition(FieldScope, CustomPropertyDefinitionProvider)
-
createStandardDefinitionReference
public com.fasterxml.jackson.databind.JsonNode createStandardDefinitionReference(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider)
Description copied from interface:SchemaGenerationContextCreate 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 anObjectNodeunless the given method isvoid, which will result in aBooleanNode.FALSE.- Specified by:
createStandardDefinitionReferencein interfaceSchemaGenerationContext- Parameters:
targetScope- property to create definition (reference) node forignoredDefinitionProvider- 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:
SchemaGenerationContext.createDefinitionReference(ResolvedType),SchemaGenerationContext.createStandardDefinition(MethodScope, CustomPropertyDefinitionProvider)
-
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 addtargetNode- node in the JSON schema that should represent the targetTypeisNullable- 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:SchemaGenerationContextEnsure that the JSON schema represented by the given node allows for it to be of "type" "null".- Specified by:
makeNullablein interfaceSchemaGenerationContext- Parameters:
node- representation of a JSON schema (part) that should allow a value of "type" "null"- Returns:
- reference to the given parameter node
-
getKeyword
public String getKeyword(SchemaKeyword keyword)
Description copied from interface:SchemaGenerationContextLook-up a given keyword's associated tag name or value for the designated JSON Schema version.- Specified by:
getKeywordin interfaceSchemaGenerationContext- Parameters:
keyword- reference to a tag name or value- Returns:
- specific tag name or value in the designated JSON Schema version
- See Also:
SchemaGeneratorConfig.getKeyword(SchemaKeyword)
-
-