Skip to content

fix: apply default tags via TextUnmarshaler - #1126

Open
vulragrag-star wants to merge 1 commit into
danielgtaylor:mainfrom
vulragrag-star:fix/680-default-text-unmarshaler
Open

vulragrag-star wants to merge 1 commit into
danielgtaylor:mainfrom
vulragrag-star:fix/680-default-text-unmarshaler

Conversation

@vulragrag-star

Copy link
Copy Markdown

Summary

Types that implement encoding.TextUnmarshaler are modeled as strings in the schema, but convertType still used reflect.Convert for default tags. That panicked for wrappers such as a duration type with default:"10s" (schema type string, Go type not a string).

Changes

  • Unmarshal string defaults through TextUnmarshaler in convertType for runtime defaults
  • Keep the schema default in wire string form for OpenAPI (jsonTag)
  • Add tests covering convertType, findDefaults, and SchemaFromField for TextUnmarshaler defaults

Fixes #680

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.20%. Comparing base (ef50837) to head (88bb960).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1126      +/-   ##
==========================================
+ Coverage   93.19%   93.20%   +0.01%     
==========================================
  Files          24       24              
  Lines        5008     5021      +13     
==========================================
+ Hits         4667     4680      +13     
  Misses        273      273              
  Partials       68       68              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vulragrag-star
vulragrag-star force-pushed the fix/680-default-text-unmarshaler branch from 758b858 to e4978cc Compare October 1, 2026 12:36
@vulragrag-star

Copy link
Copy Markdown
Author

Added tests for pointer convertType path and invalid TextUnmarshaler defaults.
Tip: e4978cc1f6782f69ffe3c0dcd59cb8b5eea8b538.

@robtme

robtme commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Hey @vulragrag-star! I haven't properly reviewed this yet, but please move the tests into an existing test file rather than creating a new one. Thank you!

Types that implement encoding.TextUnmarshaler are modeled as strings in
the schema, but convertType still used reflect.Convert for default tags.
That panicked for wrappers such as a duration type with default:"10s".

Unmarshal string defaults through TextUnmarshaler for runtime defaults,
and keep the schema default in wire string form for OpenAPI.

Fixes danielgtaylor#680
@vulragrag-star

Copy link
Copy Markdown
Author

Moved the TextUnmarshaler default tests into huma_internal_test.go (existing package huma file).
Tip: 88bb96081eab7a7eace79e228f842deb144bd3a6.

@vulragrag-star
vulragrag-star force-pushed the fix/680-default-text-unmarshaler branch from e4978cc to 88bb960 Compare October 2, 2026 00:41

This branch has not been deployed

No deployments
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.

Setting default for non-string type with string schema panics

2 participants