-
Notifications
You must be signed in to change notification settings - Fork 36
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
Align the SDK with the new DSL #203
Comments
What is your opinion on generating the SDK code based on the json schema?https://github.com/serverlessworkflow/specification/blob/main/schema/workflow.yaml |
@ribeiromiranda +1 if we can, although in my experience, the workflow can be really complex and hard to model using generators. We have much |
I understand, generating code can get very complex. Another very interesting way to make a json schema interpreter with libraries: https://cuelang.org or https://github.com/xeipuuv/gojsonschema. Is it simpler than generating the code and robust to changes in the specification. |
+1, are you willing to give it a try? |
The DSL is still changing, so I would wait till is more stable. Probably next week will be a good moment to start working on that. Relying completely in code generation is going to be complex because the presence of oneOf/anyOf/allOf, so I foresee following approaches.
|
@fjtirado despite the stability of the DSL, it's worth starting to explore our possibilities first. Regarding your points, unfortunately, Go doesn't play well with inheritance. Let's see what we can do given @ribeiromiranda suggestions. I agree that in the Java SDK option 3 can be a good alternative for the |
Yes, for option 3. in go, the option is to wrap the generated Pojo into another one https://www.geeksforgeeks.org/inheritance-in-golang/ (since GO allows calling the methods of the generated pojo within the container one, it will do the trick) |
I think these features below can be using jsonschema validation:
Development the validation (e.g. map jsonschema into a graph):
Generate code based in jsonschema
I don't know if it has other features or I might be simplistic? I think there is no need to map jsonschema into struct. If everyone agrees, I can try to develop some simple cases. A very simple validation example: package main
import (
_ "embed"
"fmt"
"log"
"os"
"github.com/xeipuuv/gojsonschema"
"sigs.k8s.io/yaml"
)
//go:embed workflow.yaml
var yamlWorkflow []byte
func main() {
jsonWorkflow, err := yaml.YAMLToJSON(yamlWorkflow)
if err != nil {
log.Fatal(err.Error())
}
yamlExample, err := os.ReadFile("./example.yaml")
if err != nil {
log.Fatal(err.Error())
}
jsonExample, err := yaml.YAMLToJSON(yamlExample)
if err != nil {
log.Fatal(err.Error())
}
schemaLoader := gojsonschema.NewBytesLoader(jsonWorkflow)
documentLoader := gojsonschema.NewBytesLoader(jsonExample)
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
log.Fatal(err.Error())
}
if result.Valid() {
fmt.Printf("The document is valid\n")
} else {
fmt.Printf("The document is not valid. see errors :\n")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
}
} |
I know how to do inheritance in Go, but that's not the point. The point is this technique is an anti-pattern in general we avoid. |
@ribeiromiranda yup, that's the overall features we will provide for the SDK. Generating diagrams can be a nice to have, but not a priority since we do not have this feature atm anyway. |
@ribeiromiranda I think that the input to the validator should be just the workflow definition stream (an io.reader) being validated (the loading of the validating schema should be hidden to the developer) |
just a reminder about it:
using generics with the SDK is a not good approach due the kubernetes integration. we had some problem related to it in the past. |
The internal representation as a graph for the resources:
I don't know how Kubernetes integration works, the need to represent it with a struct Representation example:
|
I don't see an issue with this representation, @ribeiromiranda @spolti. And I agree that generics is a no-go. Too much compatibility issues with k8s libraries. |
I created the repository with a proposal to implement the new DSL, if I follow this implementation I will create a PR. This repository implemented a basic "validator" using jsonschema and "builder", in the file "example/example.go" there are some use cases. |
@ribeiromiranda sorry for the late reply, I was on PTO. To me, it seems aligned with what we talked about. |
One little thing: this is supposed to be v4, not v3 since we are skipping 0.9 release. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What would you like to be added:
The DSL has been updated to a new and concise version.
Why is this needed:
The SDK needs to support the new DSL, as found here: https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md
For more info: serverlessworkflow/specification#843
The text was updated successfully, but these errors were encountered: