Class CleanSchemaDefinitionNamingStrategy
- java.lang.Object
-
- com.github.victools.jsonschema.generator.naming.CleanSchemaDefinitionNamingStrategy
-
- All Implemented Interfaces:
SchemaDefinitionNamingStrategy
public class CleanSchemaDefinitionNamingStrategy extends Object implements SchemaDefinitionNamingStrategy
Wrapper for aSchemaDefinitionNamingStrategythat performs a specific clean-up task on all returned values.
-
-
Constructor Summary
Constructors Constructor Description CleanSchemaDefinitionNamingStrategy(SchemaDefinitionNamingStrategy strategy, Function<String,String> cleanUpTask)Constructor expecting a naming strategy to be wrapped and the applicable clean-up task.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadjustDuplicateNames(Map<DefinitionKey,String> subschemasWithDuplicateNames, SchemaGenerationContext generationContext)Adjust the names/keys in the "definitions"/"$defs" for the given definition references that have the same names (according toSchemaDefinitionNamingStrategy.getDefinitionNameForKey(DefinitionKey, SchemaGenerationContext)) to ensure their uniqueness.StringadjustNullableName(DefinitionKey key, String definitionName, SchemaGenerationContext generationContext)Provide an alternative definition name for the given key and name when it is nullable.StringgetDefinitionNameForKey(DefinitionKey key, SchemaGenerationContext generationContext)Getter for the name/key in the "definitions"/"$defs" to represent the givenDefinitionKey.
-
-
-
Constructor Detail
-
CleanSchemaDefinitionNamingStrategy
public CleanSchemaDefinitionNamingStrategy(SchemaDefinitionNamingStrategy strategy, Function<String,String> cleanUpTask)
Constructor expecting a naming strategy to be wrapped and the applicable clean-up task.- Parameters:
strategy- definition naming strategy to be wrappedcleanUpTask- task discarding/replacing illegal characters
-
-
Method Detail
-
getDefinitionNameForKey
public String getDefinitionNameForKey(DefinitionKey key, SchemaGenerationContext generationContext)
Description copied from interface:SchemaDefinitionNamingStrategyGetter for the name/key in the "definitions"/"$defs" to represent the givenDefinitionKey.- Specified by:
getDefinitionNameForKeyin interfaceSchemaDefinitionNamingStrategy- Parameters:
key- definition reference for a type (there may be multiple different keys for the same type if custom definitions are involved)generationContext- generation context providing access to the applied configuration and type context- Returns:
- name/key in "definitions"/"$defs" for the indicated subschema
- See Also:
SchemaGenerationContext.getGeneratorConfig(),SchemaGenerationContext.getTypeContext()
-
adjustDuplicateNames
public void adjustDuplicateNames(Map<DefinitionKey,String> subschemasWithDuplicateNames, SchemaGenerationContext generationContext)
Description copied from interface:SchemaDefinitionNamingStrategyAdjust the names/keys in the "definitions"/"$defs" for the given definition references that have the same names (according toSchemaDefinitionNamingStrategy.getDefinitionNameForKey(DefinitionKey, SchemaGenerationContext)) to ensure their uniqueness.
By default, a numeric counter is appended after a separating dash to each duplicate name.- Specified by:
adjustDuplicateNamesin interfaceSchemaDefinitionNamingStrategy- Parameters:
subschemasWithDuplicateNames- definition references that initially have the same values that should be adjustedgenerationContext- generation context providing access to the applied configuration and type context- See Also:
SchemaDefinitionNamingStrategy.getDefinitionNameForKey(DefinitionKey, SchemaGenerationContext)
-
adjustNullableName
public String adjustNullableName(DefinitionKey key, String definitionName, SchemaGenerationContext generationContext)
Description copied from interface:SchemaDefinitionNamingStrategyProvide an alternative definition name for the given key and name when it is nullable.
By default, a"-nullable"suffix will be appended.- Specified by:
adjustNullableNamein interfaceSchemaDefinitionNamingStrategy- Parameters:
key- definition reference for a type (there may be multiple different keys for the same type if custom definitions are involved)definitionName- previous result ofSchemaDefinitionNamingStrategy.getDefinitionNameForKey(DefinitionKey, SchemaGenerationContext)to be adjustedgenerationContext- generation context providing access to the applied configuration and type context- Returns:
- adjusted definition name
-
-