Skip to content

Latest commit

 

History

History
75 lines (63 loc) · 4.07 KB

File metadata and controls

75 lines (63 loc) · 4.07 KB

AsyncAPI and JsonSchema2Pojo (with maven plugin)

👉 ZenWave360 Helps You Create Software Easy to Understand

Maven Central GitHub

Generate Plain Old Java Objects from OpenAPI/AsyncAPI schemas or full JSON-Schema files using https://www.jsonschema2pojo.org/ library.

jbang zw -p io.zenwave360.sdk.plugins.AsyncApiJsonSchema2PojoPlugin \
    specFile=src/main/resources/model/asyncapi.yml \
    modelPackage=io.zenwave360.example.core.domain.events \
    jsonschema2pojo.includeTypeInfo=true \
    targetFolder=.

Options

Option Description Type Default Values
specFile API Specification File String
targetFolder Target folder to generate code to. File
modelPackage Java Models package name String
jsonschema2pojo JsonSchema2Pojo settings Map {}
messageNames Message names to include in code generation (combined with operationIds). Generates code for ALL if left empty List []
bindingTypes Binding names to include in code generation. Generates code for ALL bindings if left empty List
operationIds Operation ids to include in code generation. Generates code for ALL if left empty List []

Getting Help

jbang zw -p io.zenwave360.sdk.plugins.AsyncApiJsonSchema2PojoPlugin --help

Maven Plugin Configuration (API-First)

You can use ZenWave Maven Plugin to generate code as part of your build process:

  • Adding this generator jar as dependency to zenwave maven plugin.
  • Passing any configuration as .

Use jsonschema2pojo prefix to pass any option to https://www.jsonschema2pojo.org/ underlying library.

<plugin>
    <groupId>io.github.zenwave360.zenwave-sdk</groupId>
    <artifactId>zenwave-sdk-maven-plugin</artifactId>
    <version>${zenwave.version}</version>
    <executions>
        <execution>
            <id>generate-asyncapi-producer</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <generatorName>jsonschema2pojo</generatorName>
                <inputSpec>${pom.basedir}/src/main/resources/model/asyncapi.yml</inputSpec>
                <configOptions>
                    <modelPackage>io.zenwave360.example.adapters.events.model</modelPackage>
                    <!-- use jsonschema2pojo prefix to pass any option to jsonschema2pojo underlying library -->
                    <jsonschema2pojo.includeTypeInfo>true</jsonschema2pojo.includeTypeInfo>
                </configOptions>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>io.github.zenwave360.zenwave-sdk.plugins</groupId>
            <artifactId>asyncapi-jsonschema2pojo</artifactId>
            <version>${zenwave.version}</version>
        </dependency>
    </dependencies>
</plugin>