lerenn / asyncapi-codegen

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!
Apache License 2.0
99 stars 22 forks source link

Wrong usage for validator's `required` directive #259

Closed TheSadlig closed 2 months ago

TheSadlig commented 2 months ago

Hello,

The definition for required in the asyncapi specification, and the validator's required are different:

Because of this behaviour, the validator cannot be used to validate most structs.

What I would recommend:

  1. Remove required for non-pointer fields
  2. Add a flag to force all fields to be generated as pointer.

Without the point 2., we have no way of knowing whether the incoming message was absent or not, since non-pointer struct will be initialized with empty/zero-value. This could be the default behaviour (in a future version ?), but since this would have large impacts on users, I figured having it opt-in was best for now

Thanks

lerenn commented 2 months ago

Hi @TheSadlig, thanks for the issue :)

For this version, a flag is indeed better and in a future version it could be a default behavior.

Feel free to propose a PR if you need this, as I don't have a lot of time in my hands actually.