Skip to content

feat(core): add formatType config for custom string format types - #3727

Draft
chrisahardie wants to merge 3 commits into
orval-labs:masterfrom
chrisahardie:feat/format-type-config
Draft

feat(core): add formatType config for custom string format types#3727
chrisahardie wants to merge 3 commits into
orval-labs:masterfrom
chrisahardie:feat/format-type-config

Conversation

@chrisahardie

Copy link
Copy Markdown
Contributor

Partially solves #1939

Summary

Adds override.formatType — a config that maps any OpenAPI string format (e.g. date, date-time, uuid, email) to a custom TypeScript type, with integrated support across Zod schemas, Effect schemas, faker mocks, and factory defaults.

Motivation

Users working with Temporal API, dayjs, branded types, or domain-specific formats have no way to override the generated type for string formats beyond the binary useDates flag. This feature generalizes type mapping to any format string, with full control over imports, Zod validation, mock generation, and factory defaults.

Config shape

override: {
  formatType: {
    'date-time': {
      type: 'Dayjs',
      import: { name: 'Dayjs', importPath: 'dayjs' },
      zod: {
        transform: 'dayjs',
        transformImport: { name: 'dayjs', importPath: 'dayjs', default: true },
      },
      mock: 'dayjs(faker.date.past())',
      mockImport: { name: 'dayjs', importPath: 'dayjs', default: true },
    },
    date: { type: 'Temporal.PlainDate' },
    uuid: { type: 'UUID', import: { name: 'UUID', importPath: '@company/types' } },
  },
}

What's NOT in scope

Runtime response deserialization and request body serialization are deliberately excluded. These are orthogonal concerns being addressed separately (see #1939).

chrishardie-cyber and others added 3 commits July 14, 2026 16:54
Map any OpenAPI string format to a custom TypeScript type via
override.formatType. Supports type+import, Zod transform/codec
replacement, and mock expression overrides. Uses StringFormat =
'date' | 'date-time' | 'time' | (string & {}) for autocomplete.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Moves the dayjs dependency from the root package.json catalog to a
pinned version in tests/package.json, since it's only needed for
formatType test fixtures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Restore unconditional date/date-time branch in buildPrimitivePayload
  and buildDefaultPayload so factory methods emit ISO date strings when
  neither formatType nor useDates is set (was regressed to empty string)
- Guard Zod formatType lookup against undefined schema.format matching
  empty-string key
- Document Zod transform and Effect limitations in formatType docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addeddayjs@​1.11.2110010010086100

View full report

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