-
Notifications
You must be signed in to change notification settings - Fork 2
Plugin Development
Plugins that modify the generated classes. These can be plugins for example, adding fields and methods to the class, making the class java.io.Serializable, or adding specific annotations to the class or it's methods.
All Class Generator Plugins implement the ClassGeneratorPlugin interface:
public interface ClassModifyingPlugin {
/**
* Modifies the generation of a class.
*
* @param classBuilder A builder for generating the class
* @param classDefinition The definition of the class from the json schema document
* @param pluginContext Access to any data the plugin might need
*
* @return The modified class's {@link TypeSpec} builder
*/
TypeSpec.Builder generateWith(final TypeSpec.Builder classBuilder,
final ClassDefinition classDefinition,
final PluginContext pluginContext);
}
Plugins that modify return types and parameters of generated classes. For example these plugins can change the types of nullable properties in a class to java.util.Optional, support for java.util.UUID as return types and constructor parameters, or support for java.time.ZonedDateTime as return types and constructor parameters.
All Type Name Plugins implement the TypeNamePlugin interface:
public interface TypeModifyingPlugin {
/**
* Modifies the TypeName (used as constructor parameters and getter return types) of
* generated classes in some way.
*
* @param typeName The type name to be modified
* @param definition The FieldDefinition of the type to be modified
*
* @return The modified type name
*/
TypeName modifyTypeName(final TypeName typeName, final Definition definition);
}
Plugins that produce a root field name for the root schema from a file. The plugin can decide to parse the schema for a description field or parse the schema filename to create an appropriate name for the schema. Note: the field name is converted to produce the Class name at generation time, by uppercasing the first character of the field name.
All Name Generatable Plugins implement the NameGeneratablePlugin interface:
public interface NameGeneratablePlugin {
/**
* Generates a schema field name for the root schema from the {@link Schema} and schema
* filename.
*
* @param schema the {@link Schema} to produce a field name for
* @param schemaFilename the schema filename to produce a field name for
* @return the root field name
*/
String rootFieldNameFrom(final Schema schema, final String schemaFilename);
}