added comment for what to do about cycles in json schema

This commit is contained in:
Shreyas Goenka 2023-01-17 11:26:46 +01:00
parent 7385f37df6
commit 2a66a2fc74
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 19 additions and 14 deletions

View File

@ -7,12 +7,11 @@ import (
"strings"
)
const MaxHistoryOccurances = 3
// TODO: add tests for the error cases, forcefully triggering them
// TODO: Add support for refs in case of a cycle
// TODO: handle case of self referential pointers in structs
// TODO: add ignore for -
// TODO: Add tests for the error cases, forcefully triggering them
// TODO: Add ignore for -
// TODO: Add required validation for omitempty
// TODO: Add example documentation
// TODO: Do final checks for more validation that can be added to json schema
type Schema struct {
Type JavascriptType `json:"type"`
@ -32,6 +31,12 @@ type Item struct {
Properties map[string]*Property `json:"properties,omitempty"`
}
// NOTE about loops in golangType: Right now we error out if there is a loop
// in the types traversed when generating the json schema. This can be solved
// using $refs but there is complexity around making sure we do not create json
// schema's where properties indirectly refer to each other, which would be an
// invalid json schema. See https://json-schema.org/understanding-json-schema/structuring.html#recursion
// for more details
func NewSchema(golangType reflect.Type) (*Schema, error) {
seenTypes := map[reflect.Type]struct{}{}
debugTrace := list.New()