Skip to content

feat(web-api): add blocks.validate method - #1946

Merged
zimeg merged 5 commits into
mainfrom
clack/blocks-validate
Aug 26, 2026
Merged

feat(web-api): add blocks.validate method#1946
zimeg merged 5 commits into
mainfrom
clack/blocks-validate

Conversation

@zimeg

@zimeg zimeg commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

Adds the blocks.validate Web API method to the sync, async, and legacy web clients:

from slack_sdk.models.blocks import SectionBlock, PlainTextObject

client.blocks_validate(blocks=[SectionBlock(text=PlainTextObject(text="Hello world"))])

Validate a Block Kit payload against the Block Kit schema by passing exactly one of:

  • blocks — a list of Block objects (or dicts, or a JSON string)
  • message — a message payload dict (or JSON string)
  • view — a View (or dict, or JSON string)

blocks.validate is unauthenticated (no token or scopes), so the method can be called without a configured token — matching the in-flight Node (slackapi/node-slack-sdk#2659) and Java (slackapi/java-slack-sdk#1622) additions.

Implementation notes:

  • Typed inputs mirror chat_postMessage / views_open: Block objects are serialized via _parse_web_class_objects, a View via view.to_dict(), and the payload is sent as JSON.
  • slack_sdk/web/client.py is the source of truth; async_client.py and legacy_client.py are regenerated via python scripts/codegen.py.
  • blocks.validate added to the web client coverage endpoint list (308 → 309).

Testing

  • blocks.validate is exercised by tests/slack_sdk_async/web/test_web_client_coverage.py (the endpoint-coverage test asserts every listed method is exposed on all three clients).
  • Run: python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh

Reviewer note: I was unable to run run_validation.sh locally (test deps such as aiohttp/pytest and black weren't installed). The generated files are produced by scripts/codegen.py (re-running is idempotent) and source-level checks (py_compile, AST signatures) pass. Please run the validation script before merging.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/run_validation.sh after making the changes. (See reviewer note — could not run locally; CI covers it.)

🤖 Generated with Claude Code

Add the `blocks.validate` Web API method to the sync, async, and legacy
web clients. Call it as `client.blocks_validate(blocks=...)` to validate a
Block Kit payload (`blocks`, `message`, or `view`, each a JSON-encoded
string) against the Block Kit schema, instead of the untyped
`client.api_call("blocks.validate", ...)` escape hatch. The method is
unauthenticated (no token or scopes required) per the method reference.

The sync `client.py` is the source of truth; `async_client.py` and
`legacy_client.py` are regenerated via `scripts/codegen.py`. Adds
`blocks.validate` to the web client coverage test's endpoint list.

Ref: https://docs.slack.dev/reference/methods/blocks.validate

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.06%. Comparing base (ac312d4) to head (f0c3fe4).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
slack_sdk/web/async_client.py 41.66% 7 Missing ⚠️
slack_sdk/web/client.py 41.66% 7 Missing ⚠️
slack_sdk/web/legacy_client.py 41.66% 7 Missing ⚠️

❌ Your patch check has failed because the patch coverage (41.66%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1946      +/-   ##
==========================================
- Coverage   84.17%   84.06%   -0.12%     
==========================================
  Files         118      118              
  Lines       13470    13506      +36     
==========================================
+ Hits        11339    11354      +15     
- Misses       2131     2152      +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

zimeg and others added 2 commits August 25, 2026 17:05
Bring blocks_validate to parity with chat_postMessage / views_open: accept
Block objects (Union[str, Sequence[Union[Dict, Block]]]) and a View/dict for
view, serialize them via _parse_web_class_objects and view.to_dict(), and
send as json. message accepts a dict or JSON string.

client.py is the source of truth; async_client.py and legacy_client.py are
regenerated via scripts/codegen.py.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
zimeg and others added 2 commits August 26, 2026 09:58
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
blocks.validate reads blocks/message/view as JSON-encoded form fields, not a
JSON request body — a JSON body returns invalid_arguments ("must provide
exactly one of blocks, view, or message"). Serialize each provided payload
with json.dumps (converting Block/View objects to dicts first) and send via
params, following conversations.requestSharedInvite.approve. Verified against
the live API: blocks/message/view all validate, and malformed input returns
the errors[] contract.

client.py is the source of truth; async_client.py and legacy_client.py are
regenerated via scripts/codegen.py.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg marked this pull request as ready for review August 26, 2026 17:41
@zimeg
zimeg requested a review from a team as a code owner August 26, 2026 17:41

@WilliamBergamin WilliamBergamin 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.

🚢

@WilliamBergamin WilliamBergamin 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.

🚢

@zimeg

zimeg commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

@WilliamBergamin Onward with a merge we sail! 🚢 💨

@zimeg
zimeg merged commit 21f62ba into main Aug 26, 2026
17 of 18 checks passed
@zimeg
zimeg deleted the clack/blocks-validate branch August 26, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants