-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
[FEATURE REQUEST] Provide formal type for message examples #329
Comments
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue. |
+1 this is expected by many async devs, archi... and will be great to be able to rely on specs for this purpose. |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
Hi @fmvilas and AsyncAPI team, Just to let you know how we plan to use AsyncAPI examples in Microcks.io, we released a preview video of this feature here: https://www.youtube.com/watch?v=uZaWAekvUz4 You'll see the previous suggested formalism in action. Please tell us what you think about it ;-) Cheers, |
@lbroudoux Awesome demo, thanks a lot for sharing. It super nicely shows why would it make sense to have more structured and defined examples |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
Hi AsyncAPI team, Now that we have a working implementation in Microcks and are close to release What could be the best way:
I've got some time to spend on this in coming weeks so really like to contribute back ;-) |
@lbroudoux there is no formal process like KEP for Kubernetes for example. We simply work and discuss in issues to have all the thinking process in one place. So we first discuss under issue and then once there is a consensus you go on with a PR. |
OK nice! So I actually implemented some samples using the solution that was here first described:
For now - after having tested it on a dozen of schemas and use-case - I cannot foresee any caveats, difficulties or challenges following this specification. What do you think? |
I like the suggestion a lot. I only have a question in my head to the example object from OAS that you provided in the description. There is |
It's a good point ! From what I see until now, As a very personal note and opinion, I also think that referencing stuffs outside of the specification file can lead to imprecise, too generic or totally mismatching examples. For me - and some other folks I discuss with - specifying examples is all about being very specific to the context (think of bounded context) of the operation or the API at a whole. Scaffolding valid examples embedded within the spec is usually an issue of tooling and some tools like Apicurio do this very well and help keeping examples in sync when evolving schema. Also, from my understanding using So, even if they do not sound essential to me, I tend to think that we could add something like |
afaik Avro can be presented as JSON or YAML so you can easily put it inside AsyncAPI file. Have a look at this example for our Avro schema parser https://github.com/asyncapi/avro-schema-parser#usage. Avro is part of the spec, and we specify it is Avro with
how do they do it in JSON, xml is represented as string or? |
Yes, XML represented as string between double-quotes. JSON represented as string or JSON embedded into YAML or in YAML depending on the authoring tool. In the case of Microcks importing YAML, we take care of YAML to JSON conversion based on specified content-type like you suggest for |
oh 🤦 we have |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
Regarding your last comment on this issue: yes you're right, Now that we have stabilized things and demonstrate pragmatic usages of examples through Microcks mocking and testing features, I'd like to tackle making this issue and suggestions a real proposal for Let me know, I'll be happy to start writing it in a more formal way. |
@lbroudoux I think we need to figure out this first #463. Feel free to jump into discussion |
Thanks @derberg for the heads-up. I'll jump 😉 |
According to AsyncAPI schema, example must match payload and therefore we will support this kind of validation, we just didn't have time to add it yet -> asyncapi/parser-js#99 |
Agree with the role of tooling for this. This is where tooling can bring additional value. FYI, I am a contributor to Apicurio Studio and it has validation rules for OpenAPI including examples. |
Ok. If we plan to provide example validation in the future, then this (formal type for message examples) is a good feature to support. 👍 |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
Still there ;-) with hope to tackle this one soon ! |
@lbroudoux let's do this. Please have a look at the latest contribution guide and update here information about the stage your proposal reached. I bet you want to be the champion for it and drive it forward until the end |
@lbroudoux I had a thought recently about this proposal and wanted to suggest an alternative that would not introduce a breaking change to the spec. Initial proposal is examples:
- laurent:
summary: Example for Laurent user
headers: |-
{"my-app-header": 23, "sentAt": "2020-03-11T08:03:28Z"}
payload: |-
{"fullName": "Laurent Broudoux", "email": "laurent@microcks.io", "age": 41}
- john:
summary: Example for John Doe user
headers:
my-app-header: 24
sentAt: "2020-03-11T08:03:38Z"
payload:
fullName: John Doe
email: john@microcks.io
age: 36 Current structure: examples:
- headers: |-
{"my-app-header": 23, "sentAt": "2020-03-11T08:03:28Z"}
payload: |-
{"fullName": "Laurent Broudoux", "email": "laurent@microcks.io", "age": 41}
- headers:
my-app-header: 24
sentAt: "2020-03-11T08:03:38Z"
payload:
fullName: John Doe
email: john@microcks.io
age: 36 Why not doing: examples:
- name: laurent #machine readable as it is now with message.name (for consistency)
summary: Example for Laurent user
headers: |-
{"my-app-header": 23, "sentAt": "2020-03-11T08:03:28Z"}
payload: |-
{"fullName": "Laurent Broudoux", "email": "laurent@microcks.io", "age": 41}
- name: john #machine readable as it is now with message.name (for consistency)
summary: Example for John Doe user
headers:
my-app-header: 24
sentAt: "2020-03-11T08:03:38Z"
payload:
fullName: John Doe
email: john@microcks.io
age: 36 Not everyone uses spec for testing, so not everyone should be "forced" to provide a |
Hi @derberg, thanks for the suggestion, this is a great one and make the trick possible! The initial proposal of having a key was intended to align the structure on the one from OpenAPI Spec but it's better to introduce this without a breaking change. Luckily enough, I had some time in the coming days and will review the new contribution guide to see how ti push this onward. |
Hi @derberg! Pushed this 2 PRs few days ago. However, I did not have access to labels in order to propose a |
@fmvilas I think we reached Stage 1 here, right? @lbroudoux we also need a PR against the parser as this is release requirement, to add support for new fields, not only bump node-asyncapi but also extend https://github.com/asyncapi/parser-js/blob/master/lib/models/message-traitable.js#L89 as for now we just have a simple helper that returns all examples. Thoughts? |
Great! As I saw that examples are still of Any type (despite payload and headers already in the spec) I thought there was a design decision to keep them generic ;-) Anyway, I will push the PR! |
keep in mind parser is still a bit behind the spec, some features are missing like examples validation against the schemas, so don't pay that much attention to the type that you see there |
@derberg Yup, label added. |
Suggestions have been resolved into existing PRs. I think the check list is now complete for entering Stage 2: DRAFT 😄 |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
I think that this issue is resolved @lbroudoux If you think that something should be added, please reopen it. Thanks again for the contribution! :) |
Is your feature request related to a problem? Please describe.
I'm working on an API mocking tool that aims to use a specification examples for providing mock endpoints and realize contract testing (see https://microcks.io). For REST APIs specified with OpenAPIs, Microcks tooks advantage of clearly defined exampleObject allowing to specify example values and references for every request or response fragments.
I found it very valuable to have the same mechanism with AsyncAPI to allow specification of real-life examples for providing mock channels and messages helping speed-up development on new consumers / providers. However, examples are just for now a
[Map[string, any]]
that makes them difficult to agree on a common way to structure samples.Can't it be tackled using specification extensions?
I do not see any extension mechanism to enable this...
Describe the solution you'd like
I'd like a formal type description on how a message example should be structured including some metadata, an optional set of headers and the associated payload. Something like:
Describe alternatives you've considered
I considered providing example fragments at each level of the specification (header, traits and payload) but I found it confusing because trait does not seem to allow examples and also because examples in the case of headers are the schema level and not the instance level. This proposition looks the more concise and understandable (at least to me ;-) )
Additional context
This feature will allow :
The text was updated successfully, but these errors were encountered: