Skip to content

Conversation

@kibertoad
Copy link
Collaborator

@kibertoad kibertoad commented Sep 5, 2025

Changes

Only absence of response map was accepted by default, which was too strict

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

Summary by CodeRabbit

  • New Features
    • Expanded API contracts to accept either partial or complete status-code-to-schema mappings across route definitions and their builders.
    • Improves flexibility for defining response schemas without affecting runtime behavior.

@kibertoad kibertoad requested review from a team, CarlosGamero and dariacm as code owners September 5, 2025 09:56
@kibertoad kibertoad added the patch label Sep 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Broadened the generic constraint for ResponseSchemasByStatusCode across route definition types and builder functions in packages/app/api-contracts/src/apiContracts.ts to also accept full Record<HttpStatusCode, z.Schema>, in addition to Partial and undefined. No runtime logic changed; only type signatures were updated.

Changes

Cohort / File(s) Summary of Changes
Type signature widening for response schema maps
packages/app/api-contracts/src/apiContracts.ts
Updated generics for CommonRouteDefinition, PayloadRouteDefinition, GetRouteDefinition, DeleteRouteDefinition, and builders (buildPayloadRoute, buildGetRoute, buildDeleteRoute) to allow ResponseSchemasByStatusCode as Partial<Record<...>>, Record<...>, or undefined. No runtime changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/relaxt-contract-requirements

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
packages/app/api-contracts/src/apiContracts.ts (1)

31-34: Optional: align CommonRouteDefinition’s default for consistency

While not changed in this PR, consider defaulting here to Partial | undefined too, so all exported types share the same relaxed default.

-  ResponseSchemasByStatusCode extends
-    | Partial<Record<HttpStatusCode, z.Schema>>
-    | undefined = undefined,
+  ResponseSchemasByStatusCode extends
+    | Partial<Record<HttpStatusCode, z.Schema>>
+    | undefined = Partial<Record<HttpStatusCode, z.Schema>> | undefined,

Optional follow-up: you could also drop | undefined from the generic and rely on the ? on responseSchemasByStatusCode to represent absence, reducing double-undefined unions.

📜 Review details

Configuration used: Repository: lokalise/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3f7b6 and da8c528.

📒 Files selected for processing (1)
  • packages/app/api-contracts/src/apiContracts.ts (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/app/api-contracts/src/apiContracts.ts (1)
packages/app/api-contracts/src/HttpStatusCodes.ts (1)
  • HttpStatusCode (1-64)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (24.x)
  • GitHub Check: build (20.x)
  • GitHub Check: build (22.x)

Comment on lines +68 to 71
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Default now requires a full mapping; defeats “relax default” goal

Setting the default to Record<HttpStatusCode, z.Schema> | undefined narrows usage when generics are omitted—partials won’t type-check. Default to Partial<...> | undefined; Record<...> remains assignable to Partial<...> anyway.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
// … other generic parameters …
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
) = CommonRouteDefinition<
// … remaining parameters …
🤖 Prompt for AI Agents
packages/app/api-contracts/src/apiContracts.ts around lines 68 to 71: the
generic default for ResponseSchemasByStatusCode was changed to
Record<HttpStatusCode, z.Schema> | undefined which forces a full mapping when
generics are omitted; revert the default to Partial<Record<HttpStatusCode,
z.Schema>> | undefined so callers can omit keys (a full Record still satisfies
Partial), i.e. update the generic default back to the Partial form.

Comment on lines +91 to 94
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Same issue in GetRouteDefinition default

Defaulting to Record | undefined rejects partial maps by default. Use Partial | undefined.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
🤖 Prompt for AI Agents
In packages/app/api-contracts/src/apiContracts.ts around lines 91 to 94, the
generic default for ResponseSchemasByStatusCode uses Record<HttpStatusCode,
z.Schema> | undefined which disallows partial maps; change the default to
Partial<Record<HttpStatusCode, z.Schema>> | undefined so callers can omit or
provide partial status-code maps, and apply the same change to the
GetRouteDefinition default mentioned in the comment.

Comment on lines +113 to 116
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Same issue in DeleteRouteDefinition default

Align default with the relaxed intent so partials work out of the box.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
> = CommonRouteDefinition<
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
🤖 Prompt for AI Agents
In packages/app/api-contracts/src/apiContracts.ts around lines 113 to 116, the
generic default for DeleteRouteDefinition uses a strict Record<HttpStatusCode,
z.Schema> | undefined which prevents partial response schema maps; change the
default generic to Partial<Record<HttpStatusCode, z.Schema>> | undefined so
partial response schema objects are accepted by default and align with the
relaxed intent.

Comment on lines +136 to 139
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Builder: buildPayloadRoute default also too strict

Mirror the fix here so callers can pass partial maps without specifying generics.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
🤖 Prompt for AI Agents
In packages/app/api-contracts/src/apiContracts.ts around lines 136 to 139, the
generic default for ResponseSchemasByStatusCode is too strict (requires a full
Record<HttpStatusCode, z.Schema>), preventing callers from passing partial maps
without specifying generics; change the default type to
Partial<Record<HttpStatusCode, z.Schema>> | undefined (i.e., use Partial instead
of Record) so callers can provide partial status-code-to-schema maps implicitly,
and ensure any related usages or overloads accept the updated union type.

Comment on lines +186 to 189
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Builder: buildGetRoute default too strict

Default should be Partial | undefined for the same reason.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
>(
🤖 Prompt for AI Agents
In packages/app/api-contracts/src/apiContracts.ts around lines 186 to 189, the
generic default for ResponseSchemasByStatusCode in buildGetRoute is too strict
(currently uses Record<HttpStatusCode, z.Schema> | undefined); change the
default to Partial<Record<HttpStatusCode, z.Schema>> | undefined so callers can
omit some status codes; update the generic parameter default accordingly and
ensure any related type usages still accept the looser Partial | undefined form.

Comment on lines +236 to 239
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Builder: buildDeleteRoute default too strict

Apply the same correction here.

-  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
-    | Record<HttpStatusCode, z.Schema>
-    | undefined,
+  ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
+    Partial<Record<HttpStatusCode, z.Schema>> | undefined,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
| Record<HttpStatusCode, z.Schema>
| undefined,
>(
ResponseSchemasByStatusCode extends Partial<Record<HttpStatusCode, z.Schema>> | undefined =
Partial<Record<HttpStatusCode, z.Schema>> | undefined,
>(
🤖 Prompt for AI Agents
In packages/app/api-contracts/src/apiContracts.ts around lines 236 to 239, the
generic parameter ResponseSchemasByStatusCode currently constrains to
Partial<Record<HttpStatusCode, z.Schema>> but its default is
Record<HttpStatusCode, z.Schema> | undefined which is too strict; change the
default to match the constraint (Partial<Record<HttpStatusCode, z.Schema>> |
undefined) so callers won’t be forced to supply every status code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants