forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f21e8e7
commit 2cd605a
Showing
14 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Integrate Modelina into Maven | ||
|
||
This example show how you can integrate Modelina into Maven with a custom build script. [Please have a look at the Maven project README file for further information](./maven-project/). |
25 changes: 25 additions & 0 deletions
25
examples/integrate-modelina-into-maven/maven-project/.gitignore
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Eclipse m2e generated files | ||
# Eclipse Core | ||
.project | ||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
|
||
bin | ||
.settings | ||
|
||
# Ignore Modelina generation node modules | ||
scripts/modelina/java_runtime_node | ||
scripts/modelina/node_modules |
10 changes: 10 additions & 0 deletions
10
examples/integrate-modelina-into-maven/maven-project/README.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Integrate Modelina into Maven | ||
|
||
This Java Maven project shows an example how to integrate Modelina and AsyncAPI into your build process. | ||
|
||
Here is how it works: | ||
- The script `./scripts/modelina/generate.ts` is what generates all the models, and what Maven uses to generate the models. This can also be executed manually through `npm run generate`. | ||
- The input, in this case, is an AsyncAPI document located in the root of the project `./asyncapi.json`. The input can be anything, just alter the generator script. | ||
- The Maven project file `./pom.xml` then utilizes the [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin) to execute the generate script on build so you will always have the up to date models from your AsyncAPI document. | ||
|
||
> NOTICE: The only thing you manually have to change for this to work in your project is the dependency entry for `"@asyncapi/modelina": "file:../../../../",` in the `./scripts/modelina/package.json` file to use the latest Modelina version (we only use a local one for testing purposes). |
26 changes: 26 additions & 0 deletions
26
examples/integrate-modelina-into-maven/maven-project/asyncapi.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"asyncapi": "2.2.0", | ||
"info": { | ||
"title": "example", | ||
"version": "0.1.0" | ||
}, | ||
"channels": { | ||
"/test": { | ||
"subscribe": { | ||
"message": { | ||
"payload": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"email": { | ||
"type": "string", | ||
"format": "email" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
examples/integrate-modelina-into-maven/maven-project/pom.xml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.mycompany.app</groupId> | ||
<artifactId>maven-project</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>maven-project</name> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.15.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.15.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all --> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.eirslett</groupId> | ||
<artifactId>frontend-maven-plugin</artifactId> | ||
<version>1.12.1</version> | ||
<configuration> | ||
<workingDirectory>./scripts/modelina</workingDirectory> | ||
<installDirectory>java_runtime_node</installDirectory> | ||
</configuration> | ||
<executions> | ||
<!-- It will install nodejs and npm --> | ||
<execution> | ||
<id>install node and npm</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>install-node-and-npm</goal> | ||
</goals> | ||
<configuration> | ||
<nodeVersion>v18.15.0</nodeVersion> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>Generate sources</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>npm</goal> | ||
</goals> | ||
<configuration> | ||
<arguments>run generate</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
examples/integrate-modelina-into-maven/maven-project/scripts/modelina/generate.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { JAVA_JACKSON_PRESET, JavaFileGenerator } from '@asyncapi/modelina'; | ||
import path from 'path'; | ||
|
||
// Where should the models be placed relative to root maven project? | ||
const PACKAGE_NAME = 'java/com/mycompany/app'; | ||
const MODEL_DIR = `src/main/${PACKAGE_NAME}`; | ||
|
||
const FINAL_OUTPUT_PATH = path.resolve(__dirname, '../../', MODEL_DIR); | ||
// Setup the generator and all it's configurations | ||
const generator = new JavaFileGenerator({ | ||
presets: [JAVA_JACKSON_PRESET] | ||
}); | ||
|
||
// Load the input from file, memory, or remotely. | ||
// Here we just use a local AsyncAPI file | ||
import INPUT from '../../asyncapi.json'; | ||
const input = INPUT; | ||
|
||
// Generate all the files | ||
generator.generateToFiles( | ||
input, | ||
FINAL_OUTPUT_PATH, | ||
{ | ||
packageName: 'java/com/mycompany/app' | ||
} | ||
); |
10 changes: 10 additions & 0 deletions
10
examples/integrate-modelina-into-maven/maven-project/scripts/modelina/package.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"dependencies": { | ||
"@asyncapi/modelina": "file:../../../../", | ||
"ts-node": "^10.3.0" | ||
}, | ||
"scripts": { | ||
"generate": "./node_modules/.bin/ts-node ./generate.ts", | ||
"generate:windows": "..\\node_modules\\.bin\\ts-node .%\\generate.ts" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...te-modelina-into-maven/maven-project/src/main/java/com/mycompany/app/generic/Address.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.mycompany.app.generic; | ||
import com.mycompany.app.generic.NestedObject; | ||
import java.util.Map; | ||
import com.fasterxml.jackson.annotation.*; | ||
public class Address { | ||
@JsonProperty("street_name") | ||
private String streetName; | ||
@JsonProperty("house_number") | ||
private Double houseNumber; | ||
@JsonProperty("marriage") | ||
private boolean marriage; | ||
@JsonProperty("members") | ||
private Object members; | ||
@JsonProperty("array_type") | ||
private Object[] arrayType; | ||
@JsonProperty("nestedObject") | ||
private NestedObject nestedObject; | ||
private Map<String, Object> additionalProperties; | ||
|
||
public String getStreetName() { return this.streetName; } | ||
public void setStreetName(String streetName) { this.streetName = streetName; } | ||
|
||
public Double getHouseNumber() { return this.houseNumber; } | ||
public void setHouseNumber(Double houseNumber) { this.houseNumber = houseNumber; } | ||
|
||
public boolean getMarriage() { return this.marriage; } | ||
public void setMarriage(boolean marriage) { this.marriage = marriage; } | ||
|
||
public Object getMembers() { return this.members; } | ||
public void setMembers(Object members) { this.members = members; } | ||
|
||
public Object[] getArrayType() { return this.arrayType; } | ||
public void setArrayType(Object[] arrayType) { this.arrayType = arrayType; } | ||
|
||
public NestedObject getNestedObject() { return this.nestedObject; } | ||
public void setNestedObject(NestedObject nestedObject) { this.nestedObject = nestedObject; } | ||
|
||
public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } | ||
public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; } | ||
} |
15 changes: 15 additions & 0 deletions
15
...delina-into-maven/maven-project/src/main/java/com/mycompany/app/generic/NestedObject.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.mycompany.app.generic; | ||
|
||
import java.util.Map; | ||
import com.fasterxml.jackson.annotation.*; | ||
public class NestedObject { | ||
@JsonProperty("test") | ||
private String test; | ||
private Map<String, Object> additionalProperties; | ||
|
||
public String getTest() { return this.test; } | ||
public void setTest(String test) { this.test = test; } | ||
|
||
public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } | ||
public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; } | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"config": { | ||
"example_name": "integrate-modelina-into-maven" | ||
}, | ||
"scripts": { | ||
"install": "(cd ../.. && npm i) && cd maven-project/scripts/modelina && npm i", | ||
"start": "cd ./examples/$npm_package_config_example_name/maven-project/scripts/modelina && npm run generate", | ||
"start:windows": "cd ./examples/%npm_package_config_example_name%/maven-project/scripts/modelina && npm run generate:windows", | ||
"test": "npm run start", | ||
"test:windows": "npm run start:windows" | ||
} | ||
} |
This file contains 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