Skip to content

fix(sdk): TypeSpec emitters - #4719

Merged
tothandras merged 4 commits into
mainfrom
fix/javascript-sdk-schema
Jul 16, 2026
Merged

tothandras merged 4 commits into
mainfrom
fix/javascript-sdk-schema

Conversation

@tothandras

@tothandras tothandras commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added stricter optional request and response validation, including query sorting and path parameters.
    • Undefined request fields are omitted consistently during serialization.
    • Pagination metadata now explicitly supports null cursors and required page sizes.
    • Added validation for correctly formatted sort query parameters.
  • Bug Fixes

    • Improved cursor-based pagination handling across generated clients.
    • Responses missing required fields are now rejected when validation is enabled.

Greptile Summary

This PR updates the TypeSpec emitters and regenerated TypeScript and Go SDKs. The main changes are:

  • Adds strict validation for request paths, sort parameters, payloads, and responses.
  • Separates public schemas from their encoded wire representations.
  • Omits undefined object fields during request serialization.
  • Preserves explicit null values in cursor pagination metadata.
  • Adds lint and test coverage for sort query types and encoding.

Confidence Score: 5/5

This looks safe to merge.

  • The updated path mapping preserves binding names and keeps validation optional.
  • Sort values are validated before encoding and checked again against the wire schema.
  • Wire schemas no longer apply public defaults while validating responses.
  • No blocking issue tied to an earlier review finding remains in the updated code.

Important Files Changed

Filename Overview
api/spec/packages/typespec-typescript/src/sdk-files.ts Generates ordered path and sort validation while preserving behavior when validation is disabled.
api/spec/packages/typespec-typescript/src/runtime/wire.ts Adds path-specific transport mapping and omits undefined request fields.
api/spec/packages/typespec-typescript/src/ZodOperations.tsx Emits distinct public and wire schemas for operation parameters.
api/spec/packages/typespec-go/src/operations.ts Selects sort encoding from the validated HTTP parameter name.
api/spec/packages/typespec-typescript/templates/runtime/paginate.ts Handles absent and explicit null next cursors as pagination termination.
api/spec/packages/aip/src/common/pagination.tsp Aligns cursor metadata nullability across generated SDK models.

Reviews (4): Last reviewed commit: "fix(sdk): enforce sort query convention" | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

@tothandras
tothandras requested a review from a team as a code owner July 15, 2026 20:51
@tothandras tothandras added the release-note/bug-fix Release note: Bug Fixes label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR tightens generated SDK wire validation, adds schema-driven sort and path handling, omits undefined wire properties, removes defaults from response-capable wire schemas, and standardizes nullable cursor pagination across TypeSpec, TypeScript, and Go clients.

Changes

Generated SDK validation

