-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Added JSON input validation for CLI commands #1771
base: main
Are you sure you want to change the base?
Conversation
summary += fmt.Sprintf("- %s\n", diag.Summary) | ||
} | ||
return fmt.Errorf("json input error:\n%v", summary) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there significance to normalizing before/after the ToTyped
call?
The conversion logic now lives in ToTyped
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pietern ToTyped seems not to return diagnostics for, for example, unknown fields while normalise do, hence the reason for extra call
Line: 1, | ||
Column: 1, | ||
} | ||
return newLoader().load(&root, loc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would it take to have real location information here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pietern this is what I am working on still, so TBD :)
@@ -33,7 +35,27 @@ func (j *JsonFlag) Unmarshal(v any) error { | |||
if j.raw == nil { | |||
return nil | |||
} | |||
return json.Unmarshal(j.raw, v) | |||
|
|||
dv, err := jsonloader.LoadJSON(j.raw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do the same for the YAML flag?
I believe that's the only reason we still depend on github.com/ghodss/yaml
. This package uses the json
tags in the types as opposed to yaml
tags, which the upstream YAML package uses. Since we use the json
tags as well in the dyn
package it should be possible to replace it.
Not blocking for this PR, of course.
Changes
Added JSON input validation for CLI commands
Relies on using
dyn
library.Fixes #1769 #1764
Tests
Added unit tests