danielgtaylor / huma

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

custom validation tags with constraints specified in the spec. #487

Open nguyen0096 opened 3 months ago

nguyen0096 commented 3 months ago

Currently, for example, I put tag maxLength:"3", Huma will validate to input Body and also put a text in spec to indicate the constraint.

image

I can add validation logic with Resolve method but is there anyway that I can:

Thanks! You guys created a great repository btw.

danielgtaylor commented 1 month ago

@nguyen0096 this isn't currently possible:

  1. There is no way to link custom tags with custom validation logic right now. This is a feature we could consider adding or enabling it to be added by others easily by hooking into the validation phase of the request.
  2. The <= 3 characters text is generated by the documentation tool based on the JSON Schema which has a field like "minimum": 3 within it. I don't think you can modify this easily but I'm not sure, take a look at https://github.com/stoplightio/elements. You can also consider different documentation tools, see https://huma.rocks/features/api-docs/#customizing-documentation