Layer / File(s) Summary
Wire mapping and schema contracts
api/spec/packages/aip-client-javascript/src/lib/wire.ts, api/spec/packages/typespec-typescript/src/runtime/wire.ts, api/spec/packages/aip-client-javascript/src/models/schemas.ts
Undefined object and record entries are omitted during public-to-wire mapping; wire schemas no longer apply request defaults, and sort values use string wire schemas.
Query and path validation generation
api/spec/packages/typespec-typescript/src/query-codecs.ts, api/spec/packages/typespec-typescript/src/sdk-operations.ts, api/spec/packages/typespec-typescript/src/sdk-files.ts, api/spec/packages/typespec-typescript/src/ZodOperations.tsx, api/spec/packages/typespec-typescript/src/components/ZodSchema.tsx
Generated operations carry per-parameter codec metadata, validate public sort values before encoding, validate effective query wires afterward, and validate mapped path parameters before interpolation.
Generated endpoint wiring
api/spec/packages/aip-client-javascript/src/funcs/*
Generated list operations validate sort inputs, while path-based operations map and validate transport-shaped path parameters before URL encoding when validation is enabled.
Sort contract enforcement
api/spec/packages/aip/lib/*, api/spec/packages/aip/test/*, api/spec/packages/typespec-go/src/operations.ts
The AIP linter requires sort query parameters to use Common.SortQuery, and Go classification selects the sort codec from the HTTP parameter name.

Pagination contracts

Layer / File(s) Summary
Nullable cursor models and iterators
api/spec/packages/aip/src/common/pagination.tsp, api/spec/packages/aip-client-javascript/src/models/*, api/spec/packages/typespec-typescript/templates/runtime/paginate.ts, api/v3/client/models_shared.go
next and previous are required nullable values, size is required, and generated iterators convert nullable cursors for pagination.
Pagination fixtures and tests
api/v3/client/pagination_test.go, api/spec/packages/aip-client-javascript/tests/paginate.spec.ts
HTTP fixtures and pagination helpers now include required page metadata and explicit null cursors.

Validation coverage and documentation

Layer / File(s) Summary
Generated validation tests
api/spec/packages/typespec-typescript/templates/tests/validation.spec.ts, api/spec/packages/aip-client-javascript/tests/validation.spec.ts, api/spec/packages/typespec-typescript/test/*
Tests cover request payload omission, defaults, sort and path validation ordering, nullable responses, required response fields, and behavior when validation is disabled.
Validation contract documentation and test wiring
api/spec/AGENTS.md, api/spec/Makefile, api/spec/packages/typespec-typescript/src/runtime-templates.ts, api/spec/packages/aip/package.json
Documentation defines wire validation, default handling, sort and path rules; validation tests are emitted and included in package test commands.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant WireMapper
  participant ZodSchemas
  participant HTTP
  Client->>WireMapper: map request, path, and query values
  WireMapper->>ZodSchemas: validate transport-shaped payload
  ZodSchemas-->>Client: return ValidationError or validated data
  Client->>HTTP: send encoded request
  HTTP-->>ZodSchemas: validate response wire payload
  ZodSchemas-->>Client: return decoded response
Loading

Possibly related PRs

Suggested reviewers: chrisgacsal

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 74.47% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and relevant, summarizing the main focus on TypeSpec emitter changes in the SDK pipeline.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/javascript-sdk-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tothandras
tothandras enabled auto-merge (squash) July 15, 2026 20:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/spec/packages/typespec-typescript/src/sdk-operations.ts`:
- Around line 148-160: Keep sort detection in the SDK operation generation flow
independent of `sortSchema`: set `hasSort` whenever the query parameter is named
`sort`, including aliased or otherwise valid sort types. Use `sortSchema` only
for public-schema validation, or explicitly fail emission when it cannot be
resolved, while preserving the required `<field> [asc|desc]` serialization and
snake-casing on the wire.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1638b245-e13b-4993-bcd1-9ba5ba2dc430

📥 Commits

Reviewing files that changed from the base of the PR and between 6bcae6e and 1b3af43.

📒 Files selected for processing (30)
  • api/spec/AGENTS.md
  • api/spec/packages/aip-client-javascript/src/funcs/addons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/apps.ts
  • api/spec/packages/aip-client-javascript/src/funcs/billing.ts
  • api/spec/packages/aip-client-javascript/src/funcs/currencies.ts
  • api/spec/packages/aip-client-javascript/src/funcs/customers.ts
  • api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts
  • api/spec/packages/aip-client-javascript/src/funcs/events.ts
  • api/spec/packages/aip-client-javascript/src/funcs/features.ts
  • api/spec/packages/aip-client-javascript/src/funcs/invoices.ts
  • api/spec/packages/aip-client-javascript/src/funcs/llmCost.ts
  • api/spec/packages/aip-client-javascript/src/funcs/meters.ts
  • api/spec/packages/aip-client-javascript/src/funcs/planAddons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/plans.ts
  • api/spec/packages/aip-client-javascript/src/funcs/subscriptions.ts
  • api/spec/packages/aip-client-javascript/src/funcs/tax.ts
  • api/spec/packages/aip-client-javascript/src/lib/wire.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/tests/paginate.spec.ts
  • api/spec/packages/aip-client-javascript/tests/validation.spec.ts
  • api/spec/packages/typespec-typescript/src/emitter.tsx
  • api/spec/packages/typespec-typescript/src/runtime/wire.ts
  • api/spec/packages/typespec-typescript/src/sdk-files.ts
  • api/spec/packages/typespec-typescript/src/sdk-operations.ts
  • api/spec/packages/typespec-typescript/src/zodBaseSchema.tsx
  • api/spec/packages/typespec-typescript/src/zodMemberParts.tsx
  • api/spec/packages/typespec-typescript/templates/tests/validation.spec.ts
  • api/spec/packages/typespec-typescript/test/path-validation.test.ts
  • api/spec/packages/typespec-typescript/test/sort-validation.test.ts
  • api/spec/packages/typespec-typescript/test/wire-defaults.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • api/spec/packages/typespec-typescript/src/runtime/wire.ts
  • api/spec/packages/aip-client-javascript/src/lib/wire.ts
  • api/spec/AGENTS.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
api/spec/packages/typespec-sdk/lib/index.js (1)

10-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Generalize the diagnostic error message.

The diagnostic message currently hardcodes the word "sort". If we ever add other codecs in the future, this error might be a bit confusing. You might want to make it generic so it works cleanly for any codec type!

♻️ Proposed tweak
-      messages: {
-        default: 'query codec sort must encode to a string-compatible scalar',
-      },
+      messages: {
+        default: 'query codec must encode to a string-compatible scalar',
+      },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/spec/packages/typespec-sdk/lib/index.js` around lines 10 - 12, Generalize
the diagnostic message in the messages configuration so it no longer hardcodes
“sort”; use wording that applies to any query codec while preserving the
existing requirement that the encoded value be a string-compatible scalar.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@api/spec/packages/typespec-sdk/lib/index.js`:
- Around line 10-12: Generalize the diagnostic message in the messages
configuration so it no longer hardcodes “sort”; use wording that applies to any
query codec while preserving the existing requirement that the encoded value be
a string-compatible scalar.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 23477d30-2dcb-4204-92be-a8ec7cfb5230

📥 Commits

Reviewing files that changed from the base of the PR and between 1b3af43 and 0260e8a.

⛔ Files ignored due to path filters (1)
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (47)
  • api/spec/AGENTS.md
  • api/spec/packages/aip-client-javascript/src/funcs/addons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/apps.ts
  • api/spec/packages/aip-client-javascript/src/funcs/billing.ts
  • api/spec/packages/aip-client-javascript/src/funcs/currencies.ts
  • api/spec/packages/aip-client-javascript/src/funcs/customers.ts
  • api/spec/packages/aip-client-javascript/src/funcs/events.ts
  • api/spec/packages/aip-client-javascript/src/funcs/features.ts
  • api/spec/packages/aip-client-javascript/src/funcs/governance.ts
  • api/spec/packages/aip-client-javascript/src/funcs/invoices.ts
  • api/spec/packages/aip-client-javascript/src/funcs/llmCost.ts
  • api/spec/packages/aip-client-javascript/src/funcs/meters.ts
  • api/spec/packages/aip-client-javascript/src/funcs/planAddons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/plans.ts
  • api/spec/packages/aip-client-javascript/src/funcs/subscriptions.ts
  • api/spec/packages/aip-client-javascript/src/funcs/tax.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip/package.json
  • api/spec/packages/aip/src/common/parameters.tsp
  • api/spec/packages/aip/src/currencies/operations.tsp
  • api/spec/packages/aip/src/customers/charges/operations.tsp
  • api/spec/packages/aip/src/customers/operations.tsp
  • api/spec/packages/aip/src/events/operations.tsp
  • api/spec/packages/aip/src/features/operations.tsp
  • api/spec/packages/aip/src/invoices/operations.tsp
  • api/spec/packages/aip/src/llmcost/operations.tsp
  • api/spec/packages/aip/src/meters/operations.tsp
  • api/spec/packages/aip/src/productcatalog/operations.tsp
  • api/spec/packages/aip/src/subscriptions/operations.tsp
  • api/spec/packages/typespec-go/package.json
  • api/spec/packages/typespec-go/src/operations.ts
  • api/spec/packages/typespec-go/test/operations.test.ts
  • api/spec/packages/typespec-go/test/resource-render.test.ts
  • api/spec/packages/typespec-sdk/lib/index.d.ts
  • api/spec/packages/typespec-sdk/lib/index.js
  • api/spec/packages/typespec-sdk/lib/main.tsp
  • api/spec/packages/typespec-sdk/lib/testing.d.ts
  • api/spec/packages/typespec-sdk/lib/testing.js
  • api/spec/packages/typespec-sdk/package.json
  • api/spec/packages/typespec-typescript/package.json
  • api/spec/packages/typespec-typescript/src/ZodOperations.tsx
  • api/spec/packages/typespec-typescript/src/components/ZodSchema.tsx
  • api/spec/packages/typespec-typescript/src/sdk-files.ts
  • api/spec/packages/typespec-typescript/src/sdk-operations.ts
  • api/spec/packages/typespec-typescript/src/zodBaseSchema.tsx
  • api/spec/packages/typespec-typescript/test/emit.ts
  • api/spec/packages/typespec-typescript/test/sort-validation.test.ts
💤 Files with no reviewable changes (1)
  • api/spec/packages/typespec-typescript/src/zodBaseSchema.tsx
🚧 Files skipped from review as they are similar to previous changes (17)
  • api/spec/packages/aip-client-javascript/src/funcs/events.ts
  • api/spec/packages/aip-client-javascript/src/funcs/apps.ts
  • api/spec/packages/aip-client-javascript/src/funcs/currencies.ts
  • api/spec/packages/aip-client-javascript/src/funcs/addons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/features.ts
  • api/spec/packages/aip-client-javascript/src/funcs/tax.ts
  • api/spec/packages/aip-client-javascript/src/funcs/llmCost.ts
  • api/spec/packages/aip-client-javascript/src/funcs/planAddons.ts
  • api/spec/packages/aip-client-javascript/src/funcs/billing.ts
  • api/spec/packages/aip-client-javascript/src/funcs/meters.ts
  • api/spec/AGENTS.md
  • api/spec/packages/aip-client-javascript/src/funcs/invoices.ts
  • api/spec/packages/aip-client-javascript/src/funcs/plans.ts
  • api/spec/packages/typespec-typescript/src/sdk-files.ts
  • api/spec/packages/aip-client-javascript/src/funcs/subscriptions.ts
  • api/spec/packages/typespec-typescript/test/sort-validation.test.ts
  • api/spec/packages/aip-client-javascript/src/funcs/customers.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
api/spec/packages/aip/test/sort-query-type.test.js (1)

50-63: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use alias for testing aliases.

In TypeSpec, model SortAlias is Common.SortQuery; creates a brand new structural model rather than a true alias. If you specifically want to test that true aliases are rejected or resolved, you might want to use the alias keyword instead (e.g., alias SortAlias = Common.SortQuery;), or simply rename this test to something like 'rejects a structural copy of Common.SortQuery'.

💡 Suggested tweak
-  it('rejects an alias of Common.SortQuery', async () => {
+  it('rejects a structural copy of Common.SortQuery', async () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/spec/packages/aip/test/sort-query-type.test.js` around lines 50 - 63,
Update the test using model SortAlias to use a true TypeSpec alias declaration
with alias SortAlias = Common.SortQuery, preserving the existing diagnostic
assertion and test intent for alias handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@api/spec/packages/aip/test/sort-query-type.test.js`:
- Around line 50-63: Update the test using model SortAlias to use a true
TypeSpec alias declaration with alias SortAlias = Common.SortQuery, preserving
the existing diagnostic assertion and test intent for alias handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 09d4f552-3ac2-43d2-b3c9-3c1fa14bd53b

📥 Commits

Reviewing files that changed from the base of the PR and between 0260e8a and d112e3a.

📒 Files selected for processing (13)
  • api/spec/AGENTS.md
  • api/spec/Makefile
  • api/spec/packages/aip/lib/index.js
  • api/spec/packages/aip/lib/rules/sort-query-type.js
  • api/spec/packages/aip/package.json
  • api/spec/packages/aip/test/sort-query-type.test.js
  • api/spec/packages/typespec-go/src/operations.ts
  • api/spec/packages/typespec-go/test/operations.test.ts
  • api/spec/packages/typespec-go/test/resource-render.test.ts
  • api/spec/packages/typespec-typescript/src/ZodOperations.tsx
  • api/spec/packages/typespec-typescript/src/query-codecs.ts
  • api/spec/packages/typespec-typescript/src/sdk-operations.ts
  • api/spec/packages/typespec-typescript/test/sort-validation.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/spec/packages/typespec-typescript/src/ZodOperations.tsx
  • api/spec/AGENTS.md

@tothandras
tothandras merged commit f49d9e7 into main Jul 16, 2026
30 checks passed
@tothandras
tothandras deleted the fix/javascript-sdk-schema branch July 16, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants