Skip to content

fix(csharp): emit millisecond precision for nullable datetime params in mock tests#16019

Merged
patrickthornton merged 1 commit into
mainfrom
patrick/csharp/fix-mock-test-nullable-datetime-millis
May 20, 2026
Merged

fix(csharp): emit millisecond precision for nullable datetime params in mock tests#16019
patrickthornton merged 1 commit into
mainfrom
patrick/csharp/fix-mock-test-nullable-datetime-millis

Conversation

@patrickthornton
Copy link
Copy Markdown
Contributor

Closes FER-10694

Summary

Generated C# mock-server tests for nullable date-time query/header parameters were producing WithParam("since", "2024-01-15T09:30:00Z") (no millis) while the SDK runtime serializes DateTime with yyyy-MM-ddTHH:mm:ss.fffK and actually sends 2024-01-15T09:30:00.000Z. WireMock requires exact match → 404.

Root cause: getDateTime in MockEndpointGenerator.ts only unwrapped container.optional. When the IR wraps a date-time in container.nullable (common with respect-nullable-schemas: true + coerce-optional-schemas-to-nullable: false), it returned undefined and the test fell back to the raw value.jsonExample string, which omits millis.

Example

Found while debugging auth0-teams-csharp-sdk CI: Activity.ListTest failed with Auth0.TeamsApiException : Error with status code 404. The IR for the since parameter walked as container.optional → container.nullable → named.alias → primitive.datetime. The nullable step short-circuited the recursion.

Before/after for that generated test:

// Before
.WithParam("since", "2024-01-15T09:30:00Z")
.WithParam("until", "2024-01-15T09:30:00Z")

// After
.WithParam("since", "2024-01-15T09:30:00.000Z")
.WithParam("until", "2024-01-15T09:30:00.000Z")

Fix:

case "container": {
    const container = exampleTypeReference.shape.container;
    if (container.type === "optional") {
        return container.optional == null ? undefined : this.getDateTime(container.optional);
    }
    if (container.type === "nullable") {
        return container.nullable == null ? undefined : this.getDateTime(container.nullable);
    }
    return undefined;
}

Test plan

  • pnpm turbo run compile --filter @fern-api/fern-csharp-sdk — clean
  • pnpm turbo run test --filter @fern-api/fern-csharp-sdk — 41/41 pass
  • Re-ran seed on auth0-teams-csharp config; dotnet test --filter FullyQualifiedName~Activity.ListTest now passes 2/2 (was 0/2)
  • No existing csharp-sdk seed snapshots use the bare Z form, so no fixture churn expected

🤖 Generated with Claude Code

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions
Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-05-20T05:20:23Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
csharp-sdk square 67s (n=5) 105s (n=5) 79s +12s (+17.9%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-05-20T05:20:23Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-05-20 21:13 UTC

@patrickthornton patrickthornton merged commit d0ea2b6 into main May 20, 2026
115 of 134 checks passed
@patrickthornton patrickthornton deleted the patrick/csharp/fix-mock-test-nullable-datetime-millis branch May 20, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants