-
Notifications
You must be signed in to change notification settings - Fork 117
AsyncAPI 3.x: parse servers, bindings, channel parameters and security #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ae3c7b
bd3a056
a4eb3c5
d0959f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package com.webfuzzing.asyncapi.models; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * The subset of the protocol bindings that a client acts on, plus the untouched originals. | ||
| * | ||
| * Only a handful of fields are lifted out, because only a handful change what a client has to | ||
| * do. Everything else stays in {@link #getRaw()} so nothing is lost and a later transport can | ||
| * read it without the model having to grow first. | ||
| */ | ||
| public class AsyncApiChannelBindings { | ||
|
|
||
| private final String kafkaTopic; | ||
|
|
||
| private final String amqpIs; | ||
|
|
||
| private final String amqpQueue; | ||
|
|
||
| private final String amqpExchange; | ||
|
|
||
| private final String wsMethod; | ||
|
|
||
| /** | ||
| * Key is the protocol name, e.g. "kafka" or "amqp". | ||
| * Value is the binding declared for that protocol, exactly as written. | ||
| */ | ||
| private final Map<String, JsonNode> raw; | ||
|
|
||
| private AsyncApiChannelBindings(Builder builder) { | ||
| this.kafkaTopic = builder.kafkaTopic; | ||
| this.amqpIs = builder.amqpIs; | ||
| this.amqpQueue = builder.amqpQueue; | ||
| this.amqpExchange = builder.amqpExchange; | ||
| this.wsMethod = builder.wsMethod; | ||
| this.raw = Collections.unmodifiableMap(builder.raw); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can builder.raw be null?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not today (the parser always passes a fresh map), but the setter now rejects it explicitly, so the constructor can't be reached with one.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a programming discipline, please consider adding non nullity checks whenever required, even when the expected input can never be null |
||
| } | ||
|
|
||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Nothing declared, for a channel that has no bindings at all. | ||
| */ | ||
| public static AsyncApiChannelBindings none() { | ||
| return builder().build(); | ||
| } | ||
|
|
||
| /** | ||
| * {@code bindings.kafka.topic}. When set, it overrides the channel address for Kafka. | ||
| */ | ||
| public String getKafkaTopic() { | ||
| return kafkaTopic; | ||
| } | ||
|
|
||
| /** | ||
| * {@code bindings.amqp.is}, either "queue" or "routingKey". Decides whether a publisher | ||
| * should address a queue directly or go through an exchange. | ||
| */ | ||
| public String getAmqpIs() { | ||
| return amqpIs; | ||
| } | ||
|
|
||
| /** | ||
| * {@code bindings.amqp.queue.name}. | ||
| */ | ||
| public String getAmqpQueue() { | ||
| return amqpQueue; | ||
| } | ||
|
|
||
| /** | ||
| * {@code bindings.amqp.exchange.name}. | ||
| */ | ||
| public String getAmqpExchange() { | ||
| return amqpExchange; | ||
| } | ||
|
|
||
| /** | ||
| * {@code bindings.ws.method}, the HTTP method used for the opening handshake. | ||
| */ | ||
| public String getWsMethod() { | ||
| return wsMethod; | ||
| } | ||
|
|
||
| /** | ||
| * Every binding as declared, keyed by protocol name. | ||
| */ | ||
| public Map<String, JsonNode> getRaw() { | ||
| return raw; | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private String kafkaTopic; | ||
| private String amqpIs; | ||
| private String amqpQueue; | ||
| private String amqpExchange; | ||
| private String wsMethod; | ||
| /** @see AsyncApiChannelBindings#raw */ | ||
| private Map<String, JsonNode> raw = Collections.emptyMap(); | ||
|
|
||
| private Builder() { | ||
| } | ||
|
|
||
| public Builder kafkaTopic(String kafkaTopic) { this.kafkaTopic = kafkaTopic; return this; } | ||
|
|
||
| public Builder amqpIs(String amqpIs) { this.amqpIs = amqpIs; return this; } | ||
|
|
||
| public Builder amqpQueue(String amqpQueue) { this.amqpQueue = amqpQueue; return this; } | ||
|
|
||
| public Builder amqpExchange(String amqpExchange) { this.amqpExchange = amqpExchange; return this; } | ||
|
|
||
| public Builder wsMethod(String wsMethod) { this.wsMethod = wsMethod; return this; } | ||
|
|
||
| public Builder raw(Map<String, JsonNode> raw) { this.raw = Objects.requireNonNull(raw, "raw"); return this; } | ||
|
|
||
| public AsyncApiChannelBindings build() { | ||
| return new AsyncApiChannelBindings(this); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address could be null?