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.

Responsible for:

  • Populating VariableProperties from YAML property definitions
  • Resolving $ref, polymorphism (oneOf/allOf), collections, maps, enums
  • Inferring Java types, validation annotations, and required imports
  • 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 a VariableProperties instance from a single property definition in a schema.

      Handles:

      Parameters:
      schemaName - name of the containing schema (for diagnostics)
      variableProperties - target to populate
      currentSchema - full current schema map (used for required lookup)
      schemas - global schemas map (for $ref resolution)
      propertyName - raw property name from YAML
      propertiesMap - property definition map (e.g., { type: string, format: email })
      processContext - current generation context
      innerSchemas - 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
      • format override for type: object (e.g., uuid, date)
      • Arrays/collections
      • $ref references
      • Inner objects (with properties)
      • Enums
      • Existing classes (format: existing)
      • Maps (additionalProperties)
      • Polymorphic types
      Parameters:
      schemaName - schema name (for diagnostics)
      variableProperties - target to populate
      currentSchema - current schema map
      schemas - global schemas map
      propertyName - property name
      propertiesMap - property definition
      processContext - generation context
      innerSchemas - inner schema 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)
      Extracts message definitions from AsyncAPI 2.0 channels/publish/subscribe.
      Parameters:
      allContent - full spec document
      messagesMap - output map to populate
      excludeSchemas - schemas to preserve (for polymorphic cases)
      mapToMessage - channel message map
      channelName - channel name
      channelType - "publish" or "subscribe"
    • fillRequiredAnnotationsAndImports

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

      Supports:

      • Basic: @NotNull, @NotBlank, @NotEmpty
      • Validation groups (groups = {...})
      • jakarta vs javax packages (via Spring Boot version)
      Parameters:
      variableProperties - field metadata
      currentSchema - schema containing required list
      propertyName - field name