Class AbstractMapper
- Direct Known Subclasses:
MessageMapper,SchemaMapper
Provides reusable methods to:
- Populate
VariablePropertiesfrom raw YAML maps - Handle various field types: primitives, collections, maps, enums, polymorphic schemas, and references
- Apply validation annotations and required imports based on
requiredand format constraints - Resolve inner/anonymous schemas and register them for separate generation
Subclasses SchemaMapper and MessageMapper
extend this to implement schema- and message-specific logic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final NamingStrategyNaming strategy for field/method name transformations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an AbstractMapper with default dependencies.protectedAbstractMapper(NamingStrategy namingStrategy) Creates an AbstractMapper with a specific naming strategy and a default resolver.protectedAbstractMapper(NamingStrategy namingStrategy, PropertyTypeResolver propertyTypeResolver) Creates an AbstractMapper with injected dependencies. -
Method Summary
Modifier and TypeMethodDescriptioncollectPolymorphRefs(Map<String, Object> propertiesMap) Collects all polymorphic references (oneOf, allOf, anyOf) from a properties map.protected voidfillArrayProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes array-type fields and configures collection type, element type, and realization.protected static voidfillCollectionType(VariableProperties variableProperties) Sets the final Java collection type string (e.g.,List<String>) based oncollectionType.protected static voidfillCollectionWithExistingObject(VariableProperties variableProperties, Map<String, Object> items) Configures collection realization and import forformat: existingarrays.protected voidfillEnumProperties(String schemaName, VariableProperties variableProperties, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes enum fields and registers the corresponding enum schema ininnerSchemas.protected static voidfillEnumSchema(String enumSchemaName, Map<String, Object> propertiesMap, Map<String, Object> innerSchemas) Registers an enum schema ininnerSchemasbased on raw YAML definition.protected static voidfillExistingObjectProperties(VariableProperties variableProperties) ConfiguresVariablePropertiesforformat: existingreferences.protected voidfillInnerSchema(VariableProperties variableProperties, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Registers an inner schema for subsequent DTO generation.protected voidfillMapProperties(VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, Map<String, Object> propertiesMap, ProcessContext processContext) Fills map-related properties (e.g.,additionalProperties) intoVariableProperties.static voidfillMessageFromChannel(Map<String, Object> allContent, Map<String, Object> messagesMap, Set<String> excludeSchemas, Map<String, Object> mapToMessage, String channelName, String channelType) PopulatesmessagesMapfrom AsyncAPI 2.xchannels/publish/subscribesections.protected voidfillObjectProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes inner/anonymous object schemas and registers them for separate DTO generation.voidfillProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Populates aVariablePropertiesinstance from a raw YAML property definition.protected voidfillReferenceProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Resolves$refreferences and populates field type/imports accordingly.static voidfillRequiredAnnotationsAndImports(VariableProperties variableProperties, Map<String, Object> currentSchema, String propertyName) Applies validation annotations and imports based onrequired, validation groups, and field type.voidfillVariableProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Resolves the concrete Java type and metadata for a field based on its raw YAML definition.protected StringprepareImport(ProcessContext ctx, String className) Prepares a full import string for a class in the common package.
-
Field Details
-
namingStrategy
Naming strategy for field/method name transformations.
-
-
Constructor Details
-
AbstractMapper
Creates an AbstractMapper with injected dependencies.- Parameters:
namingStrategy- the naming strategy to usepropertyTypeResolver- the property type resolver (Chain of Responsibility)
-
AbstractMapper
Creates an AbstractMapper with a specific naming strategy and a default resolver.- Parameters:
namingStrategy- the naming strategy to use
-
AbstractMapper
protected AbstractMapper()Creates an AbstractMapper with default dependencies.
-
-
Method Details
-
collectPolymorphRefs
Collects all polymorphic references (oneOf, allOf, anyOf) from a properties map.This pattern is repeated in multiple places; extracting it here avoids duplication.
- Parameters:
propertiesMap- the raw property definition map- Returns:
- flat list of all polymorphic reference objects
-
fillProperties
public void fillProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Populates aVariablePropertiesinstance from a raw YAML property definition.Sets basic field metadata (name, type, description, example, validation attributes) and delegates detailed type resolution to
fillVariableProperties(java.lang.String, ru.yojo.codegen.domain.VariableProperties, java.util.Map<java.lang.String, java.lang.Object>, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, ru.yojo.codegen.context.ProcessContext, java.util.Map<java.lang.String, java.lang.Object>).- Parameters:
schemaName- name of the containing schema (used for logging and inner schema naming)variableProperties- target field container to populatecurrentSchema- full schema map where this property is definedschemas- global map of all known schemas (for $ref resolution)propertyName- original YAML key (e.g.,"email")propertiesMap- raw YAML map for this field (e.g.,{ type: string, format: email })processContext- current generation context (Spring Boot version, helper, etc.)innerSchemas- accumulator for discovered inner schemas (e.g., anonymous objects, enums)
-
fillVariableProperties
public void fillVariableProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Resolves the concrete Java type and metadata for a field based on its raw YAML definition.Handles:
- Maps (
additionalProperties) - Arrays (
type: array) with realization and nested types - References (
$ref) - Plain/inner objects
- Enums
format: existingfor external classes- Polymorphic constructs (
oneOf,allOf,anyOf)
- Parameters:
schemaName- name of the containing schemavariableProperties- field container to populatecurrentSchema- current schema mapschemas- global schema registrypropertyName- field name in YAMLpropertiesMap- raw field definitionprocessContext- generation contextinnerSchemas- accumulator for inner schemas
- Maps (
-
prepareImport
Prepares a full import string for a class in the common package.- Parameters:
ctx- process context to resolve common packageclassName- simple class name- Returns:
- full import, e.g.,
"com.example.common.MyClass;"
-
fillMapProperties
protected void fillMapProperties(VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, Map<String, Object> propertiesMap, ProcessContext processContext) Fills map-related properties (e.g.,additionalProperties) intoVariableProperties. Supports:- Primitive value types (e.g.,
Map<String, Integer>) - Custom object values (via
$ref) - Nested collections (e.g.,
Map<String, List<User>>) - Custom key types (e.g.,
Map<UUID, ...>) realizationfor map initialization
- Parameters:
variableProperties- target fieldcurrentSchema- current schema mapschemas- global schemaspropertiesMap- field definition (must containadditionalProperties)processContext- context
- Primitive value types (e.g.,
-
fillExistingObjectProperties
ConfiguresVariablePropertiesforformat: existingreferences. Sets type to the simple class name and adds the required import.- Parameters:
variableProperties- field to configure
-
fillEnumProperties
protected void fillEnumProperties(String schemaName, VariableProperties variableProperties, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes enum fields and registers the corresponding enum schema ininnerSchemas.If
x-enumNamesis present, generates an enum with description field; otherwise, a plain enum.- Parameters:
schemaName- name of the parent schemavariableProperties- field containerpropertyName- YAML keypropertiesMap- raw enum definitionprocessContext- contextinnerSchemas- accumulator
-
fillObjectProperties
protected void fillObjectProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes inner/anonymous object schemas and registers them for separate DTO generation.Generates a unique name (e.g.,
ParentSchemaPropertyName) and stores the synthetic schema ininnerSchemas.- Parameters:
schemaName- name of the parent schemavariableProperties- field containerschemas- full schema map for reference resolutionpropertyName- proposed inner schema namepropertiesMap- raw object definitionprocessContext- contextinnerSchemas- accumulator
-
fillReferenceProperties
protected void fillReferenceProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Resolves$refreferences and populates field type/imports accordingly.Handles recursive type resolution (e.g.,
$refto scalar formats), detects referenced enums, and adds appropriate imports (local or external viapackage).- Parameters:
schemaName- current schema namevariableProperties- field to configurecurrentSchema- current schema mapschemas- global schema registrypropertyName- YAML keypropertiesMap- field definition (must contain$ref)processContext- generation contextinnerSchemas- accumulator
-
fillArrayProperties
protected void fillArrayProperties(String schemaName, VariableProperties variableProperties, Map<String, Object> currentSchema, Map<String, Object> schemas, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Processes array-type fields and configures collection type, element type, and realization.Special case: structurally empty
items(notype,$ref,properties) defaults toList<Object>.- Parameters:
schemaName- current schema namevariableProperties- field containercurrentSchema- current schema mapschemas- global schemaspropertyName- YAML keypropertiesMap- field definitionprocessContext- generation contextinnerSchemas- accumulator
-
fillCollectionWithExistingObject
protected static void fillCollectionWithExistingObject(VariableProperties variableProperties, Map<String, Object> items) Configures collection realization and import forformat: existingarrays.- Parameters:
variableProperties- field containeritems-itemsmap from YAML
-
fillInnerSchema
protected void fillInnerSchema(VariableProperties variableProperties, String propertyName, Map<String, Object> propertiesMap, ProcessContext processContext, Map<String, Object> innerSchemas) Registers an inner schema for subsequent DTO generation.Normalizes the schema (ensures
type: objectand extracts actual properties) before registration.- Parameters:
variableProperties- field containerpropertyName- proposed inner schema namepropertiesMap- raw inner schema definitionprocessContext- contextinnerSchemas- accumulator
-
fillMessageFromChannel
public static void fillMessageFromChannel(Map<String, Object> allContent, Map<String, Object> messagesMap, Set<String> excludeSchemas, Map<String, Object> mapToMessage, String channelName, String channelType) PopulatesmessagesMapfrom AsyncAPI 2.xchannels/publish/subscribesections.Resolves payload definitions, extracts polymorphic payloads (e.g.,
oneOf) and creates synthetic message definitions when needed.- Parameters:
allContent- full AsyncAPI documentmessagesMap- output map (schema name → payload)excludeSchemas- set of schema names to exclude from DTO generationmapToMessage- channel operation map (e.g.,subscribeorpublish)channelName- channel keychannelType-"subscribe"or"publish"
-
fillCollectionType
Sets the final Java collection type string (e.g.,List<String>) based oncollectionType.- Parameters:
variableProperties- field container (must haveitemsset)
-
fillRequiredAnnotationsAndImports
public static void fillRequiredAnnotationsAndImports(VariableProperties variableProperties, Map<String, Object> currentSchema, String propertyName) Applies validation annotations and imports based onrequired, validation groups, and field type.Generates:
@NotNull/@NotBlank/@NotEmptyforrequiredfieldsgroups = {...}variants if validation groups are configured@Validfor nested objects (excluding collections/enums)
- Parameters:
variableProperties- field container (updated in-place)currentSchema- schema map (to readrequired,validationGroups, etc.)propertyName- field name (to check presence inrequired)
-
fillEnumSchema
protected static void fillEnumSchema(String enumSchemaName, Map<String, Object> propertiesMap, Map<String, Object> innerSchemas) Registers an enum schema ininnerSchemasbased on raw YAML definition.Delegates to
fillByEnumWithDescription(java.util.Map<java.lang.String, java.lang.Object>)orfillByEnum(java.util.List<java.lang.String>)depending on presence ofx-enumNames.- Parameters:
enumSchemaName- enum schema namepropertiesMap- raw enum definitioninnerSchemas- accumulator
-