Generating jsonschema from cue #663
Replies: 4 comments 10 replies
-
Original reply by @bfallik in cuelang/cue#663 (comment) I'm just getting started learning cue so I was wondering why the need for Go code in that chain above? I would have expected cue to be able to output openapi directly and my local tests seem to confirm that it can:
|
Beta Was this translation helpful? Give feedback.
-
Original reply by @myitcv in cuelang/cue#663 (comment) I think you can even do this as a one-line with
The trick here being to import the exported JSONSchema as Untested, but it looks about right? |
Beta Was this translation helpful? Give feedback.
-
Original reply by @mpvl in cuelang/cue#663 (comment) We do plan to add a native to jsonschema converter, but for for now the focus is on the |
Beta Was this translation helpful? Give feedback.
-
Original reply by @ying-jeanne in cuelang/cue#663 (comment) Hi @mpvl and CUErs :), I would have to start converting cue into Jsonschema with golang soon, would like to know whether we currently have a converter already? or I would have to do the cue export suggested above. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Originally opened by @khepin in cuelang/cue#663
Wanted / needed to generate jsonschema from a cue file and while that isn't directly supported, I found a couple tools that you can stitch together to achieve that:
Here's the cue file:
From this, cue can generate an open api specification
cue export --out openapi test.cue
Which gives us the following openapi spec:
With that, there are a couple tools online that claim to go from openapi to jsonschema. The one I found that seems up to date and actually worked was: https://www.npmjs.com/package/@openapi-contrib/openapi-schema-to-json-schema
With the following javascript / nodejs code:
We finally get our jsonschema:
I briefly verified it at https://www.jsonschemavalidator.net/ and it seems to behave correctly. I haven't tested more advanced use cases though, but for simple ones this works well.
So by using cuelang + golang + javascript, you get a jsonschema that you can now import and use in your I guess!
Beta Was this translation helpful? Give feedback.
All reactions