8000 Use Zod v4 as Source of Truth for Configuration Schema · Issue #1459 · onetimesecret/onetimesecret · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Use Zod v4 as Source of Truth for Configuration Schema #1459
Open
3 of 6 issues completed
Open
Feature
3 of 6 issues completed
@delano

Description

@delano

We want to modernize our configuration management by leveraging Zod v4's native JSON Schema conversion feature to use Zod as the primary schema definition while generating JSON Schema for Ruby backend compatibility.

Description

Currently we're considering implementing a unified configuration schema approach. We'd like to explore using Zod v4 as the source of truth for our configuration schema, taking advantage of the new native z.toJSONSchema() function to generate the JSON Schema that Ruby consumes during startup validation.

This approach would provide better TypeScript developer experience while maintaining full compatibility with our Ruby configuration validation needs. We already have extensive Zod schemas for system settings in our API layer that we can build upon.

TODO

  • Upgrade to Zod v4 to access native JSON Schema conversion
  • Create unified Zod configuration schema in src/schemas/config.ts
  • Leverage existing systemSettingsSchema from colonel API endpoints
  • Implement build script using z.toJSONSchema() to generate etc/config.schema.json
  • Update Ruby configuration loading to use generated JSON Schema
  • Add schema generation to build pipeline with verification
  • Update documentation in etc/README.md
  • Migrate existing Ruby DEFAULTS hash to use generated defaults
  • Migrate OT::Config from module to class
  • Provide facility to re-merge static and dynamic config on the fly
  • Provide facility for "unmodifiable" static config for the lifetime of the process. So if OT.conf remains the entry point for the full merged static+dynamic configuration, we can use something like OT::Config.static or OT::Config.static_configuration as the frozen hash we use when we merge with dynamic configuration.

Technical Considerations

  • Native Conversion: Zod v4's z.toJSONSchema() eliminates third-party dependency and provides better conversion fidelity
  • Schema Integration: Build upon existing systemSettingsSchema and related schemas already defined in src/schemas/api/endpoints/colonel.ts
  • Default Value Extraction: Leverage JSON Schema defaults generation to replace Ruby DEFAULTS hash
  • Build Pipeline: Ensure generated schema is validated in CI and committed for Ruby consumption
  • Backward Compatibility: Maintain compatibility with existing Ruby configuration validation logic
Existing Schema Foundation

We already have comprehensive Zod schemas for system settings including:

  • Interface configuration (UI/API settings, branding, navigation)
  • Secret options and TTL settings
  • Mail/Truemail configuration
  • Diagnostics and Sentry integration
  • Rate limiting configuration
  • Colonel/admin functionality

These can serve as the foundation for our unified configuration schema.

Opportunities for Improvement

  • Zero Dependencies: Native JSON Schema conversion eliminates external library dependency
  • Type Safety: Full TypeScript intellisense and validation throughout configuration handling
  • Schema Reuse: Leverage existing API endpoint schemas for consistent validation
  • Single Source of Truth: Eliminate schema drift between frontend API validation and backend config validation
  • Better Developer Experience: Zod's composition features enable cleaner schema organization

References

https://zod.dev/json-schema

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiIssues related to the API functionality or documentation.configUpdates to configuration files, environment settings, or build parametersdocumentationIssues or pull requests related to documentation.dxImprovements to developer experience, tooling, code organization, or documentationfrontendVue + Tailwind appimprovementIssues or pull requests that involve improvements to the project.typescriptPull requests that update typescript code

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0