cloudevents / cloudevents/sdk-csharp
Allow users to signal whether extensions are required
@jskeet is already working on this.
Since May 8, 2025.
- Dominant language
- C#
- Stars
- 334
- Forks
- 88
- Avg merge
- 7m
- Merged PRs (30d)
- 2
Description
Use case: From a producer-perspective, I want to avoid poison messages being produced due to missing attributes that are required in the system (either by intermediaries or consumers). This should be handled as a cross-cutting concern, to avoid gaps.
Currently, the SDK allows extensions to be created, and it allows users to provide a validator to execute.
The validator method can be used to ensure the type, structure, or even combination of extensions that should be set, providing full validation of the extension. However, it doesn't allow users to indicate that it is a required extension.
Taking the example of a tenant attribute that is required within the system's boundaries, I could register the attribute as follows:
var tenantIdAttribute =
CloudEventAttribute.CreateExtension("tenant", CloudEventAttributeType.String, tenantValue =>
{
if (tenantValue is not string tenant) throw new ArgumentException("tenant attribute must be of type string");
if (string.IsNullOrWhiteSpace(tenant))
throw new ArgumentException("tenant attribute must not be null, empty or whitespace");
});
However, the validation only runs if the attribute is actually set, but from a user's perspective, the ability to indicate this as a required extension is equally important. Currently, the SDK allows me to tackle extension validation as a cross-cutting concern by providing a validation method to the SDK, however, it currently neglects what may be most essential to many users, verifying that the attribute is actually there.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.