Skip to content

This tool generates JSON schemas from Go structs which can be used as event definition produced by a service.

License

Notifications You must be signed in to change notification settings

SadriShehu/schematic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Schematic

This tool generates JSON schemas from Go structs which can be used as event definition produced by a service.

Usage

Create a new directory and in a main.go file add/define your events like follows and use the below func main() snippet

var genSchema map[string]generator.Schema{
    "event.name": {
			Schemas:    "http://json-schema.org/draft-07/schema#",
			Title:      "Your event name",
			Type:       "object",
			Required:   generator.GenerateRequired(YourEventStruct{}, nil),
			Properties: generator.GenerateProperties(YourEventStruct{}),
    },
    ...
}

func main() {
	path := flag.String("path", "/tmp/schemas/", "enter full path where to save schemas")
	help := flag.Bool("help", false, "print help/usage information")

	flag.Parse()

	if *help {
		flag.PrintDefaults()
		return
	}

	if err := schematic.BuildEvents(path, genSchema); err != nil {
		log.Fatalf("there was an error during file writing. Error: %s", err)
	}

	log.Printf("Schemas generated succssfully, located at: %s", *path)
}

By default the schemas will be generate to /tmp/schemas/ but this can be redefined as needed when the go program is executed by using the -path parameter.

Contributors

@endrit101 - Endrit Toplica

About

This tool generates JSON schemas from Go structs which can be used as event definition produced by a service.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages