-
-
Notifications
You must be signed in to change notification settings - Fork 556
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
Goa not enforcing required attribute #3318
Comments
I believe what's happening here is that the Goa generated CLI uses the service type to load the JSON passed on the command line. Because the attribute is required the corresponding field does not use a pointer and so defaults to 0. So the server gets an object with the field set to 0, it is not missing and validation does not fail. To convince yourself use another client tool (e.g. |
That was what I was afraid was happening - is there a way to avoid this besides not using |
This is just the CLI code behaving that way when loading bodies from the JSON in the terminal - not the underlying server or client packages so any service making use of these packages won't have this issue. |
Understood, but one of the reasons I'd like to use goa is that it will generate both the cli and server for me. Having to write/maintain a CLI separately from the goa-generated one is taking away one of the main selling points for me. I will look into some of the other validation functions to see if I can work around it in the short term, but would love to see if there is a better long term fix. Similar to #687 |
Makes sense, I'd be happy to consider / help putting together a PR that improved this. We may need to generate special types for the CLI instead of relying on the existing service level types to perform that kind of validation. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
You'll see that I've defined the attribute
UnitsGranted
, which is anInt64
that is a required attribute inVestingPlanRequest
. The Service, Type and generated code definitions look good, but when I go to run the CLI and server, theRequired
function seems to not be enforcing anything and it's just being passed through as0
with no input validation. What am I missing here?Service Definition
Type Definition
Generated code
Running my CLI
Logs on the Server side
The text was updated successfully, but these errors were encountered: