Skip to content

Adopt auto-generated TypeScript clients from OpenAPI spec #81

@scotwells

Description

@scotwells

Summary

The search service uses openapi-ts to auto-generate TypeScript clients from its OpenAPI spec, while activity manually maintains TypeScript types in ui/src/types/. We should evaluate aligning on the auto-generated approach for consistency and reduced maintenance burden.

Current State

Activity (manual types):

  • Hand-written TypeScript types in ui/src/types/activity.ts, ui/src/types/policy.ts, etc.
  • Types must be manually kept in sync with Go API types
  • OpenAPI uses default naming (with ~1 URL encoding for slashes)

Search (auto-generated):

  • Uses openapi-ts to generate TypeScript clients from OpenAPI spec
  • Uses ToRESTFriendlyName for clean schema names (dots instead of ~1)
  • Types automatically stay in sync with Go API changes

Required Changes

If we adopt auto-generation:

  1. Add ToRESTFriendlyName to OpenAPI config in cmd/activity/main.go:

    genericConfig.OpenAPIV3Config.GetDefinitionName = func(name string) (string, spec.Extensions) {
        friendlyName, extensions := namer.GetDefinitionName(name)
        return openapiutil.ToRESTFriendlyName(friendlyName), extensions
    }
    genericConfig.OpenAPIV3Config.Definitions = nil  // Force re-computation (see datum-cloud/search#64)
  2. Add openapi-ts generation to the build pipeline

  3. Replace manual types in ui/src/types/ with generated ones

Trade-offs

Pros:

  • Single source of truth (Go types)
  • Types always in sync after code generation
  • Consistent approach across services
  • Less manual maintenance

Cons:

  • Generated types may need wrapper types for UI-specific concerns
  • Additional build step dependency
  • Migration effort for existing UI code

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions