Skip to content

Generate CodingKeys enum in @Entity macro - #39

Merged
colemancda merged 3 commits into
masterfrom
feature/coding-keys-macro
Aug 25, 2026
Merged

Generate CodingKeys enum in @Entity macro#39
colemancda merged 3 commits into
masterfrom
feature/coding-keys-macro

Conversation

@colemancda

Copy link
Copy Markdown
Member

Summary

  • @Entity now generates a public enum CodingKeys: String, CodingKey, Sendable, CaseIterable with a case for id plus every @Attribute/@CompositeAttribute/@Relationship property, in declaration order.
  • Backwards compatible: if the type already declares a CodingKeys enum (or typealias), the macro skips generation and the manual declaration is used.
  • The String raw type keeps the generated enum compatible with Embedded Swift, where CodingKey synthesis without a raw type is unavailable.

Limitation

When entity A's @Relationship(inverse: .foo) references entity B's keys, the compiler must type-check .foo against B.CodingKeys while macros are still expanding, and it will not expand @Entity's generated enum to satisfy another macro's argument. Entities referenced as a relationship destination therefore still need a manual CodingKeys; this is documented in the test model.

Testing

  • New macro tests: generated enum shape and case order, and that a manual CodingKeys suppresses generation.
  • Facility in the test model now relies on the generated enum, confirming Codable synthesis picks it up.
  • Full suite passes: 255 tests in 27 suites.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Swift

Swift / code-coverage/llvm-cov

The overall line coverage in commit c6f4b47 in the feature/coding-keys-... branch remains at 96%, unchanged from commit e43de80 in the master branch.

Show a line coverage summary of the most impacted files.
File master e43de80 feature/coding-keys-... c6f4b47 +/-
Sources/CoreMod...os/Entity.swift 100% 99% -1%

@colemancda
colemancda merged commit 456c3e1 into master Aug 25, 2026
32 checks passed
@colemancda
colemancda deleted the feature/coding-keys-macro branch August 25, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant