Skip to content

Added a duration type fix - #166

Merged
djthorpe merged 1 commit into
mainfrom
djt/0726/duration
Jul 26, 2026
Merged

Added a duration type fix#166
djthorpe merged 1 commit into
mainfrom
djt/0726/duration

Conversation

@djthorpe

Copy link
Copy Markdown
Member

This pull request improves support for custom types derived from time.Duration that implement their own MarshalJSON method. Previously, such types were incorrectly rendered as integers in generated JSON schemas rather than as duration strings. The changes ensure these types are correctly identified and their schema is set to "string" with format "duration". Several regression tests are added to verify this behavior.

Custom duration type handling:

  • Added the isDurationLikeType function to detect named types derived from time.Duration that implement json.Marshaler, ensuring they are treated as duration strings in schemas.
  • Updated applySpecialTypeSchema and marshalDefault to use isDurationLikeType, so custom duration types are rendered with type "string" and format "duration". [1] [2]

Testing improvements:

  • Introduced the customDuration type and customDurationStruct for testing, simulating a common pattern where packages define local duration types with custom JSON marshaling.
  • Added regression tests (TestFor_CustomDuration_TopLevel and TestFor_CustomDuration_StructField) to verify that custom duration types are properly handled in both top-level and struct field contexts.

@djthorpe djthorpe self-assigned this Jul 26, 2026
Copilot AI review requested due to automatic review settings July 26, 2026 11:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@djthorpe
djthorpe merged commit 73804ea into main Jul 26, 2026
1 check failed
@djthorpe
djthorpe deleted the djt/0726/duration branch July 26, 2026 11:37
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.

2 participants