danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.71k stars 134 forks source link

Response struct without a "Body" field is silently ignored if using Register #481

Open RangelReale opened 1 month ago

RangelReale commented 1 month ago

If we register an operation where the output struct don't have a "Body" field, the output is completely ignored and nothing is written to the http connection.

This is a surprising behavior, maybe Register should panic if the output structure don't have this field? This will for sure generate nasty bugs in big codebases.

outofthisworld commented 1 month ago

If we register an operation where the output struct don't have a "Body" field, the output is completely ignored and nothing is written to the http connection.

This is a surprising behavior, maybe Register should panic if the output structure don't have this field? This will for sure generate nasty bugs in big codebases.

Also just to add to this, all of the fields in the struct will automatically become 'headers'. Which you can see in the docs

In addition, returning nil as a response body causes the package to error due to some Serialization issue. Now you could argue you should be instead returning No Content, however I don't necessarily agree because you could be expecting a pointer to something, return it, oops accidently nil and then get a 500.