Skip to content

1.3.1

Choose a tag to compare

@Traqueur-dev Traqueur-dev released this 20 Oct 19:56
· 13 commits to main since this release
abfd268

๐Ÿ”ง Structura v1.3.1 โ€“ Fully Inline Polymorphic Fields

Complete field flattening for polymorphic interfaces.

โœจ New Feature

๐ŸŽฏ Fully Inline Polymorphic Fields

Combine @Options(inline = true) with @Polymorphic(inline = true) to flatten all fields (discriminator + implementation fields) to parent level.

@Polymorphic(key = "type", inline = true)
public interface DatabaseConfig extends Loadable {}

public record AppConfig(
    String appName,
    @Options(inline = true) DatabaseConfig database  // FULLY inline
) implements Loadable {}

YAML - Before v1.3.1:

app-name: MyApp
type: mysql        # Discriminator at parent (v1.3.0)
database:          # Fields still nested
  host: localhost
  port: 3306

YAML - After v1.3.1:

app-name: MyApp
type: mysql        # Everything at parent level
host: localhost
port: 3306

๐Ÿ”ง Implementation

RecordInstanceFactory Changes:

  • New method: enrichParentDataWithDiscriminator() - Validates discriminator presence and prepares data for polymorphic resolution
  • Enhanced: isInlineField() - Now detects polymorphic interfaces with @Polymorphic(inline = true)
  • Enhanced: resolveComponentValue() - Handles both concrete records and polymorphic interfaces separately

๐ŸŽฎ Use Cases

Simple Configuration:

app-name: MyApp
type: mysql
host: db.example.com
port: 3307

Custom Discriminator Key:

app-name: MyApp
provider: s3
bucket: my-data
region: us-west-2

Mixed Inline/Nested:

app-name: MyApp
type: mysql          # database (fully inline)
host: db.local
cache:               # cache (traditional nested)
  type: redis
  host: cache.local

๐Ÿงช Testing

  • New test suite: FullyInlinePolymorphicTest (+205 lines, 8 tests)
  • Tests cover: full flattening, multiple types, custom keys, defaults, mixed configs, error scenarios

๐Ÿ“‹ Migration Guide

No Breaking Changes - This is an opt-in enhancement.

To adopt:

// Add @Options(inline = true) to your polymorphic field
public record Config(
    @Options(inline = true) DatabaseConfig database  // Add this annotation
) implements Loadable {}

๐Ÿ“Š Comparison

Mode Discriminator Fields Flags Required
Traditional Inside field Inside field None
Inline Discriminator Parent level Inside field @Polymorphic(inline=true)
Fully Inline โœจ Parent level Parent level @Polymorphic(inline=true) + @Options(inline=true)

๐ŸŽฏ Best Practices

โœ… Use when:

  • Simple polymorphic configurations
  • Maximum YAML readability needed
  • No field name conflicts between inline fields

โŒ Avoid when:

  • Multiple inline polymorphic fields share field names
  • Complex implementations with many fields
  • Need clear visual separation

๐Ÿ“ Version

1.3.0 โ†’ 1.3.1

Full Changelog: 1.3.0...1.3.1