cue
cue copied to clipboard
jsonschema.Marshal
Is your feature request related to a problem? Please describe. When exporting a config, I sometimes need the value of a field to equal the json-schema of another cue type. For example: LLM tool definitions.
Describe the solution you'd like Similar to json.Marshal, I would like a jsonschema.Marshal that takes a cue definition and outputs json-schema.
Describe alternatives you've considered Alternatively, I have to maintain json-schema by hand, or do a two-phase build process.
Do you mean generating jsonschema from CUE? If so, this would be https://github.com/cue-lang/cue/issues/929.
I want to generate jsonschema or openapi in cue via a function like json.Marshal.
For example:
test.cue
import "encoding/jsonschema"
#ThinkTool: {
name: string
description: string
}
Component: {
id: "LLMComponent"
parameters: {
model: string | *"gpt-4o"
tools: {
think_tool: jsonschema.Marshal(#ThinkTool)
}
}
}
cue export test.cue
{
"Component": {
"id": "LLMInterface",
"parameters": {
"model": "gpt-4o",
"tools": {
"think_tool": "{\"openapi\":\"3.0.0\",\"info\":{\"title\":\"Generated by cue.\",\"version\":\"no version\"},\"paths\":{},\"components\":{\"schemas\":{\"Thought\":{\"type\":\"object\",\"required\":[\"name\",\"description\"],\"properties\":{\"name\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"}}}}}}"
}
}
}
}
I see, thanks. I would suggest that we focus on https://github.com/cue-lang/cue/issues/929 to track supporting encoding CUE schemas to JSON Schema; once that is in place, adding a package to be imported and used from CUE code should be pretty straightforward, so it doesn't need to be tracked separately. As a general rule of thumb, we expose encodings as CUE standard library APIs.