danielgtaylor / huma

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

Feature: Accept valueless path/query/header/cookie tags #402

Open NorbertHauriel opened 4 months ago

NorbertHauriel commented 4 months ago

First of all thank you for building this package, I have just started using it and finding it fantastic.

What I think would be very useful and easy to implement, is to just accept tags without value, just like how encoding/json does, like this:

json:""

The above makes use of the struct field name, avoiding having to duplicate the same field name when we do not want to change it. You can call reflect.StructTag.Lookup instead of reflect.StructTag.Get. When Lookup returns true for its second value, we are processing the tag value be it empty or not. If empty, overwrite it with reflect.StructField.Name, otherwise do as it has been done before.