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

varsettings=newAsyncApiReaderSettings();settings.RuleSet.Add(newValidationRule<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.0info:
title: testversion: 1.0.0license:
name: apachecontact: name: API Supporturl: https://www.example.com/supportemail: support@example.com

Diagnostics will contain the following error message.

Clone this wiki locally