Refactor recommendations¶
Overview¶
The refactor
exporter provides a way to generalize a set of ALFA definitions such that common fields are elevated into common ‘Base’ types (generalize), and existing types extend the ‘Base’ type with fields unqiue to them (specialize).
If a field’s name and data type are identical across 2 or more definitions, it becomes a candidate to be generalized into a ‘Base’ type definition. This may not always be suitable, therefore the behaviour can be controlled via configuration.
This action is performed as an export
, without modifying the orignal source, so it is possible to evaluate options, identify reusable model patterns and guide how a model could look.
Usage:
The export can excuted using the ALFA Maven CLI command:
mvn "com.schemarise.alfa.utils:alfa-maven-plugin:3.5.5:cli" "-Dalfa.exporters=refactor" "-Dalfa.output=target" "-Dalfa.settings=namespace=demo" "-Dalfa.sourcepath=model"
NOTE: The sourcepath
is the path to the existing ALFA model defintions.
Example¶
Before¶
The following diagram shows a generated diagam from an JSON Schema model imported into ALFA, before any refactor is performed.
This model contained definitions with some attributes being common to many
definitions in the model (e.g. source
, version_id
). Overall, the model definitions are ‘disconnected’ and isolated.

After¶
The diagram below shows the generated diagram after refactor
export is performed. Common attributed have been brought out as ‘Base’ types, allowing some hierachy to be seen.
If suitable names are given to generated ‘Base’ definitions, in many cases, the model as a whole can result in a better representation.

Configuration¶
The refactoring can be controlled via configuration such as to control over-generalization with many levels in a hierarchy.
These can be set via settings
configuration.
ignoreFields
: comma seprated list of fields not to be considered for refactoringgroupAttribSizeThreshold
: number of attributes considered ‘common’ between 2 or more types before a Base type is created, default 2groupUsageCountPercentage
: number of types from which fields are being specialized into a Base typegeneratedNamePrefix
: Prefix to be used for Base types. Default is ‘Base’