-
-
Notifications
You must be signed in to change notification settings - Fork 152
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: treat encoding.TextUnmarshaler as string in schema #550
Conversation
WalkthroughThe recent changes introduce support for types that implement the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant Registry
participant SchemaHandler
Client->>Server: Request with custom type
Server->>Registry: Handle request
Registry->>SchemaHandler: Generate schema
SchemaHandler-->>Registry: Return schema
Registry-->>Server: Return response
Server-->>Client: Send response with data
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #550 +/- ##
=======================================
Coverage 92.75% 92.76%
=======================================
Files 22 22
Lines 3879 3883 +4
=======================================
+ Hits 3598 3602 +4
Misses 236 236
Partials 45 45 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- registry.go (2 hunks)
- schema.go (3 hunks)
- schema_test.go (2 hunks)
Additional comments not posted (5)
registry.go (1)
96-100
: LGTM: Handleencoding.TextUnmarshaler
types as strings.The addition correctly identifies types implementing
encoding.TextUnmarshaler
and treats them as strings, aligning with the PR objectives to simplify schema handling for custom types.schema.go (1)
704-710
: LGTM: Treatencoding.TextUnmarshaler
as strings inschemaFromType
.The implementation correctly treats types implementing
encoding.TextUnmarshaler
as strings, enhancing the schema's ability to handle diverse data types.schema_test.go (3)
1176-1176
: LGTM: Define custom date typeMyDate
.The definition of
MyDate
as a type alias fortime.Time
is appropriate for implementing custom unmarshalling behavior.
1178-1185
: LGTM: ImplementUnmarshalText
forMyDate
.The method correctly parses RFC3339 date strings and assigns them to
MyDate
, ensuring seamless integration withencoding.TextUnmarshaler
.
1189-1202
: LGTM: TestMyDate
integration with schema.The test successfully verifies that
MyDate
can be unmarshalled from JSON and is represented as a string in the schema, confirming the intended behavior.
This PR causes the JSON Schema generation/validation functionality in Huma to treat custom types which implement
encoding.TextUnmarshaler
as astring
type by default. This makes it easier to wrap known types and do things like create your own custom date/time type.This behavior can be escaped by implementing
huma.SchemaProvider
for your type.Fixes #471
Summary by CodeRabbit
New Features
TextUnmarshaler
interface, allowing more efficient schema handling for specific data types.MyDate
, which can parse RFC3339 formatted date strings.Bug Fixes
MyDate
as a string type when unmarshalling JSON data.Tests
MyDate
type.