Package ru.yojo.codegen.mapper
Class AbstractMapper
java.lang.Object
ru.yojo.codegen.mapper.AbstractMapper
- Direct Known Subclasses:
MessageMapper,SchemaMapper
Base class for schema and message mapping logic.
Responsible for:
- Populating
VariablePropertiesfrom YAML property definitions - Resolving
$ref, polymorphism (oneOf/allOf), collections, maps, enums - Inferring Java types, validation annotations, and required imports
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidfillMessageFromChannel(Map<String, Object> allContent, Map<String, Object> messagesMap, Set<String> excludeSchemas, Map<String, Object> mapToMessage, String channelName, String channelType) Extracts message definitions from AsyncAPI 2.0channels/publish/subscribe.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 single property definition in a schema.static voidfillRequiredAnnotationsAndImports(VariableProperties variableProperties, Map<String, Object> currentSchema, String propertyName) Adds validation annotations and imports based onrequiredlist 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 Java type and metadata for a property, based on its definition.
-
Constructor Details
-
AbstractMapper
public AbstractMapper()
-
-
Method Details
-
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 single property definition in a schema.Handles:
- Basic metadata: name, description, example, default
- Validation: min/max length/size, pattern, digits, min/max value
- Type/format inference (
string,date,uuid, etc.) - Polymorphism detection (
oneOf,allOf,anyOf) - Delegation 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>)for type resolution - Required annotations/imports for validation
- Parameters:
schemaName- name of the containing schema (for diagnostics)variableProperties- target to populatecurrentSchema- full current schema map (used forrequiredlookup)schemas- global schemas map (for$refresolution)propertyName- raw property name from YAMLpropertiesMap- property definition map (e.g.,{ type: string, format: email })processContext- current generation contextinnerSchemas- accumulator for generated inner schemas (e.g., enums, inner DTOs)
-
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 Java type and metadata for a property, based on its definition.Dispatches to specialized handlers for:
- Empty property →
Object formatoverride fortype: object(e.g.,uuid,date)- Arrays/collections
$refreferences- Inner objects (with
properties) - Enums
- Existing classes (
format: existing) - Maps (
additionalProperties) - Polymorphic types
- Parameters:
schemaName- schema name (for diagnostics)variableProperties- target to populatecurrentSchema- current schema mapschemas- global schemas mappropertyName- property namepropertiesMap- property definitionprocessContext- generation contextinnerSchemas- inner schema accumulator
- Empty property →
-
fillMessageFromChannel
public static void fillMessageFromChannel(Map<String, Object> allContent, Map<String, Object> messagesMap, Set<String> excludeSchemas, Map<String, Object> mapToMessage, String channelName, String channelType) Extracts message definitions from AsyncAPI 2.0channels/publish/subscribe.- Parameters:
allContent- full spec documentmessagesMap- output map to populateexcludeSchemas- schemas to preserve (for polymorphic cases)mapToMessage- channel message mapchannelName- channel namechannelType-"publish"or"subscribe"
-
fillRequiredAnnotationsAndImports
public static void fillRequiredAnnotationsAndImports(VariableProperties variableProperties, Map<String, Object> currentSchema, String propertyName) Adds validation annotations and imports based onrequiredlist and field type.Supports:
- Basic:
@NotNull,@NotBlank,@NotEmpty - Validation groups (
groups = {...}) jakartavsjavaxpackages (via Spring Boot version)
- Parameters:
variableProperties- field metadatacurrentSchema- schema containingrequiredlistpropertyName- field name
- Basic:
-