Skip to content

Commit b2a1c0c

Browse files
bieluclaude
andcommitted
test: cover 3.x message trait headers
Adds 3.x counterparts to the 2.x message trait tests, so the change to the 3.x writer is shown not to regress: a trait without headers, a trait with headers, and a 2.x trait with schemaFormat but no headers upgraded to 3.x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7d0d3b5 commit b2a1c0c

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎test/ByteBard.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,63 @@ public void V2_AsyncApiMessageTrait_WithSchemaFormatAndNoHeaders_Deserializes()
133133
trait.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0).Should().BePlatformAgnosticEquivalentTo(input);
134134
}
135135

136+
[Test]
137+
public void V3_AsyncApiMessageTrait_WithoutHeaders_Serializes()
138+
{
139+
var expected =
140+
"""
141+
name: TraitName
142+
""";
143+
144+
var trait = new AsyncApiMessageTrait { Name = "TraitName" };
145+
146+
var actual = trait.SerializeAsYaml(AsyncApiVersion.AsyncApi3_0);
147+
148+
actual.Should().BePlatformAgnosticEquivalentTo(expected);
149+
}
150+
151+
[Test]
152+
public void V3_AsyncApiMessageTrait_WithHeaders_Reserializes()
153+
{
154+
var input =
155+
"""
156+
headers:
157+
type: object
158+
name: TraitName
159+
""";
160+
161+
// The 3.x reader fills in the default schema format, so the headers come back in the explicit multi-format form.
162+
var expected =
163+
"""
164+
headers:
165+
schemaFormat: application/vnd.aai.asyncapi+json;version=3.0.0
166+
schema:
167+
type: object
168+
name: TraitName
169+
""";
170+
171+
var trait = new AsyncApiStringReader().ReadFragment<AsyncApiMessageTrait>(input, AsyncApiVersion.AsyncApi3_0, out var diagnostic);
172+
173+
diagnostic.Errors.Should().BeEmpty();
174+
trait.Headers.Schema.Should().BeOfType<AsyncApiJsonSchema>();
175+
trait.SerializeAsYaml(AsyncApiVersion.AsyncApi3_0).Should().BePlatformAgnosticEquivalentTo(expected);
176+
}
177+
178+
[Test]
179+
public void V2_AsyncApiMessageTrait_WithSchemaFormatAndNoHeaders_UpgradesToV3WithoutHeaders()
180+
{
181+
var input =
182+
"""
183+
schemaFormat: application/vnd.aai.asyncapi+json;version=2.6.0
184+
name: TraitName
185+
""";
186+
187+
var trait = new AsyncApiStringReader().ReadFragment<AsyncApiMessageTrait>(input, AsyncApiVersion.AsyncApi2_0, out var diagnostic);
188+
189+
diagnostic.Errors.Should().BeEmpty();
190+
trait.SerializeAsYaml(AsyncApiVersion.AsyncApi3_0).Should().BePlatformAgnosticEquivalentTo("name: TraitName");
191+
}
192+
136193
[Test]
137194
public void V2_AsyncApiMessage_WithNoSchemaFormat_DoesNotSerializeSchemaFormat()
138195
{

0 commit comments

Comments
 (0)