RedHatInsights / event-schemas

WIP consoledot CloudEvents schemas
Apache License 2.0
4 stars 10 forks source link

[DRAFT] PoC generation of libraries using quicktype.io #12

Closed kahowell closed 2 years ago

kahowell commented 2 years ago

To update the bindings, first do npm install, and then node scripts/generate.js

josejulio commented 2 years ago

I think this makes a quick and easy way to build bindings for a lot of languages.

That said, I haven't looked on the details, but I didn't see the bindings for the Event class - at least didn't see it for java - but maybe I missed it.

On java I used some libraries to be able to parse the schema file and use it to validate the input before the actual conversion to a java object. This is because not all json-schema features (i.e. oneOf or allOf) map nicely to java classes.

It has been working nice, but it's something to do manually for java and we would need to find alternatives for the other languages.

For example, the json-schema [1] generates a Foo class that has both bar and baz and no restriction that only one can be used at the same time.

[1]

{
  "id": "http://json-schema.org/geo",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "description": "A geographical coordinate",
  "type": "object",
  "properties": {
    "foo": {
        "type": "object",
        "oneOf": [
            {
                "type": "object",
                "properties": {
                    "bar": {
                        "type": "number"
                    }
                }
            },
            {
                "type": "object",
                "properties": {
                    "baz": {
                        "type": "number"
                    }
                }
            }
        ]
    }
  }
}
kahowell commented 2 years ago

I didn't see the bindings for the Event class

Actually, I was thinking it's wiser to use the official SDKs/integrations for CloudEvents, e.g. CloudEvents Java SDK. See core docs and Jackson docs for how this might work in a typical Java application.

vkrizan commented 2 years ago

@kahowell As I mentioned via email, can the lib support be in a separate repository?

kahowell commented 2 years ago

@vkrizan absolutely, I think this would be better practice for reasons you mentioned in the email (especially avoiding clutter of the schema repo). It should also allow developers to contribute to the bindings for their language of choice with confidence that they won't break bindings for an unfamiliar language. I will try to get some repos set up for this w/ some automation in the near future.

kahowell commented 2 years ago

Closing in favor of standalone repos; see: