Add required condition

This commit is contained in:
Arpit Jasapara 2024-01-22 16:25:13 -08:00
parent 77116cf1cf
commit 699f7dd527
No known key found for this signature in database
GPG Key ID: F10F7691DDA7C0B9
2 changed files with 14 additions and 5 deletions

View File

@ -133,13 +133,16 @@ func (s *Schema) validatePattern(instance map[string]any) error {
}
func (s *Schema) validateConst(instance map[string]any) error {
for name, property := range s.Properties {
if property.Const == nil {
for k, v := range instance {
fieldInfo, ok := s.Properties[k]
if !ok {
continue
}
v, ok := instance[name]
if ok && v != property.Const {
return fmt.Errorf("expected value of property %s to be %v. Found: %v", name, property.Const, v)
if fieldInfo.Const == nil {
continue
}
if v != fieldInfo.Const {
return fmt.Errorf("expected value of property %s to be %v. Found: %v", k, fieldInfo.Const, v)
}
}
return nil

View File

@ -125,6 +125,12 @@ func (c *config) skipPrompt(p jsonschema.Property, r *renderer) (bool, error) {
return false, nil
}
var keys []string
for k := range p.Schema.SkipPromptIf.Properties {
keys = append(keys, k)
}
p.Schema.SkipPromptIf.Required = append(keys, p.Schema.SkipPromptIf.Required...)
validationErr := p.Schema.SkipPromptIf.ValidateInstance(c.values)
if validationErr != nil {
return false, nil