correct typo and some comments

This commit is contained in:
Shreyas Goenka 2023-01-17 13:43:50 +01:00
parent e79c52ff37
commit cc350f761a
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 9 additions and 4 deletions

View File

@ -43,6 +43,7 @@ import (
type: object type: object
properties: {} properties: {}
} }
for details visit: https://json-schema.org/understanding-json-schema/reference/object.html#properties
*/ */
type Schema struct { type Schema struct {
Type JavascriptType `json:"type"` Type JavascriptType `json:"type"`
@ -53,13 +54,13 @@ type Schema struct {
type Property struct { type Property struct {
Type JavascriptType `json:"type"` Type JavascriptType `json:"type"`
Items *Item `json:"items,omitempty"` Items *Items `json:"items,omitempty"`
Properties map[string]*Property `json:"properties,omitempty"` Properties map[string]*Property `json:"properties,omitempty"`
AdditionalProperties *Property `json:"additionalProperties,omitempty"` AdditionalProperties *Property `json:"additionalProperties,omitempty"`
Required []string `json:"required,omitempty"` Required []string `json:"required,omitempty"`
} }
type Item struct { type Items struct {
Type JavascriptType `json:"type"` Type JavascriptType `json:"type"`
Properties map[string]*Property `json:"properties,omitempty"` Properties map[string]*Property `json:"properties,omitempty"`
Required []string `json:"required,omitempty"` Required []string `json:"required,omitempty"`
@ -188,6 +189,8 @@ func addStructFields(fields []reflect.StructField, golangType reflect.Type) []re
return fields return fields
} }
// TODO: see what kind of schema will be generated for interface{}
// params: // params:
// golangType: golang type for which json schema properties to generate // golangType: golang type for which json schema properties to generate
// seenTypes : set of golang types already seen in path during recursion. // seenTypes : set of golang types already seen in path during recursion.
@ -212,7 +215,7 @@ func toProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, de
} }
// case array/slice // case array/slice
var items *Item var items *Items
if golangType.Kind() == reflect.Array || golangType.Kind() == reflect.Slice { if golangType.Kind() == reflect.Array || golangType.Kind() == reflect.Slice {
elemGolangType := golangType.Elem() elemGolangType := golangType.Elem()
elemJavascriptType, err := javascriptType(elemGolangType) elemJavascriptType, err := javascriptType(elemGolangType)
@ -223,7 +226,7 @@ func toProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, de
if err != nil { if err != nil {
return nil, err return nil, err
} }
items = &Item{ items = &Items{
// TODO: Add a test for slice of object // TODO: Add a test for slice of object
Type: elemJavascriptType, Type: elemJavascriptType,
Properties: elemProps.Properties, Properties: elemProps.Properties,
@ -238,6 +241,8 @@ func toProperty(golangType reflect.Type, seenTypes map[reflect.Type]struct{}, de
if golangType.Key().Kind() != reflect.String { if golangType.Key().Kind() != reflect.String {
return nil, fmt.Errorf("only string keyed maps allowed") return nil, fmt.Errorf("only string keyed maps allowed")
} }
// TODO: Add a test for map of maps, and map of slices. Check that there
// is already a test for map of objects and map of primites
additionalProperties, err = safeToProperty(golangType.Elem(), seenTypes, debugTrace) additionalProperties, err = safeToProperty(golangType.Elem(), seenTypes, debugTrace)
if err != nil { if err != nil {
return nil, err return nil, err