From 769d0921086ee5ca42d59890d59e512d8c6ec259 Mon Sep 17 00:00:00 2001 From: Arpit Jasapara Date: Tue, 23 Jan 2024 21:58:50 -0800 Subject: [PATCH] apply comments --- libs/jsonschema/instance.go | 15 +++------------ libs/template/config.go | 2 ++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libs/jsonschema/instance.go b/libs/jsonschema/instance.go index 6acd139b5..5bcbcc0aa 100644 --- a/libs/jsonschema/instance.go +++ b/libs/jsonschema/instance.go @@ -24,10 +24,7 @@ func (s *Schema) LoadInstance(path string) (map[string]any, error) { // We convert integer properties from float64 to int64 here. for name, v := range instance { propertySchema, ok := s.Properties[name] - if !ok { - continue - } - if propertySchema.Type != IntegerType { + if !ok || propertySchema.Type != IntegerType { continue } integerValue, err := toInteger(v) @@ -105,10 +102,7 @@ func (s *Schema) validateTypes(instance map[string]any) error { func (s *Schema) validateEnum(instance map[string]any) error { for k, v := range instance { fieldInfo, ok := s.Properties[k] - if !ok { - continue - } - if fieldInfo.Enum == nil { + if !ok || fieldInfo.Enum == nil { continue } if !slices.Contains(fieldInfo.Enum, v) { @@ -135,10 +129,7 @@ func (s *Schema) validatePattern(instance map[string]any) error { func (s *Schema) validateConst(instance map[string]any) error { for k, v := range instance { fieldInfo, ok := s.Properties[k] - if !ok { - continue - } - if fieldInfo.Const == nil { + if !ok || fieldInfo.Const == nil { continue } if v != fieldInfo.Const { diff --git a/libs/template/config.go b/libs/template/config.go index f23fef605..4173c4cd9 100644 --- a/libs/template/config.go +++ b/libs/template/config.go @@ -125,6 +125,8 @@ func (c *config) skipPrompt(p jsonschema.Property, r *renderer) (bool, error) { return false, nil } + // All fields referred to in a SkipPromptIf condition are implicitly made required and + // we diverge from strictly following the JSON schema because it makes the author UX better. var keys []string for k := range p.Schema.SkipPromptIf.Properties { keys = append(keys, k)