Class AbstractMapper

java.lang.Object
ru.yojo.codegen.mapper.AbstractMapper
Direct Known Subclasses:
MessageMapper, SchemaMapper

public class AbstractMapper extends Object
Base class for schema and message mapping logic.

Provides reusable methods to:

  • Populate VariableProperties from raw YAML maps
  • Handle various field types: primitives, collections, maps, enums, polymorphic schemas, and references
  • Apply validation annotations and required imports based on required and 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.

  • 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)
      Parameters:
      schemaName - name of the containing schema (used for logging and inner schema naming)
      variableProperties - target field container to populate
      currentSchema - full schema map where this property is defined
      schemas - 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: existing for external classes
      • Polymorphic constructs (oneOf, allOf, anyOf)
      Parameters:
      schemaName - name of the containing schema
      variableProperties - field container to populate
      currentSchema - current schema map
      schemas - global schema registry
      propertyName - field name in YAML
      propertiesMap - raw field definition
      processContext - generation context
      innerSchemas - accumulator for inner schemas
    • fillMessageFromChannel

      public static void fillMessageFromChannel(Map<String,Object> allContent, Map<String,Object> messagesMap, Set<String> excludeSchemas, Map<String,Object> mapToMessage, String channelName, String channelType)
      Populates messagesMap from AsyncAPI 2.x channels/publish/subscribe sections.

      Resolves payload definitions, extracts polymorphic payloads (e.g., oneOf) and creates synthetic message definitions when needed.

      Parameters:
      allContent - full AsyncAPI document
      messagesMap - output map (schema name → payload)
      excludeSchemas - set of schema names to exclude from DTO generation
      mapToMessage - channel operation map (e.g., subscribe or publish)
      channelName - channel key
      channelType - "subscribe" or "publish"
    • fillRequiredAnnotationsAndImports

      public static void fillRequiredAnnotationsAndImports(VariableProperties variableProperties, Map<String,Object> currentSchema, String propertyName)
      Applies validation annotations and imports based on required, validation groups, and field type.

      Generates:

      • @NotNull/@NotBlank/@NotEmpty for required fields
      • groups = {...} variants if validation groups are configured
      • @Valid for nested objects (excluding collections/enums)
      Parameters:
      variableProperties - field container (updated in-place)
      currentSchema - schema map (to read required, validationGroups, etc.)
      propertyName - field name (to check presence in required)