-
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
8fd81c9
commit 544b364
Showing
6 changed files
with
276 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
asyncapi: "2.0.0" | ||
info: | ||
title: "Application API" | ||
version: "0.1.0" | ||
contact: | ||
name: "Fancy Team" | ||
url: "https://greenhalos.lu" | ||
email: "[email protected]" | ||
servers: | ||
test: | ||
url: "http://rabbitmq" | ||
protocol: "amqp" | ||
description: "RabbitMQ Server" | ||
channels: | ||
exchange/routing.key: | ||
description: "Description explaining exactly what happens here" | ||
subscribe: | ||
message: | ||
$ref: "#/components/messages/l.g.j.e.ExampleApplication$ExamplePublisherMessage" | ||
publish: | ||
message: | ||
$ref: "#/components/messages/l.g.j.e.ExampleApplication$ExampleListenerMessage" | ||
components: | ||
schemas: | ||
j.l.Integer-decfea64: | ||
examples: | ||
- 42 | ||
- 352 | ||
type: "integer" | ||
format: "int32" | ||
j.l.String-38af4fe9: | ||
examples: | ||
- "Lorem" | ||
- "ipsum" | ||
type: "string" | ||
j.l.String-931073f3: | ||
examples: | ||
- "EUR" | ||
- "USD" | ||
- "CHF" | ||
type: "string" | ||
j.m.BigDecimal-dbc8e12d: | ||
examples: | ||
- 42.42 | ||
- 352.01 | ||
type: "number" | ||
format: "float" | ||
l.g.j.e.ExampleApplication$ExampleListenerMessage: | ||
title: "ExampleListenerMessage" | ||
properties: | ||
amount: | ||
$ref: "#/components/schemas/j.m.BigDecimal-dbc8e12d" | ||
currency: | ||
$ref: "#/components/schemas/j.l.String-931073f3" | ||
id: | ||
$ref: "#/components/schemas/l.g.j.e.ExampleApplication$ObjectRepresentingAnId" | ||
l.g.j.e.ExampleApplication$ExamplePublisherMessage: | ||
title: "ExamplePublisherMessage" | ||
properties: | ||
amount: | ||
$ref: "#/components/schemas/j.m.BigDecimal-dbc8e12d" | ||
currency: | ||
$ref: "#/components/schemas/j.l.Integer-decfea64" | ||
l.g.j.e.ExampleApplication$ObjectRepresentingAnId: | ||
title: "ObjectRepresentingAnId" | ||
properties: | ||
value: | ||
$ref: "#/components/schemas/j.l.String-38af4fe9" | ||
messages: | ||
l.g.j.e.ExampleApplication$ExampleListenerMessage: | ||
payload: | ||
$ref: "#/components/schemas/l.g.j.e.ExampleApplication$ExampleListenerMessage" | ||
title: "ExampleListenerMessage" | ||
l.g.j.e.ExampleApplication$ExamplePublisherMessage: | ||
payload: | ||
$ref: "#/components/schemas/l.g.j.e.ExampleApplication$ExamplePublisherMessage" | ||
title: "ExamplePublisherMessage" | ||
description: "this is a message which gets published" |
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,58 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>j2asyncapi</artifactId> | ||
<groupId>lu.greenhalos</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>j2asyncapi-example</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>lu.greenhalos</groupId> | ||
<artifactId>j2asyncapi-annotation</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>lu.greenhalos</groupId> | ||
<artifactId>j2asyncapi-processor</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
57 changes: 57 additions & 0 deletions
57
j2asyncapi-example/src/main/java/lu/greenhalos/j2asyncapi/example/ExampleApplication.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,57 @@ | ||
package lu.greenhalos.j2asyncapi.example; | ||
|
||
import lu.greenhalos.j2asyncapi.annotations.AsyncApi; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static lu.greenhalos.j2asyncapi.annotations.AsyncApi.Type.LISTENER; | ||
import static lu.greenhalos.j2asyncapi.annotations.AsyncApi.Type.PUBLISHER; | ||
|
||
|
||
/** | ||
* @author Ben Antony - [email protected] | ||
*/ | ||
public class ExampleApplication { | ||
|
||
@AsyncApi( | ||
type = PUBLISHER, exchange = "exchange", routingKey = "routing.key", payload = ExamplePublisherMessage.class | ||
) | ||
public void publish() { | ||
|
||
System.out.println("publish the message ExampleListenerMessage"); | ||
} | ||
|
||
|
||
@AsyncApi( | ||
type = LISTENER, exchange = "exchange", routingKey = "routing.key", payload = ExampleListenerMessage.class, | ||
description = "Description explaining exactly what happens here" | ||
) | ||
public void on(ExampleListenerMessage message) { | ||
} | ||
|
||
@AsyncApi.Message(description = "this is a message which gets published") | ||
public static class ExamplePublisherMessage { | ||
|
||
public BigDecimal amount; | ||
@AsyncApi.Field(type = Integer.class) | ||
public String currency; | ||
} | ||
|
||
public static class ExampleListenerMessage { | ||
|
||
public BigDecimal amount; | ||
@AsyncApi.Field(examples = { "EUR", "USD", "CHF" }) | ||
public String currency; | ||
public ObjectRepresentingAnId id; | ||
} | ||
|
||
public static class ObjectRepresentingAnId { | ||
|
||
private final String value; | ||
|
||
public ObjectRepresentingAnId(String value) { | ||
|
||
this.value = value; | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
j2asyncapi-example/src/test/java/lu/greenhalos/j2asyncapi/example/AsyncApiGeneratorTest.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,81 @@ | ||
package lu.greenhalos.j2asyncapi.example; | ||
|
||
import com.asyncapi.v2.model.AsyncAPI; | ||
import com.asyncapi.v2.model.info.Contact; | ||
import com.asyncapi.v2.model.info.Info; | ||
import com.asyncapi.v2.model.server.Server; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; | ||
|
||
import lu.greenhalos.j2asyncapi.annoations.AsyncApiProcessor; | ||
import lu.greenhalos.j2asyncapi.core.Config; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import java.util.Map; | ||
|
||
|
||
/** | ||
* @author Ben Antony - [email protected] | ||
*/ | ||
public class AsyncApiGeneratorTest { | ||
|
||
private static final String DOCS_TARGET = "../docs/asyncapi-example.yaml"; | ||
|
||
@Test | ||
void generate() throws IOException { | ||
|
||
var asyncAPI = new AsyncAPI(); | ||
asyncAPI.setInfo(info()); | ||
asyncAPI.setServers(servers()); | ||
|
||
var config = Config.builder() | ||
.withAsyncApi(asyncAPI) | ||
.build(); | ||
|
||
AsyncApiProcessor.process(ExampleApplication.class, config); | ||
writeToFile(asyncAPI); | ||
} | ||
|
||
|
||
private Map<String, Server> servers() { | ||
|
||
return Map.of("test", server()); | ||
} | ||
|
||
|
||
private Server server() { | ||
|
||
var server = new Server(); | ||
server.setUrl("http://rabbitmq"); | ||
server.setDescription("RabbitMQ Server"); | ||
server.setProtocol("amqp"); | ||
|
||
return server; | ||
} | ||
|
||
|
||
private static Info info() { | ||
|
||
return new Info("Application API", "0.1.0", null, null, | ||
new Contact("Fancy Team", "https://greenhalos.lu", "[email protected]"), null); | ||
} | ||
|
||
|
||
private static void writeToFile(AsyncAPI asyncAPI) throws IOException { | ||
|
||
var objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); | ||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
|
||
var bytes = objectMapper.writeValueAsBytes(asyncAPI); | ||
FileUtils.writeByteArrayToFile(new File(DOCS_TARGET), bytes); | ||
} | ||
} |
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