Repository navigation
fix(sdk): TypeSpec emitters - #4719
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesGenerated SDK validation
Pagination contracts
Validation coverage and documentation
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (30)
api/spec/AGENTS.mdapi/spec/packages/aip-client-javascript/src/funcs/addons.tsapi/spec/packages/aip-client-javascript/src/funcs/apps.tsapi/spec/packages/aip-client-javascript/src/funcs/billing.tsapi/spec/packages/aip-client-javascript/src/funcs/currencies.tsapi/spec/packages/aip-client-javascript/src/funcs/customers.tsapi/spec/packages/aip-client-javascript/src/funcs/entitlements.tsapi/spec/packages/aip-client-javascript/src/funcs/events.tsapi/spec/packages/aip-client-javascript/src/funcs/features.tsapi/spec/packages/aip-client-javascript/src/funcs/invoices.tsapi/spec/packages/aip-client-javascript/src/funcs/llmCost.tsapi/spec/packages/aip-client-javascript/src/funcs/meters.tsapi/spec/packages/aip-client-javascript/src/funcs/planAddons.tsapi/spec/packages/aip-client-javascript/src/funcs/plans.tsapi/spec/packages/aip-client-javascript/src/funcs/subscriptions.tsapi/spec/packages/aip-client-javascript/src/funcs/tax.tsapi/spec/packages/aip-client-javascript/src/lib/wire.tsapi/spec/packages/aip-client-javascript/src/models/schemas.tsapi/spec/packages/aip-client-javascript/tests/paginate.spec.tsapi/spec/packages/aip-client-javascript/tests/validation.spec.tsapi/spec/packages/typespec-typescript/src/emitter.tsxapi/spec/packages/typespec-typescript/src/runtime/wire.tsapi/spec/packages/typespec-typescript/src/sdk-files.tsapi/spec/packages/typespec-typescript/src/sdk-operations.tsapi/spec/packages/typespec-typescript/src/zodBaseSchema.tsxapi/spec/packages/typespec-typescript/src/zodMemberParts.tsxapi/spec/packages/typespec-typescript/templates/tests/validation.spec.tsapi/spec/packages/typespec-typescript/test/path-validation.test.tsapi/spec/packages/typespec-typescript/test/sort-validation.test.tsapi/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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/spec/packages/typespec-sdk/lib/index.js (1)
10-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueGeneralize 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
⛔ Files ignored due to path filters (1)
api/spec/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (47)
api/spec/AGENTS.mdapi/spec/packages/aip-client-javascript/src/funcs/addons.tsapi/spec/packages/aip-client-javascript/src/funcs/apps.tsapi/spec/packages/aip-client-javascript/src/funcs/billing.tsapi/spec/packages/aip-client-javascript/src/funcs/currencies.tsapi/spec/packages/aip-client-javascript/src/funcs/customers.tsapi/spec/packages/aip-client-javascript/src/funcs/events.tsapi/spec/packages/aip-client-javascript/src/funcs/features.tsapi/spec/packages/aip-client-javascript/src/funcs/governance.tsapi/spec/packages/aip-client-javascript/src/funcs/invoices.tsapi/spec/packages/aip-client-javascript/src/funcs/llmCost.tsapi/spec/packages/aip-client-javascript/src/funcs/meters.tsapi/spec/packages/aip-client-javascript/src/funcs/planAddons.tsapi/spec/packages/aip-client-javascript/src/funcs/plans.tsapi/spec/packages/aip-client-javascript/src/funcs/subscriptions.tsapi/spec/packages/aip-client-javascript/src/funcs/tax.tsapi/spec/packages/aip-client-javascript/src/models/schemas.tsapi/spec/packages/aip/package.jsonapi/spec/packages/aip/src/common/parameters.tspapi/spec/packages/aip/src/currencies/operations.tspapi/spec/packages/aip/src/customers/charges/operations.tspapi/spec/packages/aip/src/customers/operations.tspapi/spec/packages/aip/src/events/operations.tspapi/spec/packages/aip/src/features/operations.tspapi/spec/packages/aip/src/invoices/operations.tspapi/spec/packages/aip/src/llmcost/operations.tspapi/spec/packages/aip/src/meters/operations.tspapi/spec/packages/aip/src/productcatalog/operations.tspapi/spec/packages/aip/src/subscriptions/operations.tspapi/spec/packages/typespec-go/package.jsonapi/spec/packages/typespec-go/src/operations.tsapi/spec/packages/typespec-go/test/operations.test.tsapi/spec/packages/typespec-go/test/resource-render.test.tsapi/spec/packages/typespec-sdk/lib/index.d.tsapi/spec/packages/typespec-sdk/lib/index.jsapi/spec/packages/typespec-sdk/lib/main.tspapi/spec/packages/typespec-sdk/lib/testing.d.tsapi/spec/packages/typespec-sdk/lib/testing.jsapi/spec/packages/typespec-sdk/package.jsonapi/spec/packages/typespec-typescript/package.jsonapi/spec/packages/typespec-typescript/src/ZodOperations.tsxapi/spec/packages/typespec-typescript/src/components/ZodSchema.tsxapi/spec/packages/typespec-typescript/src/sdk-files.tsapi/spec/packages/typespec-typescript/src/sdk-operations.tsapi/spec/packages/typespec-typescript/src/zodBaseSchema.tsxapi/spec/packages/typespec-typescript/test/emit.tsapi/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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/spec/packages/aip/test/sort-query-type.test.js (1)
50-63: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
aliasfor 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 thealiaskeyword 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
📒 Files selected for processing (13)
api/spec/AGENTS.mdapi/spec/Makefileapi/spec/packages/aip/lib/index.jsapi/spec/packages/aip/lib/rules/sort-query-type.jsapi/spec/packages/aip/package.jsonapi/spec/packages/aip/test/sort-query-type.test.jsapi/spec/packages/typespec-go/src/operations.tsapi/spec/packages/typespec-go/test/operations.test.tsapi/spec/packages/typespec-go/test/resource-render.test.tsapi/spec/packages/typespec-typescript/src/ZodOperations.tsxapi/spec/packages/typespec-typescript/src/query-codecs.tsapi/spec/packages/typespec-typescript/src/sdk-operations.tsapi/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
Summary by CodeRabbit
New Features
Bug Fixes
Greptile Summary
This PR updates the TypeSpec emitters and regenerated TypeScript and Go SDKs. The main changes are:
Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (4): Last reviewed commit: "fix(sdk): enforce sort query convention" | Re-trigger Greptile
Context used (3)