danielgtaylor / huma

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

Allow custom Transform for nested objects #404

Closed nunoo closed 5 months ago

nunoo commented 5 months ago

We implement the json.Marshaler interface on some objects that are present in some of our response bodies. However huma can't reasonably decipher what the final response looks like. Is there a way we could annotate a (nested) type either with an additional method to implement some interface so we can tell huma how to generate the docs?

The problem is go doesn't support embedding generics, so we implement Marshal to remove the intermediate field name. Huma optionally would never even need to call the method itself, just use it to determine the output type for documentation.

danielgtaylor commented 5 months ago

@nunoo have you tried implementing a huma.SchemaProvider for the type? See https://huma.rocks/features/schema-customization/#field-schema

nunoo commented 5 months ago

Thanks a lot that's exactly what I needed, I appreciate the quick response!