Class SchemaCleanUpUtils
java.lang.Object
com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils
Utility for cleaning up generated schemas.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionensureDefinitionKeyIsPlain(String definitionKey) Replace characters in the given definition key that are neither alphanumeric nor a dot, dash or underscore (as expected by OpenAPI).ensureDefinitionKeyIsUriCompatible(String definitionKey) Replace characters in the given definition key that are deemed incompatible within a URI (as expected by JSON Schema).voidreduceAllOfNodes(List<tools.jackson.databind.node.ObjectNode> jsonSchemas) Remove and mergeSchemaKeyword.TAG_ALLOFparts when there are no conflicts between the sub-schemas.voidreduceAnyOfNodes(List<tools.jackson.databind.node.ObjectNode> jsonSchemas) Reduce nestedSchemaKeyword.TAG_ANYOFparts when one contains an entry with only anotherSchemaKeyword.TAG_ANYOFinside.voidreduceRedundantMemberAttributes(List<tools.jackson.databind.node.ObjectNode> jsonSchemas, tools.jackson.databind.node.ObjectNode definitionsNode, String referenceKeyPrefix) Discard attributes on member schemas, that also reference an entry in the common definitions, which contains those exact same attributes.voidsetStrictTypeInfo(List<tools.jackson.databind.node.ObjectNode> jsonSchemas, boolean considerNullType) Go through all sub-schemas and look for those without aSchemaKeyword.TAG_TYPEindication.
-
Constructor Details
-
SchemaCleanUpUtils
Constructor.- Parameters:
config- configuration to be applied
-
-
Method Details
-
reduceAllOfNodes
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
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
-
reduceRedundantMemberAttributes
public void reduceRedundantMemberAttributes(List<tools.jackson.databind.node.ObjectNode> jsonSchemas, tools.jackson.databind.node.ObjectNode definitionsNode, String referenceKeyPrefix) Discard attributes on member schemas, that also reference an entry in the common definitions, which contains those exact same attributes.- Parameters:
jsonSchemas- generated schemas that may contain redundant attributes in nested object member schemasdefinitionsNode- object node containing common schema definitionsreferenceKeyPrefix- designated prefix to the entries in the returned definitions node (i.e., onSchemaKeyword.TAG_REFvalues)
-
setStrictTypeInfo
public void setStrictTypeInfo(List<tools.jackson.databind.node.ObjectNode> jsonSchemas, boolean considerNullType) Go through all sub-schemas and look for those without aSchemaKeyword.TAG_TYPEindication. 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
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
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
-