-
Notifications
You must be signed in to change notification settings - Fork 76
Description
Is your feature request related to a problem? Please describe.
Currently, when inferring the schema from an input type for a tool, we only use the jsonschema:
tag to set a description of a field.
If we have a struct like this:
type HiArgs struct {
Name string `json:"name" jsonschema:"the name to say hi to"`
Age int `json:"age" jsonschema:"the age of the person" minimum:"0" maximum:"120" default:"20"`
Funkos []string `json:"funkos" jsonschema:"the funkos the person has" minimum:"1" examples:"[\"Batman\", \"Superman\"]" default:"[\"Batman\"]"`
}
The minimum
, maximum
, examples
, default
, ... and other tags we could have as exposed in the jsonschema-go (for example) are not being set in the actual schema.
Describe the solution you'd like
Ideally, to have the resulting schema with the correct fields inferred from the struct we provide from their field tags.
Having some helper handlers for the tags as proposed in this PR or a cleaner approach.
Describe alternatives you've considered
The current approach is not to infer those fields from the struct, but rather to provide a jsonschema.For
proactively to the tool:
...
schema, err := jsonschema.For[GetExample]()
if err != nil {
return nil, err
}
var minimum float64 = 1.0
schema.Properties["scopeHours"].Description = "Number of hours to look back for events" // easier using the `jsonschema` tag in the struct field
schema.Properties["scopeHours"].Default = json.RawMessage(`24`)
schema.Properties["scopeHours"].Minimum = jsonschema.Ptr(1.0)
schema.Properties["scopeHours"]. Maximum = jsonschema.Ptr(1000.0)
...
return schema, nil
If we use a tool to generate client code from an OpenAPI definition or similar standards, the schemas/structs could already have the necessary tags, and we would need to define them manually. Of course, we need to take into consideration the complexity of more complicated struct tags.