Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andrewnester
Copy link
Contributor

Changes

Added JSON input validation for CLI commands

Relies on using dyn library.

Fixes #1769 #1764

Tests

Added unit tests

summary += fmt.Sprintf("- %s\n", diag.Summary)
}
return fmt.Errorf("json input error:\n%v", summary)
}
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI "invalid character" error message when issuing valid jobs create command
2 participants