spec icon indicating copy to clipboard operation
spec copied to clipboard

[RFC] Support JSON Schema for bindings

Open magicmatatjahu opened this issue 3 years ago • 15 comments

Is your feature request related to a problem? Please describe.

Making review for this PR https://github.com/asyncapi/asyncapi-react/pull/259 I realized that we don't have JSON Schema definitions for officially supported bindings by AsyncAPI. Currently we have only markdown documents like for http -> https://github.com/asyncapi/bindings/tree/master/http

Without JSON Schema for bindings we cannot:

  • validate bindings object in parser-js,
  • using binding's model in templates for parsed schemas by parser-js,
  • render correctly bindings in templates and React component - we still can, but the JSON Schema would make it easier.

how to validate bindings in parser is a different problem, but I'd like to mention it here.

Can't it be tackled using specification extensions? and Describe the solution you'd like

We can use extensions to define JSON Schema for each officially supported bindings (link).

I very like this approach (treating bindings as extensions), because then versioning of bindings is not related to AsyncAPI versioning at all - bindings can be versioned next to the official AsyncAPI release without any problems.

Problems which I see with this solution:

  • where we should store JSON Schemas? Probably the bindings repository is the best place.
  • what with bindingsObject object? Make references to external JSON Schemas in bindings repo or maybe remove whole object and then user should define extension of appropriate binding in spec? TBH I don't know. In my PoV I would like to choose second variant, because I think that AsyncAPI JSON Schema should be as small as possible without reference to external sources, but it could degrade DX. Feel free to share your thoughts about that!

Describe alternatives you've considered

If we cannot use extension to define JSON Schema for official supported bindings, then only solution as I see, is describing definition here, but I very don't like this.

magicmatatjahu avatar Mar 10 '21 12:03 magicmatatjahu

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Mar 10 '21 12:03 github-actions[bot]

At the moment bindings have versioning independent from spec version, and it is good imho. we should store schemas in bindings repo so it is easier to binding maintainers to maintain them, and just ref those in here but dereference as part of publishing process because we do not want to do it during parsing.

derberg avatar Apr 13 '21 11:04 derberg

...and just ref those in here but dereference as part of publishing process because we do not want to do it during parsing.

I agree with that! We can use for that standalone compilation to generate validation function for our schema to improve performance. At the moment we "compile" (including dereferencing) schema in each execution of the parse function (line). I don't know how we can speed parsing, but I think that it should be faster :)

magicmatatjahu avatar Apr 13 '21 11:04 magicmatatjahu

We can use for that standalone compilation to generate validation function for our schema to improve performance. At the moment we "compile" (including dereferencing) schema in each execution of the parse function (line). I don't know how we can speed parsing, but I think that it should be faster :)

@magicmatatjahu are you talking about splitting the task of validating bindings into separate standalone components and only validate those bindings in use? Instead of everything at once? 🤔

jonaslagoni avatar Apr 13 '21 13:04 jonaslagoni

@jonaslagoni No. Ajv supports compilation of the JSON Schema to "standalone" function which can be saved to file and then reused in JS application. In reference to @derberg comments:

we should store schemas in bindings repo so it is easier to binding maintainers to maintain them, and just ref those in here but dereference as part of publishing process because we do not want to do it during parsing.

So by this standalone function we can dereference refs for binding's JSON Schemas, compiled it and save to file and use this function in parser. By this operation we can move @asyncapi/specs package to devDependencies -- currently specs are bundled in parser and we can reduce size.

EDIT: Of course this logic doesn't handle the problem with JSON Schemas for extensions (also for custom bindings), but it is a good way to handle supported bindings and speed up the parser.

magicmatatjahu avatar Apr 13 '21 13:04 magicmatatjahu

I would not worry much about custom bindings, we accept any bindings in the spec, look at IBM or Anypoint (in progress). Json schema for extensions will be solved by extension registry.

My feeling is this is not related to spec at all as json schema is a tool, not the spec. Next step would be to first create those JSON Schemas for bindings, right? the only open problem for me is location. Bindings repo seems best as it will be better to maintain it, but on the other hand, in the asyncapi json schema we should not reference files from master but rather a tag. Now question is, I'm not decided, is it ok to always push new tag on bindings repo even if there will be a change just in one binding (bindings are versioned separately). For me this is just a technical tag, not related to specification, so sounds good to me, but correct me if I'm wrong

derberg avatar Apr 14 '21 07:04 derberg

I want to help implement this feature, As I understand we need to:

  1. Create JSON Schema for each binding and store them in binding repo.
    • How are we going to approach this? just look at the specifications and create a JSON Schema for it?
  2. Reference those Schemas here.
    • Where exactly?
  3. generate standalone functions to validate the bindings against JSON Schemas(that we created at the first stage) and use them in parser.
    • Where, at what repo and when?

Sorry, these questions might have obvious answers that I don't see.

KhudaDad414 avatar Apr 15 '21 06:04 KhudaDad414

How are we going to approach this? just look at the specifications and create a JSON Schema for it?

yeap 😄 but don't worry, some do not have bindings defined yet. my only concern is that there are different bindings per different AsyncAPI object, like operation and message for example. So there will be maximum of 4 schemas per protocol. So 🤔 we either have 4 files, with proper pattern in file name, or one custom yaml with 4 schemas in it.

Where exactly? Here https://github.com/asyncapi/asyncapi-node/blob/master/schemas/2.0.0.json. For example now we have kafka: {} and should have kafka: '$ref: xxx' .But not now, this is next step. We do not want to have url refs, at least I think.

Where, at what repo and when?

This one is a next step after the previous one, like a final step on how to at the end enable parser to consume these schemas.


Let's just solve it step by step I think and first figure out how and then create files with JSON schemas

derberg avatar Apr 16 '21 08:04 derberg

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Jun 16 '21 00:06 github-actions[bot]

Bindings schemas are already merged with https://github.com/asyncapi/bindings/pull/60 Now we need to figure out how to handle it in the parser and the asyncapi json schema https://github.com/asyncapi/parser-js/issues/315

derberg avatar Jun 16 '21 11:06 derberg

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Aug 16 '21 00:08 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Dec 15 '21 00:12 github-actions[bot]

I think it makes sense to move this to https://github.com/asyncapi/spec-json-schemas, right?

jonaslagoni avatar Jan 19 '22 15:01 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar May 27 '22 00:05 github-actions[bot]

@derberg Could you unstale that issue. We have discussed solution for it :)

magicmatatjahu avatar May 30 '22 09:05 magicmatatjahu

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 28 '22 00:09 github-actions[bot]

@magicmatatjahu I suggest we close it

  • schemas were created long time ago already by Khuda
  • Jonas is not integrating them in the spec-json-schema

or we move it to spec-json-schema and close once PR from Jonas is merged

derberg avatar Sep 29 '22 13:09 derberg

Agree this can be closed :)

jonaslagoni avatar Mar 09 '23 13:03 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Sep 01 '23 00:09 github-actions[bot]

@derberg can you close this one as complete 🙂

jonaslagoni avatar Oct 26 '23 10:10 jonaslagoni

closing as merge of https://github.com/asyncapi/spec-json-schemas/pull/208 will solve it definitely

derberg avatar Oct 31 '23 11:10 derberg