Skip to content

v0.13.0: Simplified Type API#122

Draft
zedrdave wants to merge 7 commits intomainfrom
refactor/simplified-type-api
Draft

v0.13.0: Simplified Type API#122
zedrdave wants to merge 7 commits intomainfrom
refactor/simplified-type-api

Conversation

@zedrdave
Copy link
Member

Summary

This PR introduces a cleaner, more intuitive type API with simplified type helper names.

Breaking Changes

Renamed type helpers (old names removed):

Old New
GetResponseData<Ops, Op> ApiResponse<Op>
GetRequestBody<Ops, Op> ApiRequest<Op>
GetPathParameters<Ops, Op> ApiPathParams<Op>
GetQueryParameters<Ops, Op> ApiQueryParams<Op>

Internal helpers (no longer exported):

  • isQueryMethod → internal
  • isMutationMethod → internal

Improvements

  • Removed types-documentation.ts - type documentation now inline
  • Simplified index.ts exports structure
  • Added inline JSDoc to QQueryOptions and QMutationOptions properties
  • Updated CLI to generate simplified type aliases
  • Removed direct components/operations type access from tests/examples
  • Added USAGE.md with concise usage examples

Migration Guide

Update your type imports and usage:

// Before (v0.12.x)
type Response = GetResponseData<OpenApiOperations, 'getPet'>
type Body = GetRequestBody<OpenApiOperations, 'createPet'>

// After (v0.13.0)
type Response = ApiResponse<OpType.getPet>
type Body = ApiRequest<OpType.createPet>

Test Results

  • 290 tests passing
  • Type checking passes
  • Linting clean

BREAKING CHANGES:
- Renamed type helpers to shorter, more intuitive names:
  - GetResponseData<Ops, Op> → ApiResponse<Op>
  - GetRequestBody<Ops, Op> → ApiRequest<Op>
  - GetPathParameters<Ops, Op> → ApiPathParams<Op>
  - GetQueryParameters<Ops, Op> → ApiQueryParams<Op>
- Old type names removed entirely (no backward compatibility)
- Made isQueryMethod/isMutationMethod internal (not exported)

Changes:
- Removed types-documentation.ts - docs now inline in types.ts
- Simplified index.ts exports
- Added inline JSDoc to QQueryOptions/QMutationOptions
- Updated CLI to generate simplified type aliases
- Removed direct components/operations type access from tests
- Added USAGE.md with concise usage examples
- Added readonly property handling tests
- Merged readonly-library-integration.test.ts into readonly-properties.test.ts
- Removed 13 duplicate tests
- Organized into logical describe blocks:
  - ApiResponse - Response Types
  - ApiRequest - Mutation Request Bodies
  - ApiPathParams and ApiQueryParams
  - OpType Namespace
  - Integration with useOpenApi
- Test count: 290 → 277 (removed duplicates)
- Verifies status can be omitted (optional)
- Verifies status accepts enum values ('available' | 'pending' | 'sold')
- Verifies invalid enum values are rejected
- Verifies optional chaining required when accessing status
BREAKING CHANGE:
- ApiResponse now makes ALL fields required regardless of 'required' status
- No null checks needed for any response fields
- Assumes reliable backend that always returns complete objects

New:
- ApiResponseSafe type for unreliable backends
- Only readonly fields required, others preserve optional status

This simplifies consumer code by eliminating null checks for response
fields that the server should always return.
- Updated all docs/manual/*.md files to use OperationId.X pattern
- Added import statements for OperationId where needed
- Updated JSDoc examples in src/types.ts and src/index.ts
- Ensures consistency across all documentation and examples
- CLI now generates api-enums.ts with const enum objects
- Enums named as {SchemaName}{PropertyName} in PascalCase
- Automatic deduplication of identical enum value sets
- Type-safe usage: PetStatus.Available instead of 'available'
- Added 7 new tests for enum extraction
- Updated USAGE.md and docs with enum examples
- Updated docs/manual/02-queries.md and 04-reactive-parameters.md
- Updated USAGE.md to use PetStatus enum
- Updated src/types.ts JSDoc examples
- Updated tests to use PetStatus enum
- Added api-enums.ts fixture for tests
- Fixed openapi-types.ts fixture to use 'adopted' instead of 'sold'
- Added backward compatibility test showing string literals still work
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