Skip to content

Fix spec issues from merged PRs #405 and #406#416

Open
salmanbshah wants to merge 1 commit intomainfrom
salmanshah/fix-405-406-spec-issues
Open

Fix spec issues from merged PRs #405 and #406#416
salmanbshah wants to merge 1 commit intomainfrom
salmanshah/fix-405-406-spec-issues

Conversation

@salmanbshah
Copy link
Contributor

Why?

PRs #405 and #406 documented two new endpoints in the Unstable spec but introduced several discrepancies between the spec and actual backend behavior. An audit identified 5 issues — wrong error formats, missing enums, incorrect error codes, and undocumented auth requirements.

How?

Five targeted fixes to descriptions/0/api.intercom.io.yaml, each verified against backend source code.

Decisions

Kept all fixes in a single PR since they're all corrections to the same spec file from the same audit pass.


Backend evidence for each fix

Fix 1: 400 error format on GET /messages/whatsapp/status

Was: flat {type: error, request_id, message}Should be: {type: "error.list", errors: [{code, message}]}

Backend proof: All ApiCodedError exceptions go through error_handler.rbrender_errorrender_errors, which always wraps in the error.list format. The 404 example in the same endpoint already used the correct format — this was an inconsistency within the same PR.

Fix 2: type enum missing on whatsapp_message_status

Was: no enum, just example: broadcast_outboundShould be: 5 values

Backend proof: whatsapp_event.rb:14-19 defines the enum:

enum :type, {
  broadcast_outbound: 'broadcast_outbound',
  inbox_outbound: 'inbox_outbound',
  inbound: 'inbound',
  admin_reply: 'admin_reply',
  admin_reply_with_template: 'admin_reply_with_template',
}

Fix 3: required properties on whatsapp_message_status

Was: no required array — Should be: [conversation_id, status, type, message_id]

Backend proof: messages_controller.rb whatsapp_status action always builds the response hash with conversation_id, status, type, and message_id from non-nullable DB columns.

Fix 4: 401 error code on PUT conversation_parts

Was: code: unauthorized, message: Access Token InvalidShould be: code: token_unauthorized, message: Not authorized to access resource

Backend proof: code.rb:44 defines TOKEN_UNAUTHORIZED = 'token_unauthorized'. The controller's unauthorized_api_error method returns message: 'Not authorized to access resource'.

Fix 5: WRITE_TICKETS scope undocumented on PUT conversation_parts

Was: no mention of ticket scope — Should be: documented

Backend proof: conversation_parts_controller.rb:58-61 checks unauthorized_ticket_write? which verifies @token.scope.include?(WRITE_TICKETS) for ticket conversations.

Implementation Plan

Fix PRs #405 and #406 — OpenAPI Spec Issues

Context

PRs #405 and #406 documented two previously-undocumented endpoints in the Unstable spec. Both merged. An audit found multiple discrepancies between spec and backend. Single PR to fix all 5 issues.

File to modify

descriptions/0/api.intercom.io.yaml — only file

Fixes

From PR #405 — GET /messages/whatsapp/status

Fix 1 (HIGH): 400 error example — wrong format

Spec has flat {type: error, request_id, message}. Backend always renders {type: "error.list", errors: [{code, message}]} via error_handler.rbrender_errors. The 404 in the same endpoint is already correct.

Fix 2 (HIGH): type field missing enum

whatsapp_event.rb:14-19 defines 5 values. Spec has none.

Fix 3 (MEDIUM): No required properties

Controller always returns conversation_id, status, type, message_id.

From PR #406 — PUT /conversations/{conversation_id}/conversation_parts/{id}

Fix 4 (HIGH): 401 error code and message wrong

Spec: code: unauthorized, message: Access Token Invalid
Backend: code: token_unauthorized, message: Not authorized to access resource

Fix 5 (MEDIUM): WRITE_TICKETS scope undocumented

Controller checks unauthorized_ticket_write? verifying WRITE_TICKETS scope for ticket conversations.

Verification

  1. fern check — 0 errors, 290 warnings (same as main)
  2. Each fix verified against backend source files

Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@salmanbshah salmanbshah enabled auto-merge (squash) March 20, 2026 12:32
@salmanbshah salmanbshah requested review from a team and levindixon March 20, 2026 23:20
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.

1 participant