Skip to content

Validation Rules

Alex Wichmann edited this page Jun 11, 2025 · 1 revision

Validation Rules

Validation Rules can be added, to validate parts of the specification during reading, any errors/warnings will be pushed to the Diagnostics output of the reader.

as an example we could have the following validation rule for a License

var settings = new AsyncApiReaderSettings();
settings.RuleSet.Add(new ValidationRule<AsyncApiLicense>((context, item) =>
{
    context.Enter("name");
    if (item != null && item.Name != "MIT")
    {
        context.CreateError("license", "License MUST be MIT");
    }
    context.Exit();
})); 

Given the following AsyncApi specification

asyncapi: 2.6.0
info:
  title: test
  version: 1.0.0
  license:
    name: apache
  contact:  
    name: API Support
    url: https://www.example.com/support
    email: support@example.com

Diagnostics will contain the following error message.

Clone this wiki locally