Repository navigation
feat: AsyncAPI 3.0 and 3.1 support - #1316
Merged
Merged
Conversation
- New boat:generate-spring-cloud-stream-embedded goal (boat-spring-cloud-stream generator): Spring Cloud Stream handlers, functions and StreamBridge publishers per AsyncAPI operation. - boat:generate accepts AsyncAPI documents with any generator (models only for others). - boat:validate validates AsyncAPI 3.0 documents; boat:bundle bundles them, with a projectionOpenApiVersion parameter matching boat:generate. - JSON Schema draft-04 to 2020-12 payloads, inline or as Multi Format Schema Objects under components/schemas. - Fix: bundling OpenAPI 3.1 resolves external refs under oneOf, items, not, if/then and the other JSON Schema keywords, and in nested discriminator mappings. - Fix: deduplicateSchemas rewrites discriminator mappings of merged schemas. Co-authored-by: Cursor <cursoragent@cursor.com>
…i/specs WebJar boat-engine unpacks schemas/3.0.0-without-$id.json from org.webjars.npm:asyncapi__specs at build time instead of committing a copy. Co-authored-by: Cursor <cursoragent@cursor.com>
Documents declaring asyncapi 3.1.x are loaded like 3.0.x and validated against the official 3.1.0 JSON Schema; both schemas are unpacked from the @asyncapi/specs WebJar. The AsyncAPI 3.1.0 schema formats are accepted for payloads and headers. Co-authored-by: Cursor <cursoragent@cursor.com>
…annel extensions Adds a CloudEvents fixture with two channels, untagged send and receive operations, schemas shared across events and x-producers/x-consumers on each channel. Covers validation, bundling, projection and Spring Cloud Stream generation. Co-authored-by: Cursor <cursoragent@cursor.com>
checkResponseExampleFulfill force-unwrapped properties and items.properties, so object/array schemas without a properties block crashed the lint with a NullPointerException. Treat missing properties as nothing to check, and add regression tests for object and array-of-object schemas. Co-authored-by: Cursor <cursoragent@cursor.com>
|
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.



Summary
Adds AsyncAPI 3.0 and 3.1 support to BOAT, so a service can keep its event contracts next to its REST specs and generate Spring Cloud Stream code from them. See the new AsyncAPI 3.0 and 3.1 section of the plugin README and the 0.19.0 release notes.
An AsyncAPI document is loaded, validated and projected onto an OpenAPI document with one operation per AsyncAPI operation and message. BOAT then bundles and de-duplicates it as usual, so OpenAPI and AsyncAPI documents that share schema files produce the same model classes.
Goals
boat:generate-spring-cloud-stream-embedded(generatorboat-spring-cloud-stream): generates{Tag}Handlerinterfaces,{Tag}FunctionsConfigurationwithConsumer/Functionbeans and{Tag}Publisherclasses onStreamBridge(grouped by operation tag, or by channel when untagged), plus anasyncapi-bindings.propertieswith the binding destinations. Whether code is generated for the producing or the consuming side follows each operation'saction;inverseOperationsgenerates the other side.boat:generateaccepts AsyncAPI input with any generator. Other generators only generate the payload and header models.boat:validatechecks AsyncAPI documents against the official AsyncAPI JSON Schema of their version (3.0.0 or 3.1.0), plus reference and schema-format checks.boat:bundlebundles an AsyncAPI document into a single file with de-duplicatedcomponents/schemas. Its newprojectionOpenApiVersionparameter matches the one onboat:generate.boat:lint,boat:docandboat:diffskip AsyncAPI documents found in directories;boat:shipships them as is.AsyncAPI 3.1
asyncapi: 3.1.xload like 3.0.x. 3.1 adds ROS 2 bindings and the AsyncAPIversion=3.1.0schema formats; neither changes what is generated.boat:validatepicks the official schema by document version, so a ROS 2 binding passes in a 3.1 document and fails in a 3.0 one.Schemas
components/schemas, where the component key names the model.projectionOpenApiVersion(default3.0.3) sets the OpenAPI version of the projection. Use3.1.0for 2019-09/2020-12 schemas and keywords such asconstandif/then. Warnings name the schemas a given version cannot express; referenced schema files are checked too.Fixes in existing code
allOf/oneOf/itemsrefs only forComposedSchema/ArraySchema, but OpenAPI 3.1 schemas are parsed asJsonSchema. External refs under those and the other JSON Schema keywords stayed relative to their own file, and so did nested discriminator mappings.OpenApi31SchemaRefsrebases them whenBoatCacheloads a schema, and resolves the leftovers to components after the parser has finished.DeduplicateSchemasTransformer: now also rewrites discriminator mappings that pointed at a merged duplicate.Review notes
boat-engineunpacksschemas/3.0.0-without-$id.jsonandschemas/3.1.0-without-$id.jsonfrom theorg.webjars.npm:asyncapi__specsWebJar (asyncapi-specs.version, 6.11.1) intotarget/classesduringgenerate-resources. The WebJar is not a runtime dependency.com.networknt:json-schema-validator1.5.9 inboat-engine, used only for that schema check.MavenProjectCompiler(scaffold test helper) is now public and reads the settings file from theMavenProjectCompiler.settingssystem property, so the scaffold and codegen tests run outside GitHub Actions.boat-maven-plugin/src/it/example/boat-generate/asyncapi/cover inline schemas, and schemas reused between OpenAPI and AsyncAPI.Test plan
mvn -B -Dgpg.skip -pl boat-engine,boat-scaffold,boat-maven-plugin -am verifyincluding invoker ITs (local)AsyncApiLoaderTest#loadsAsyncApi31,AsyncApiValidatorTest#validatesAgainstTheSchemaOfTheDocumentVersion,BundlerTests#bundlesTheReferencesOfOpenApi31Schemas(fails without the 3.1 fix),DeduplicateSchemasTransformerTests#rewritesDiscriminatorMappingsOfMergedSchemas,AsyncApiMojoTests#bundlesAsyncApiOntoTheProjectionOpenApiVersion, and the AsyncAPI loader/validator/projector/bundler/codegen suites