Skip to content

Use offsets in datetime validators#68

Merged
RawToast merged 3 commits intomasterfrom
datetime-offset
Feb 16, 2026
Merged

Use offsets in datetime validators#68
RawToast merged 3 commits intomasterfrom
datetime-offset

Conversation

@RawToast
Copy link
Copy Markdown
Owner

@RawToast RawToast commented Feb 16, 2026

Summary by CodeRabbit

  • New Features
    • Added dateTimeOffset configuration (default: enabled) to control timezone-offset validation for datetime fields when strictDates is enabled; configurable globally or per-schema.
  • New Specs
    • Added a DateTime Offset test OpenAPI spec exercising account and API-key endpoints and DateTime/Account/ApiKey schemas.
  • Tests
    • Updated and expanded tests to cover offset behavior, CLI help, and config permutations.
  • Chores
    • Package version bumped.

…idation

When strictDates is enabled, dateTimeOffset controls whether datetime schemas
generate z.string().datetime({ offset: true }) (accepting both 'Z' and '+HH:MM')
or z.string().datetime() (accepting only 'Z'). Defaults to true.

Supports boolean (all-or-nothing) and string[] (per-schema) control.
…maName

Separate ownName from currentSchemaName in getZodTypeFromSchema so that
dateTimeOffset array matching only applies to top-level named schemas,
not to inline properties inside object schemas. Previously, an object
schema named 'Account' in the dateTimeOffset array would incorrectly
apply offset to its inline date-time properties.

Also adds dateTimeOffset to CLI help text and integration tests for CLI
config pass-through and empty array edge case.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

Adds a dateTimeOffset option (boolean | string[]) controlling whether Zod datetime validators include timezone offsets when strictDates is enabled; integrates the option across specs, CLI, config schema, core schema generation, and tests.

Changes

Cohort / File(s) Summary
Specs Addition
packages/specs/index.ts, packages/specs/resources/datetime-offset.yaml
Adds a new OpenAPI spec (datetime-offset.yaml) and exports dateTimeOffsetYamlPath in specs index.
Core Schema Generation
packages/zenko/src/core/schema-generator.ts, packages/zenko/src/zenko.ts, packages/zenko/src/core/__tests__/schema-generator.test.ts
Adds dateTimeOffset to SchemaOptions/GenerateOptions; threads an ownName naming context through getZodTypeFromSchema and buildString so datetime validators can conditionally use { offset: true }. Tests added/updated for behavior.
CLI & Config Integration
packages/zenko/src/cli.ts, packages/zenko/zenko-config.schema.json, packages/zenko/package.json
Extends CLI config entry and JSON schema with `dateTimeOffset?: boolean
Tests & Expectations
packages/zenko/src/__tests__/cli.test.ts, packages/zenko/src/__tests__/config-options.test.ts, packages/zenko/src/__tests__/petstore.test.ts
Updates expectations to use z.string().datetime({ offset: true }) by default under strictDates; adds tests covering dateTimeOffset true/false, per-schema lists, and edge cases.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI / Config
    participant Runner as generateWithMetadata
    participant SchemaGen as schema-generator
    participant Builder as buildString
    participant Zod as Zod Output

    CLI->>Runner: pass dateTimeOffset
    Runner->>SchemaGen: build SchemaOptions (dateTimeOffset, strictDates)
    SchemaGen->>SchemaGen: getZodTypeFromSchema(schema, ..., ownName)
    SchemaGen->>Builder: buildString(schema, SchemaOptions, schemaName)
    alt strictDates AND dateTimeOffset applies
        Builder->>Zod: z.string().datetime({ offset: true })
    else
        Builder->>Zod: z.string().datetime()
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through schemas, nibbling time's seam,
Added offsets so timestamps can dream.
From CLI to Zod, the option took flight,
Now datetimes wear zones and sleep snug at night. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master
Title check ✅ Passed The title 'Use offsets in datetime validators' clearly and accurately describes the main change in the changeset, which adds datetime offset support throughout the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch datetime-offset

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.34%. Comparing base (11d77bd) to head (d95481b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   97.32%   97.34%   +0.02%     
==========================================
  Files          16       16              
  Lines        2171     2188      +17     
==========================================
+ Hits         2113     2130      +17     
  Misses         58       58              

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/zenko/src/zenko.ts`:
- Line 104: The defaulting of dateTimeOffset to true causes
z.string().datetime({ offset: true }) for existing strictDates users and expands
allowed inputs; change the default behavior so existing users keep the previous
validation: set dateTimeOffset to false (or undefined) unless explicitly
enabled, and ensure the code path that builds the schema (the place using
dateTimeOffset when strictDates is true to call z.string().datetime(...)) only
passes { offset: true } when the user explicitly requested offset support;
update references to dateTimeOffset and strictDates (and the z.string().datetime
call) accordingly and add a brief changelog note if you intend to keep a
behavior change.

@RawToast RawToast changed the title Add Datetime offset support Use offsets in datetime validators Feb 16, 2026
@RawToast RawToast merged commit bde054d into master Feb 16, 2026
6 checks passed
@RawToast RawToast deleted the datetime-offset branch February 16, 2026 05:17
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.

1 participant