Class SchemaCleanUpUtils


  • public class SchemaCleanUpUtils
    extends Object
    Utility for cleaning up generated schemas.
    • 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 merge SchemaKeyword.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 added SchemaKeyword.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 unnecessary SchemaKeyword.TAG_ALLOF nodes
      • reduceAnyOfNodes

        public void reduceAnyOfNodes​(List<com.fasterxml.jackson.databind.node.ObjectNode> jsonSchemas)
        Reduce nested SchemaKeyword.TAG_ANYOF parts when one contains an entry with only another SchemaKeyword.TAG_ANYOF inside. This makes for more readable schemas being generated but has the side-effect that any manually added SchemaKeyword.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 nested SchemaKeyword.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 a SchemaKeyword.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 possible
        considerNullType - 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