Skip to content

chore: release v0.19.0#138

Merged
zedrdave merged 5 commits intomainfrom
feature/query-safe-response-by-default
Feb 28, 2026
Merged

chore: release v0.19.0#138
zedrdave merged 5 commits intomainfrom
feature/query-safe-response-by-default

Conversation

@zedrdave
Copy link
Copy Markdown
Member

@zedrdave zedrdave commented Feb 28, 2026

Summary

Release v0.19.0 with improved response type semantics and optimized import handling.

Changes

Added

  • Unified Response Types: All responses (GET, POST, PATCH, DELETE) now use a single, consistent type
  • Strict Response Option: New --use-strict-response CLI flag to control whether all fields are required
    • Default: ApiResponse (ALL fields required, matches typical API behavior)
    • Opt-in: ApiResponseStrict (only readonly/required fields required)

Fixed

  • Import Optimization: Generated API client files now import only the required response type (ApiResponse or ApiResponseStrict) instead of always importing both, preventing noUnusedLocals lint errors in strict TypeScript projects
  • Semantic Clarity: Clarified that readonly fields only affect request bodies (mutations), not response types
  • Documentation: Updated all help text and README examples to reflect correct type semantics

Changed

  • Breaking: Removed ApiResponseSafe type (use ApiResponseStrict instead)
  • Breaking: Removed --use-query-safe-response flag (replaced with --use-strict-response)
  • Response typing is now consistent across ALL operations regardless of HTTP method

Related Issues

  • Addresses Copilot review feedback on unused import handling
  • Based on feature/query-safe-response-by-default branch

Testing

  • All 342 tests passing
  • Validated with npm run lint, npm run types, npm run test:run

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prepares the v0.19.0 release of the library and introduces a new CLI flag intended to control “query-safe” (readonly-required) response typing for GET operations during code generation.

Changes:

  • Add --use-query-safe-response / --no-use-query-safe-response option parsing, help text, and plumbing into api-types.ts generation.
  • Bump package version to 0.19.0 and update README npm badge.
  • Add a 0.19.0 entry to the changelog.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/cli.ts Adds the new CLI flag, updates usage text, and passes the flag into generateApiTypesContent.
package.json Version bump to 0.19.0.
package-lock.json Lockfile version metadata updated to 0.19.0.
README.md Updates npm badge cache-busting version parameter to 0.19.0.
CHANGELOG.md Adds the 0.19.0 release entry documenting the new flag.

@zedrdave zedrdave force-pushed the feature/query-safe-response-by-default branch from dd7ad86 to 145d65b Compare February 28, 2026 10:51
- Remove --no-exclude flag, use --exclude-prefix false instead
- Add --use-query-safe-response flag (default: true) to automatically return ApiResponseSafe for useQuery
- All fields required for GET responses (assumes API shares schema for POST/PATCH and GET)
- Add searchPets operation to toy-openapi.json for consistent test generation
- Update tests to include new searchPets operation

Changes:
- CLI: --exclude-prefix 'false' disables exclusion (instead of --no-exclude)
- CLI: --use-query-safe-response enables ApiResponseSafe for queries (default)
- CLI: --no-use-query-safe-response disables for cases where readonly fields aren't distinguished
- Updated help text with documentation on semantic distinction
- Regenerated test fixtures with searchPets and default ApiResponseSafe
@zedrdave zedrdave force-pushed the feature/query-safe-response-by-default branch from 145d65b to edc0370 Compare February 28, 2026 11:21
Use --use-query-safe-response false instead to disable
Updated type semantics based on requirements:

- ApiResponseSafe (GET/useQuery): Now requires ALL fields including optional
  * Assumes API shares schema for POST/PATCH and GET
  * Server always returns all fields for GET operations

- ApiResponse (POST/PATCH/useMutation): Excludes readonly, preserves optional
  * Readonly fields excluded (client cannot set them)
  * Optional fields observed as per OpenAPI spec

Changes:
- Renamed RequireReadonly to ExcludeReadonly (now excludes readonly fields)
- ApiResponse now uses ExcludeReadonly instead of RequireAll
- ApiResponseSafe now uses RequireAll (makes ALL fields required)
- Updated all documentation and help text to reflect correct semantics
- Updated README examples
- Regenerated test fixtures with updated comments

This is a breaking change as ApiResponseSafe now requires optional fields
that were previously optional.
Major semantic fix based on correct requirements:

1. ALL responses (GET, POST, PUT, PATCH, DELETE) now use the SAME type
2. By DEFAULT, ApiResponse makes ALL fields required (assumes server always returns everything)
3. NEW --use-strict-response flag for ApiResponseStrict (only readonly/required fields required)
4. Readonly ONLY affects request bodies (mutations), NOT response types

Type Changes:
- ApiResponse (default): ALL fields required for ALL responses
- ApiResponseStrict (opt-in): Only readonly OR required fields are required
- Removed ApiResponseSafe (was conceptually wrong)
- Added RequireReadonlyOrRequired helper type

CLI Changes:
- Removed --use-query-safe-response flag
- Added --use-strict-response flag (defaults to false)
- Updated all help text and log messages
- Response type is now consistent across ALL operations (no query vs mutation distinction)

Breaking Changes:
- ApiResponseSafe removed (use ApiResponse or ApiResponseStrict)
- All responses now default to ALL fields required
- --use-query-safe-response flag removed

This aligns with the correct semantic: readonly affects what you can POST,
not what the API returns.
Updated:
- CHANGELOG.md: Added Unreleased section documenting breaking changes
- CHANGELOG.md: Updated v0.13.0 entry with note about incorrect semantics
- tests/unit/readonly-properties.test.ts: Updated to use ApiResponseStrict
- Test descriptions now reflect correct semantics:
  * ApiResponse (default): ALL fields required
  * ApiResponseStrict (opt-in): Only readonly/required fields required
  * readonly only affects request bodies, not responses

All 342 tests passing with updated semantics.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

src/cli.ts:1404

  • When useStrictResponse is enabled, the generated api-client import list still includes ApiResponse even though all generated Response aliases use ApiResponseStrict. In consumer projects with noUnusedLocals/lint rules enabled, this can make the generated file fail to compile. Consider emitting only the selected response type in the import (either ApiResponse or ApiResponseStrict) based on useStrictResponse.
import type {
  ApiResponse${useStrictResponse ? ',\n  ApiResponseStrict' : ''},
  ApiRequest,
  ApiPathParams,
  ApiPathParamsInput,
  ApiQueryParams,
  operations,
} from './api-operations.js'

@zedrdave zedrdave merged commit e87bf02 into main Feb 28, 2026
7 checks passed
@zedrdave zedrdave deleted the feature/query-safe-response-by-default branch February 28, 2026 13:09
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