Skip to content

Commit 82374ed

Browse files
authored
Add Identifiable conformance to PartiallyGenerated struct in GenerableMacro (#73)
* Add Identifiable conformance to `PartiallyGenerated` struct in `GenerableMacro` * Add generation ID to GeneratedContent initialization in tests
1 parent f171982 commit 82374ed

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Sources/AnyLanguageModelMacros/GenerableMacro.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,15 @@ public struct GenerableMacro: MemberMacro, ExtensionMacro {
690690

691691
return DeclSyntax(
692692
stringLiteral: """
693-
public struct PartiallyGenerated: Sendable, ConvertibleFromGeneratedContent {
693+
public struct PartiallyGenerated: Identifiable, Sendable, ConvertibleFromGeneratedContent {
694+
public var id: GenerationID
695+
694696
\(optionalProperties)
695697
696698
private let rawContent: GeneratedContent
697699
698700
public init(_ generatedContent: GeneratedContent) throws {
701+
self.id = generatedContent.id ?? GenerationID()
699702
self.rawContent = generatedContent
700703
701704
if \(properties.isEmpty ? "case .structure = generatedContent.kind" : "case .structure(let properties, _) = generatedContent.kind") {

Tests/AnyLanguageModelTests/GenerableMacroTests.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,18 @@ struct GenerableMacroTests {
126126

127127
@Test("Create instance from GeneratedContent")
128128
func fromGeneratedContent() throws {
129-
let content = GeneratedContent(properties: [
130-
"name": GeneratedContent("Bob"),
131-
"age": GeneratedContent(kind: .number(25)),
132-
])
129+
let generationID = GenerationID()
130+
let content = GeneratedContent(
131+
properties: [
132+
"name": GeneratedContent("Bob"),
133+
"age": GeneratedContent(kind: .number(25)),
134+
],
135+
id: generationID
136+
)
133137

134138
let args = try TestArguments(content)
135139
#expect(args.name == "Bob")
136140
#expect(args.age == 25)
141+
#expect(args.asPartiallyGenerated().id == generationID)
137142
}
138143
}

0 commit comments

Comments
 (0)