Documentation ¶
Overview ¶
Example (BasicSchema) ¶
package main import ( "fmt" "log" "github.com/cloudquery/codegen/jsonschema" ) func main() { type basic struct { A string `json:"a" jsonschema:"minLength=2,required"` } data, err := jsonschema.Generate(new(basic)) if err != nil { log.Fatal(err) } fmt.Println(string(data)) }
Output: { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://github.com/cloudquery/codegen/jsonschema_test/basic", "$ref": "#/$defs/basic", "$defs": { "basic": { "properties": { "a": { "type": "string", "minLength": 2 } }, "additionalProperties": false, "type": "object", "required": [ "a" ] } } }
Index ¶
- func Generate(a any, options ...Option) ([]byte, error)
- func GenerateIntoFile(a any, filePath string, options ...Option)
- func Sanitize(sc *jsonschema.Schema) error
- func TestJSONSchema(t *testing.T, schema string, cases []TestCase)
- func WithRemovedKeys(t *testing.T, val any, keys ...string) string
- type Option
- type TestCase
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate returns a formatted JSON schema for the input struct, according to the tags defined by https://github.com/invopop/jsonschema
func GenerateIntoFile ¶ added in v0.3.3
func Sanitize ¶ added in v0.3.5
func Sanitize(sc *jsonschema.Schema) error
func TestJSONSchema ¶ added in v0.3.5
Types ¶
type Option ¶ added in v0.3.9
type Option func(*jsonschema.Reflector)
func WithAddGoComments ¶ added in v0.3.9
Click to show internal directories.
Click to hide internal directories.