Skip to content

Document the real 422 bodies and the nullable campaign sender name - #72

Open
Rabsztok wants to merge 5 commits into
mainfrom
mailtrap-openapi-document-the-422-error
Open

Rabsztok wants to merge 5 commits into
mainfrom
mailtrap-openapi-document-the-422-error

Conversation

@Rabsztok

@Rabsztok Rabsztok commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Motivation

Several error responses in the Account Management, Email Campaigns and Email Sending references don't match what the API returns. Some 422 bodies have a different errors shape, three operations don't list their 422 at all, and a campaign's from_display_name can be null. Clients generated from these documents decode those responses wrongly.

Changes

  • Account Management
    • Bulk permission updates return errors as a single message.
    • Creating an API token returns either messages per attribute (the token's own validation, such as no permissions or the active-token limit) or a single message (an invalid permission, such as an unknown resource). It is documented as a oneOf with an example of each.
    • Creating a sub account returns errors as an array of messages.
    • Deleting an account access lists its 422: the account owner's access can't be removed.
  • Email Campaigns
    • Start and schedule get their own 422: a single message (an invalid transition or datetime) or sending-validation messages per attribute, campaign-wide ones under base. The documented array never occurs.
    • Cancel, terminate and reset keep the shared 422, narrowed to a single message.
    • Listing campaigns lists its 422 for an out-of-range token, as listing templates already does.
    • from_display_name is null for a campaign without a sender name.
  • Email Sending
    • Domain setup instructions return one message per key (email or base), not arrays.
    • Deleting a domain lists its 422 for a domain that inbound inboxes still use.

This touches the same responses: blocks as #71 and sits next to the code samples #69 edits; whichever lands second rebases.

How to test

You'll need an admin API token for an account with a sending domain and email campaigns, and an organization API token for the sub-account checks. Each response below should match what the API reference now documents for that operation.

Account Management

  • Owner permissions: PUT /api/account_accesses/{owner_access_id}/permissions/bulk with any permission. Expect 422, {"errors":"You can't update the permissions of an account owner"}.
  • Token without permissions: POST /api/api_tokens with an empty resources list. Expect 422, {"errors":{"base":["No permissions selected. Please choose at least one."]}}.
  • Token with an unknown resource: POST /api/api_tokens with {"resource_type":"project","resource_id":<missing id>,"access_level":100} in resources. Expect 422, {"errors":"Resource of type 'project' and ID #<id> not found"}.
  • Owner access delete: DELETE /api/account_accesses/{owner_access_id}. Expect 422, {"errors":"You can not remove the owner of the account"}.
  • Sub-account limit: POST /api/organizations/{organization_id}/sub_accounts for an organization at its sub-account limit. Expect 422, {"errors":["Accounts limit reached"]}. A name over 80 characters returns {"errors":["Failed to create account."]}.

Email Campaigns

  • Start, sending validation fails: POST /api/email_campaigns/{id}/start on a draft of an account with no company information. Expect 422 with the message under errors.base as an array.
  • Start, invalid transition: start a campaign that is already started. Expect 422, {"errors":"Cannot transition from 'started' to 'scheduled'"}.
  • Schedule: the same two cases on POST /api/email_campaigns/{id}/schedule give the same two shapes.
  • Cancel, terminate, reset: each from a state that doesn't allow it returns a single message, e.g. cancelling a draft gives {"errors":"Campaign is not scheduled"}.
  • List, token out of range: GET /api/email_campaigns?per_page=100&token=100000000000000000. Expect 422, {"errors":"token is out of range"}.
  • No sender name: GET /api/email_campaigns/{id} for a campaign created without from_display_name. Expect 200 with "from_display_name": null.

Email Sending

  • Setup instructions, invalid email: POST /api/domains/{domain_id}/send_setup_instructions with {"email":"invalid"}. Expect 422, {"errors":{"email":"Invalid email address"}}.
  • Domain delete, inbound inbox uses it: DELETE /api/domains/{domain_id} for a domain an inbound inbox depends on. Expect 422, {"errors":{"base":["Can't delete the domain because there are inbound inboxes depending on it."]}}.

Summary by CodeRabbit

  • Documentation
    • Expanded API documentation with specific 422 error cases for account management, including permission changes, token creation, and sub-account creation.
    • Clarified email campaign validation responses for pagination, sending, and lifecycle actions, and documented nullable sender display names.
    • Added email-sending error details for invalid setup addresses, blocked domains, and domains that cannot be deleted while inbound inboxes depend on them.

Decisions:
- Describe each 422 by the body the API renders: a string, an array, or per-attribute strings, where the documents claimed per-attribute arrays
- Add the 422s that deleting an account access, listing campaigns and deleting a domain return but did not list
- Split start/schedule from cancel/terminate/reset: only the first two return sending-validation errors, and no action returns a plain array
- Keep the per-attribute response component for API token reset, which still renders that shape
- from_display_name is null for a campaign without a sender name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7cd672f8-c037-4bc0-8298-b816113851cb

No actionable comments were generated in the recent review.

Walkthrough

The OpenAPI specifications add endpoint-specific error responses and examples for account management, email campaigns, and email sending. Campaign documentation also permits a null from_display_name and separates lifecycle action errors from sending-validation errors.

Changes: Account management

Layer / File(s) Summary
Account access error responses
specs/account-management.openapi.yml
Account-access deletion and permission updates document 422 failure cases and examples.
Token and sub-account error responses
specs/account-management.openapi.yml
API-token and sub-account creation document endpoint-specific 422 schemas and examples.

Email campaigns

Layer / File(s) Summary
Campaign list and response fields
specs/email-campaigns.openapi.yml
The list endpoint documents a 422 response for an overflowing pagination offset. from_display_name allows null.
Campaign action error contracts
specs/email-campaigns.openapi.yml
Start and schedule use a sending-specific error response. Lifecycle errors use a single-message shape; sending errors also support attribute-based validation errors.

Email sending

Layer / File(s) Summary
Domain and setup-instruction errors
specs/email-sending.openapi.yml
Domain deletion documents the inbound-inbox dependency that blocks deletion. Setup instructions document invalid email and blocked-domain errors.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Other

Suggested reviewers: mklocek, izikaj, oshchyhol

Merge Risk: Minimal · previous review 923be

This PR documents API error responses and a nullable field in the OpenAPI specifications. It changes no runtime behavior, and no merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main themes: documenting the real 422 response bodies and the nullable campaign sender name. It is specific and matches the changes in the three OpenAPI spec files. It does not…
Description check Passed The description follows the repository template's Motivation and Changes sections, and it adds a detailed How to test section with concrete request and response checks. It has no Images and GIFs secti…
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.
Full details: Title check

Explanation

The title names the two main themes: documenting the real 422 response bodies and the nullable campaign sender name. It is specific and matches the changes in the three OpenAPI spec files. It does not cover the Account Management and Email Sending changes, which the description allows.

Full details: Description check

Explanation

The description follows the repository template's Motivation and Changes sections, and it adds a detailed How to test section with concrete request and response checks. It has no Images and GIFs section, and it does not fill the template placeholders. That section fits a spec-only change with no visual output, so this gap is not critical. The description also says the change overlaps PR #71 and needs a rebase, which is useful context.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 55f01c02-1e70-449b-a94b-d8909e135eaf
Commits

Reviewing files that changed from the base of the PR and between 4e6814d and 923beb9.

Files selected for processing: 2

  • specs/account-management.openapi.yml
  • specs/email-campaigns.openapi.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Decisions:
- Start and schedule 422 is a oneOf of the existing single-message and per-attribute schemas, as the API token create 422 is, instead of a third schema that copied both.
- The bulk permission, API token and sub-account 422 descriptions now name every cause the API returns them for: an invalid access level, an update that leaves no permissions, an organization scheduled for deletion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Decisions:
- A permission update that would leave billing as the only permission in an organization without the Organizations and Sub-Accounts feature returns a single-message 422; API tokens can't hold billing, so the token create 422 doesn't list it
- The schemas used as oneOf branches require errors, so a body can't match both branches
- Sending-validation messages always come under base, not per attribute
- The datetime error only applies to scheduling, since start takes no datetime
- from_display_name and the Reply-To display_name accept and return null, in requests as in responses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread specs/account-management.openapi.yml Resolved
@Rabsztok
Rabsztok marked this pull request as ready for review November 16, 2026 10:05
Decisions:
- A missing or empty account.name reaches Rails' default 400 body, {"status":400,"error":"Bad Request"}, which has no errors key and stopped matching ErrorResponse once errors became required
- BadRequest mirrors the Email Sending document's schema of the same name, plus the status the body carries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rabsztok
Rabsztok requested a review from oshchyhol November 16, 2026 10:11
Comment thread specs/account-management.openapi.yml Resolved
Decisions:
- The backend always wraps these 422 bodies as { errors: ... }, so generated clients get a non-optional field, as with the named error schemas
- The templates list 422 changes with the campaigns one so the two stay identical
- email-sending's UnprocessableEntity backs the new delete-domain 422, and every 422 that uses it renders errors, so it requires errors as its account-management counterpart does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants