Skip to content

Commit

Permalink
feat: add descriptions as javadocs over generated code (#18)
Browse files Browse the repository at this point in the history
* feat: add descriptions as javadocs over generated code

* fix: generation for mqtt and amqp (#14)

* fix api calls for mqtt and amqp

* fix port variables

* feat: add annotations to the model generation (#12)

* WIP, update to spec 2.0

* WIP, update to spec 2.0, remove definition of topic via extension

* working version for api 2.0

* add model generation

* Add support of Kafka generation

* update readme

* fix value ref, add jackson lib

* add validation annotations to schema

* fix no type case

* add annotation for jackson

* add description and examples to javadoc

* Update readme, move missed features block

* switch publish to subscribe and vice versa, because of wrong understanding of spec

* Fix consumed key, add key to publish operation

* move jackson and validation dependencies from kafka block

* fix README formatting

* mark annotations as done in README

* add support of multi-line description

* fix json in examples

* chore(release): 0.5.0 (#15)

chore(release): 0.5.0

* fix api calls for mqtt and amqp

* fix port variables

* fix yet another api operation call

Co-authored-by: asyncapi-bot <[email protected]>

* chore(release): 0.5.1 (#19)

chore(release): 0.5.1

* feat: generalize Kafka properties (#16)

* feat: generalize kafka properties. use spring-kafka props inst.of custom, move props to template params

* fix wrong param name in example

* fix: generation for mqtt and amqp (#14)

* fix api calls for mqtt and amqp

* fix port variables

* feat: add annotations to the model generation (#12)

* WIP, update to spec 2.0

* WIP, update to spec 2.0, remove definition of topic via extension

* working version for api 2.0

* add model generation

* Add support of Kafka generation

* update readme

* fix value ref, add jackson lib

* add validation annotations to schema

* fix no type case

* add annotation for jackson

* add description and examples to javadoc

* Update readme, move missed features block

* switch publish to subscribe and vice versa, because of wrong understanding of spec

* Fix consumed key, add key to publish operation

* move jackson and validation dependencies from kafka block

* fix README formatting

* mark annotations as done in README

* add support of multi-line description

* fix json in examples

* chore(release): 0.5.0 (#15)

chore(release): 0.5.0

* fix api calls for mqtt and amqp

* fix port variables

* fix yet another api operation call

Co-authored-by: asyncapi-bot <[email protected]>

* chore(release): 0.5.1 (#19)

chore(release): 0.5.1

* feat: generalize kafka properties. use spring-kafka props inst.of custom, move props to template params

* fix wrong param name in example

Co-authored-by: asyncapi-bot <[email protected]>

* chore(release): 0.6.0 (#20)

chore(release): 0.6.0

* feat: add descriptions as javadocs over generated code

Co-authored-by: asyncapi-bot <[email protected]>
  • Loading branch information
Tenischev and asyncapi-bot authored Apr 26, 2020
1 parent 91646bd commit c321c71
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = ({ Nunjucks }) => {

Nunjucks.addFilter('splitByLines', (str) => {
if (str) {
return str.split(/\r?\n|\r/);
return str.split(/\r?\n|\r/).filter((s) => s !== "");
} else {
return "";
}
Expand Down
4 changes: 4 additions & 0 deletions partials/CommonPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public interface PublisherService {

{% for channelName, channel in asyncapi.channels() %}
{% if channel.hasSubscribe() %}
{% if channel.description() or channel.subscribe().description() %}/**{% for line in channel.description() | splitByLines %}
* {{line | safe}}{% endfor %}{% for line in channel.subscribe().description() | splitByLines %}
* {{line | safe}}{% endfor %}
*/{% endif %}
@Gateway(requestChannel = "{{channelName | camelCase}}OutboundChannel")
void {{channel.subscribe().id() | camelCase}}(String data);
{% endif %}
Expand Down
4 changes: 4 additions & 0 deletions partials/KafkaPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class PublisherService {
private KafkaTemplate<Integer, String> kafkaTemplate;
{% for channelName, channel in asyncapi.channels() %}
{%- if channel.hasSubscribe() %} {% set varName = channel.subscribe().message().payload().uid() | camelCase %}
{% if channel.description() or channel.subscribe().description() %}/**{% for line in channel.description() | splitByLines %}
* {{line | safe}}{% endfor %}{% for line in channel.subscribe().description() | splitByLines %}
* {{line | safe}}{% endfor %}
*/{% endif %}
public void {{channel.subscribe().id() | camelCase}}(Integer key, {{varName | upperFirst}} {{varName}}) {
Message<{{varName | upperFirst}}> message = MessageBuilder.withPayload({{varName}})
.setHeader(KafkaHeaders.TOPIC, "{{channelName}}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class MessageHandlerService {
{% if asyncapi | isProtocol('kafka') %}
{% for channelName, channel in asyncapi.channels() %}
{%- if channel.hasPublish() %}

{% if channel.description() or channel.publish().description() %}/**{% for line in channel.description() | splitByLines %}
* {{line | safe}}{% endfor %}{% for line in channel.publish().description() | splitByLines %}
* {{line | safe}}{% endfor %}
*/{% endif %}
@KafkaListener(topics = "{{channelName}}"{% if channel.publish().binding('kafka') %}, groupId = "{{channel.publish().binding('kafka').groupId}}"{% endif %})
public void {{channel.publish().id() | camelCase}}(@Payload {{channel.publish().message().payload().uid() | camelCase | upperFirst}} payload,
@Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) Integer key,
Expand All @@ -40,6 +45,10 @@ public class MessageHandlerService {
{% else %}
{% for channelName, channel in asyncapi.channels() %}
{% if channel.hasPublish() %}
{% if channel.description() or channel.publish().description() %}/**{% for line in channel.description() | splitByLines %}
* {{line | safe}}{% endfor %}{% for line in channel.publish().description() | splitByLines %}
* {{line | safe}}{% endfor %}
*/{% endif %}
public void handle{{channelName | upperFirst}}(Message<?> message) {
System.out.println("handler {{channelName}}");
System.out.println(message.getPayload());
Expand Down
10 changes: 7 additions & 3 deletions template/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
{%- endfor -%}
{%- for serverName, server in asyncapi.servers() %}{% if server.protocol() == 'amqp' %}
amqp:
broker:
broker: {% for line in server.description() | splitByLines %}
# {{line | safe}}{% endfor %}
host: {{server.url() | replace(':{port}', '') }}
port: {% if server.variable('port') %}{{server.variable('port').defaultValue()}}{% endif %}
username:
Expand All @@ -30,7 +31,8 @@ amqp:
{% endif %}
{% if server.protocol() == 'mqtt' %}
mqtt:
broker:
broker: {% for line in server.description() | splitByLines %}
# {{line | safe}}{% endfor %}
host: tcp://{{server.url() | replace(':{port}', '')}}
port: {% if server.variable('port') %}{{server.variable('port').defaultValue()}}{% endif %}
username:
Expand All @@ -42,7 +44,9 @@ mqtt:
{% endif %}{% endfor %}
{%- if asyncapi | isProtocol('kafka') %}
spring:
kafka:
kafka: {% for serverName, server in asyncapi.servers() %}
# - {{serverName}} in {{server.url()}} : {% for line in server.description() | splitByLines %}
# {{line | safe}}{% endfor %}{% endfor %}
bootstrap-servers: {% for serverName, server in asyncapi.servers() %}{% if server.variable('port') %}{{server.url() | replace('{port}', server.variable('port').defaultValue())}}{% else %}{{server.url()}}{% endif %}{% if not loop.last %},{% endif %}{% endfor %}
{%- if hasPublish %}
listener:
Expand Down

0 comments on commit c321c71

Please sign in to comment.