Skip to content

Commit

Permalink
use mqtt specific wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenischev committed Nov 22, 2023
1 parent c2d565e commit cf8cde7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,21 @@ function replaceAll(originalStr, replacePattern, replaceString) {
}
filter.replaceAll = replaceAll;

function toTopicString(channelName, hasParameters, parameters) {
function toTopicString(channelName, hasParameters, parameters, convertDots, replaceValue) {
if (hasParameters) {
let topicName = replaceAll(channelName, ".", "\.")
Object.keys(parameters).forEach(value => topicName = topicName.replace("{" + value + "}", ".*"))
let topicName = channelName
if (convertDots) {
topicName = replaceAll(topicName, ".", "\.")
}
Object.keys(parameters).forEach(value => topicName = topicName.replace("{" + value + "}", replaceValue))
return topicName
} else {
return channelName
}
}

filter.toTopicString = toTopicString
function toMqttTopicString(channelName, hasParameters, parameters) {
return toTopicString(channelName, hasParameters, parameters, false, "+")
}

filter.toMqttTopicString = toMqttTopicString
4 changes: 2 additions & 2 deletions template/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ mqtt:
{% if server.binding('mqtt') and server.binding('mqtt').keepAlive | isDefined %}keepAlive: {{server.binding('mqtt').keepAlive}}{% endif %}
topic:
{%- for channelName, channel in asyncapi.channels() %}{% if channel.hasPublish() %}
{{channel.publish().id() | camelCase}}: {{channelName | toTopicString(channel.hasParameters(), channel.parameters()) }}
{{channel.publish().id() | camelCase}}: {{channelName | toMqttTopicString(channel.hasParameters(), channel.parameters()) }}
{%- elif channel.hasSubscribe() %}
{{channel.subscribe().id() | camelCase}}: {{channelName | toTopicString(channel.hasParameters(), channel.parameters())}}
{{channel.subscribe().id() | camelCase}}: {{channelName | toMqttTopicString(channel.hasParameters(), channel.parameters()) }}
{%- endif %}{% endfor %}
{% endif %}{% endfor %}

Expand Down

0 comments on commit cf8cde7

Please sign in to comment.