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 StringensureDefinitionKeyIsPlain(String definitionKey)Replace characters in the given definition key that are neither alphanumeric nor a dot, dash or underscore (as expected by OpenAPI).StringensureDefinitionKeyIsUriCompatible(String definitionKey)Replace characters in the given definition key that are deemed incompatible within a URI (as expected by JSON Schema).voidreduceAllOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)Remove and mergeSchemaKeyword.TAG_ALLOFparts when there are no conflicts between the sub-schemas.voidreduceAnyOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)Reduce nestedSchemaKeyword.TAG_ANYOFparts when one contains an entry with only anotherSchemaKeyword.TAG_ANYOFinside.
-
-
-
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_ALLOFparts 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_ALLOFnodes
-
reduceAnyOfNodes
public void reduceAnyOfNodes(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
Reduce nestedSchemaKeyword.TAG_ANYOFparts when one contains an entry with only anotherSchemaKeyword.TAG_ANYOFinside. 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_ANYOFnodes
-
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-SchemaDefinitionNamingStrategyoutput- 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-SchemaDefinitionNamingStrategyoutput- Returns:
- simplified version of the given definition key
-
-