Class SchemaCleanUpUtils
- java.lang.Object
-
- com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils
-
public class SchemaCleanUpUtils extends Object
Utility for cleaning up generated schemas.
-
-
Constructor Summary
Constructors Constructor Description SchemaCleanUpUtils(SchemaGeneratorConfig config)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
ensureDefinitionKeyIsPlain(String definitionKey)
Replace characters in the given definition key that are neither alphanumeric nor a dot, dash or underscore (as expected by OpenAPI).String
ensureDefinitionKeyIsUriCompatible(String definitionKey)
Replace characters in the given definition key that are deemed incompatible within a URI (as expected by JSON Schema).void
reduceAllOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
Remove and mergeSchemaKeyword.TAG_ALLOF
parts when there are no conflicts between the sub-schemas.void
reduceAnyOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
Reduce nestedSchemaKeyword.TAG_ANYOF
parts when one contains an entry with only anotherSchemaKeyword.TAG_ANYOF
inside.void
setStrictTypeInfo(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas, boolean considerNullType)
Go through all sub-schemas and look for those without aSchemaKeyword.TAG_TYPE
indication.
-
-
-
Constructor Detail
-
SchemaCleanUpUtils
public SchemaCleanUpUtils(SchemaGeneratorConfig config)
Constructor.- Parameters:
config
- configuration to be applied
-
-
Method Detail
-
reduceAllOfNodes
public void reduceAllOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
Remove and mergeSchemaKeyword.TAG_ALLOF
parts when there are no conflicts between the sub-schemas. This makes for more readable schemas being generated but has the side-effect that any manually addedSchemaKeyword.TAG_ALLOF
(e.g. through a custom definition of attribute overrides) may be removed as well if it isn't strictly speaking necessary.- Parameters:
jsonSchemas
- generated schemas that may contain unnecessarySchemaKeyword.TAG_ALLOF
nodes
-
reduceAnyOfNodes
public void reduceAnyOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
Reduce nestedSchemaKeyword.TAG_ANYOF
parts when one contains an entry with only anotherSchemaKeyword.TAG_ANYOF
inside. This makes for more readable schemas being generated but has the side-effect that any manually addedSchemaKeyword.TAG_ANYOF
(e.g. through a custom definition of attribute overrides) may be removed as well if it isn't strictly speaking necessary.- Parameters:
jsonSchemas
- generated schemas that may contain unnecessary nestedSchemaKeyword.TAG_ANYOF
nodes
-
setStrictTypeInfo
public void setStrictTypeInfo(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas, boolean considerNullType)
Go through all sub-schemas and look for those without aSchemaKeyword.TAG_TYPE
indication. Then try to derive the appropriate type indication from the other present tags (e.g., "properties" implies it is an "object").- Parameters:
jsonSchemas
- sub-schemas to check and extend where required and possibleconsiderNullType
- whether to always include "null" as possible "type" in addition to the implied values- Since:
- 4.30.0
-
ensureDefinitionKeyIsUriCompatible
public String ensureDefinitionKeyIsUriCompatible(String definitionKey)
Replace characters in the given definition key that are deemed incompatible within a URI (as expected by JSON Schema).- Parameters:
definitionKey
-SchemaDefinitionNamingStrategy
output- Returns:
- URI compatible version of the given definition key
-
ensureDefinitionKeyIsPlain
public String ensureDefinitionKeyIsPlain(String definitionKey)
Replace characters in the given definition key that are neither alphanumeric nor a dot, dash or underscore (as expected by OpenAPI).- Parameters:
definitionKey
-SchemaDefinitionNamingStrategy
output- Returns:
- simplified version of the given definition key
-
-