Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom field schemas; add omittable example #145

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

danielgtaylor
Copy link
Owner

This PR adds an optional huma.SchemaProvider interface, which a type can implement to provide its own custom JSON Schema, disabling the built-in schema generator and enabling customized behavior for request/response body fields.

When combined with custom serialization logic, this can enable use-cases like determining whether a field was sent at all, is null, or is a value. A new example is added to showcase this functionality.

As part of this work, a small change in huma.go is made to properly set the operation.requestBody.required OpenAPI field, and this field is then later checked to determine whether the body is required. This works much better with custom operation schemas, which would not be required before even when that field was set.

Fixes #137.

@danielgtaylor danielgtaylor merged commit fbc1a70 into main Oct 20, 2023
3 checks passed
@danielgtaylor danielgtaylor deleted the custom-field-schema branch October 20, 2023 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support nullable type
1 participant