apply comments

This commit is contained in:
Arpit Jasapara 2024-01-23 21:58:50 -08:00
parent 699f7dd527
commit 769d092108
No known key found for this signature in database
GPG Key ID: F10F7691DDA7C0B9
2 changed files with 5 additions and 12 deletions

View File

@ -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 {

View File

@ -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)