jsonschema

package
v0.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: MPL-2.0 Imports: 10 Imported by: 62 modules, 61 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(a any, options ...Option) ([]byte, error)

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 GenerateIntoFile(a any, filePath string, options ...Option)

func Sanitize added in v0.3.5

func Sanitize(sc *jsonschema.Schema) error

func TestJSONSchema added in v0.3.5

func TestJSONSchema(t *testing.T, schema string, cases []TestCase)

func WithRemovedKeys added in v0.3.5

func WithRemovedKeys(t *testing.T, val any, keys ...string) string

Types

type Option added in v0.3.9

type Option func(*jsonschema.Reflector)

func WithAddGoComments added in v0.3.9

func WithAddGoComments(base, path string) Option

type TestCase added in v0.3.5

type TestCase struct {
	Name         string
	Spec         string
	Err          bool
	ErrorMessage string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL