diff --git a/filters/all.js b/filters/all.js index fbce936b6..a8cb0b745 100644 --- a/filters/all.js +++ b/filters/all.js @@ -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 \ No newline at end of file +function toMqttTopicString(channelName, hasParameters, parameters) { + return toTopicString(channelName, hasParameters, parameters, false, "+") +} + +filter.toMqttTopicString = toMqttTopicString \ No newline at end of file diff --git a/template/src/main/resources/application.yml b/template/src/main/resources/application.yml index 8aa1d9f64..29936f4bc 100644 --- a/template/src/main/resources/application.yml +++ b/template/src/main/resources/application.yml @@ -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 %}