V3 FluentBuilder validation failed when an operation references a component message
- Dominant language
- C#
- Stars
- 88
- Forks
- 17
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 2
Description
### I tried this:
I tried to build an AsyncAPI v3 document using the FluentBuilder API where an operation references a message.
Minimal reproducible example (reduced from the README):
```csharp
[Fact]
public void Validate_FluentBuilder_Should_Valid()
{
var channelParameterSchema = new JsonSchemaBuilder().FromType();
var builder = ServiceProvider.GetRequiredService();
var doc = builder
.WithTitle("Cloud Event API")
.WithVersion("1.0.0")
.WithServer("StreetLightsApi", server => server
.WithHost("https://streetlights.fake.com")
.WithProtocol(AsyncApiProtocol.Http, "2.0")
.WithBinding(new HttpServerBindingDefinition()))
.WithChannel("events", channel => channel
.WithServer("#/servers/StreetLightsApi")
.WithDescription("The endpoint used to publish and subscribe to cloud events")
.WithBinding(new HttpChannelBindingDefinition())
.WithMessage("lightMeasuredEvent", definitionBuilder => { }))
.WithOperation("observeCloudEvents", operation => operation
.WithAction(V3OperationAction.Send)
.WithChannel("#/channels/events")
.WithTitle("ObserveCloudEvents")
.WithDescription("Observes cloud events published by the StreetLightsApi")
.WithBinding(new HttpOperationBindingDefinition
{
Method = HttpMethod.POST,
Type = HttpBindingOperationType.Response
})
.WithMessage("#/components/messages/lightMeasuredEvent"))
.WithMessageComponent("lightMeasuredEvent", message => message
.WithName("LightMeasuredEvent")
.WithDescription("The event fired whenever the luminosity of a light has been measured")
.WithContentType("application/json"))
.Build();
}
```
### This happened:
`Build()` throws a `FluentValidation.ValidationException`:
```
Validation failed:
-- Operations.Values[0].Messages[0]:
The operation must reference a message defined by the channel it belongs to
```
### I expected this:
_No response_
### Is there a workaround?
_No response_
### Anything else?
Root cause analysis:
- `V3OperationMessageValidator ` enforces that operation messages must reference channel messages only
- During validation, `DereferenceChannelMessage(...)` is called with a reference like
`#/components/messages/lightMeasuredEvent`
- This method explicitly rejects non-channel references and throws an `InvalidDataException`, which causes the validator to fail
### Platform(s)
Windows
### Community Notes
* Please vote by adding a 👍 reaction to the issue to help us prioritize.
* If you are interested to work on this issue, please leave a comment.name: Bug Report 🐞
Contributor guide
Assessment
This issue has not been assessed yet.