Repository navigation
fix: write custom bindings as x- extensions in AsyncAPI 3 documents #67
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
Open
bielu
wants to merge
4
commits into
ByteBardOrg:vnext
Choose a base branch
from
bielu:fix/v3-custom-binding-keys
base: vnext
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
60e5ce6
fix: write custom bindings as x- extensions in AsyncAPI 3 documents
bielu 8b93442
fix: read a binding registered under an x- key as that binding
bielu 785bad7
fix: keep mqtt5 and mercure as AsyncAPI 3 binding names
bielu a1a3bb5
fix: refuse to write clashing binding names in AsyncAPI 3
bielu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| namespace ByteBard.AsyncAPI.Bindings | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using ByteBard.AsyncAPI.Models; | ||
| using ByteBard.AsyncAPI.Models.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// The binding names AsyncAPI 3 defines, and the key a binding is written under in an AsyncAPI 3 document. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// In AsyncAPI 3 the server, channel, operation and message bindings objects only allow the protocol names | ||
| /// the specification lists, plus <c>x-</c> extensions. A custom binding (one whose <see cref="IBinding.BindingKey"/> | ||
| /// is not listed) is therefore written as <c>x-<key></c>. AsyncAPI 2 allows any key, so it keeps the key as is. | ||
| /// </remarks> | ||
| public static class AsyncApiBindingKeys | ||
| { | ||
| // Every binding the AsyncAPI 3.0 and 3.1 specifications name in a bindings object. The prose is normative; the | ||
| // JSON schemas omit mqtt5 and mercure, but the specification text lists them as fixed fields. | ||
| private static readonly HashSet<string> SpecificationKeys = new HashSet<string>(StringComparer.Ordinal) | ||
| { | ||
| "amqp", "amqp1", "anypointmq", "googlepubsub", "http", "ibmmq", "jms", "kafka", "mercure", "mqtt", "mqtt5", | ||
| "nats", "pulsar", "redis", "ros2", "sns", "solace", "sqs", "stomp", "ws", | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Whether AsyncAPI 3 defines a binding with this name. | ||
| /// </summary> | ||
| /// <param name="key">The binding key.</param> | ||
| /// <returns><c>true</c> for a binding the specification lists; <c>false</c> otherwise, including for <c>x-</c> keys.</returns> | ||
| public static bool IsSpecificationKey(string key) | ||
| { | ||
| return key != null && SpecificationKeys.Contains(key); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The property name a binding is written under in an AsyncAPI 3 bindings object. | ||
| /// </summary> | ||
| /// <param name="key">The binding key.</param> | ||
| /// <returns>The key itself for a specification binding or an <c>x-</c> key; otherwise the key with an <c>x-</c> prefix.</returns> | ||
| public static string ToV3Key(string key) | ||
| { | ||
| if (key is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(key)); | ||
| } | ||
|
|
||
| return IsSpecificationKey(key) || key.StartsWith(AsyncApiConstants.ExtensionFieldNamePrefix, StringComparison.Ordinal) | ||
| ? key | ||
| : AsyncApiConstants.ExtensionFieldNamePrefix + key; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.