Class SchemaCleanUpUtils

java.lang.Object
com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils

public class SchemaCleanUpUtils extends Object
Utility for cleaning up generated schemas.
  • Constructor Details

    • SchemaCleanUpUtils

      public SchemaCleanUpUtils(SchemaGeneratorConfig config)
      Constructor.
      Parameters:
      config - configuration to be applied
  • Method Details

    • reduceAllOfNodes

      public void reduceAllOfNodes(List<tools.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<tools.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
    • 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 schemas
      definitionsNode - object node containing common schema definitions
      referenceKeyPrefix - designated prefix to the entries in the returned definitions node (i.e., on SchemaKeyword.TAG_REF values)
    • setStrictTypeInfo

      public void setStrictTypeInfo(List<tools.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