AsyncAPI 3.x: publish a message's example, some of the time - #1754
Draft
LautaroPetaccio wants to merge 1 commit into
Draft
AsyncAPI 3.x: publish a message's example, some of the time#1754LautaroPetaccio wants to merge 1 commit into
LautaroPetaccio wants to merge 1 commit into
Conversation
A document's message examples are what its author knows the service accepts. A service that silently drops what it does not recognise may never answer a sampled payload, so with --probAsyncApiExamples the first example of a message is offered as a whole value beside the schema-derived genes, at that probability. Off by default, like every new feature. It reuses what REST already does with a schema's 'example': the example is put on the message's own copy of the payload schema, and the gene builder turns it into the same choice it offers REST. Only the first example is used: the OpenAPI parser the genes go through reads the schemas as 3.0, which drops the plural 'examples'. Scalars are left alone, as the builder would complain about 'example' on them. A headers example loses the field the correlation id is stamped into, as the headers gene did before it.
LautaroPetaccio
added this pull request to stack #1712
September 13, 2026 21:33
LautaroPetaccio
marked this pull request as ready for review
September 13, 2026 21:34
LautaroPetaccio
marked this pull request as draft
September 13, 2026 21:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thirteenth in the AsyncAPI stack, on top of #1753. Draft, like the two below it.
Why
A message's
examplesare what the document's author knows the service accepts. A service that silently drops what it does not recognise — the normal behaviour of a Kafka consumer or a WebSocket handler faced with a malformed message — may never reply to a payload sampled from the schema alone, and a search that never sees a reply never gets to tell the reply variants apart. Publishing the author's example some of the time is the cheapest way to make sure the search starts from something that works.What it does
With
--probAsyncApiExamples p(@Experimental,@Probability, 0 by default), the first example of a message is offered as a whole value beside the schema-derived genes, chosen with probabilitypwhen the message is sampled. Same for a headers example, minus the field the correlation id is stamped into, which the headers gene does not have either.How — no new machinery
REST already turns a schema's
exampleinto aChoiceGenebetween the example and the schema-derived genes, atprobUseExamples. So the example is put on the message's own copy of the payload schema before it goes toRestActionBuilderV3.createGeneForDTO, and that machinery does the rest. Ten lines inAsyncApiGeneBuilder, one line inoptions().Two limits, both stated in the code:
exampleson a 3.0 schema — checked empirically, not assumed; the singularexamplesurvives. A TODO says where to pass them all once the builder can take them. In the corpus, every message with examples has exactly one.exampleon a non-object schema, and that would reach the user as a complaint about a document that is in order.The
TODOthis resolves inAsyncApiSampleris removed.Testing
AsyncApiGeneBuilderTest(+5): the ScalarPlanetCreatedexample published whole when asked for every time; nothing changing shape when not asked; a scalar payload left alone; a headers example losing the correlation field; only the first of two examples used.AsyncApiSamplerTest(+1): through the sampler with--probAsyncApiExamples=1.0, the payload of a sampled action is the author's example.All AsyncAPI suites plus the config ones: 199 tests, 0 failures.