scheme

command
v0.167.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 8 Imported by: 0

README

func parseJsonSchema(fpath string) []*Combinator {
	// reading json file
	data, err := ioutil.ReadFile(fpath)
	if err != nil {
		log.Fatal(err)
	}

	// parsings json
	var parsed interface{}
	d := json.NewDecoder(bytes.NewReader(data))
	d.UseNumber()
	if err := d.Decode(&parsed); err != nil {
		log.Fatal(err)
	}

	// processing constructors
	combinators := []*Combinator{}

	parsefunc := func(data []interface{}, kind string) {
		for _, data := range data {
			data := data.(map[string]interface{})

			// name
			name := normalizeName(data["id"].(string), 10)

			// identifier
			id := normalize(data[kind].(string))
			if id == "vector" {
				continue
			}

			// fields
			fields := make([]Field, 0, 16)
			srcFields := data["params"].([]interface{})
			for _, srcField := range srcFields {
				srcField := srcField.(map[string]interface{})
				name := srcField["name"].(string)
				typeName := srcField["type"].(string)
				fields = append(fields, makeField(name, typeName))
			}

			// type
			typeName := normalize(data["type"].(string))

			combinators = append(combinators, &Combinator{id, name, fields, typeName})
		}
	}
	parsefunc(parsed.(map[string]interface{})["constructors"].([]interface{}), "predicate")
	parsefunc(parsed.(map[string]interface{})["methods"].([]interface{}), "method")
	return combinators
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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