Skip to content

feat(schema): add offline input validation - #2934

Open
hiSandog wants to merge 1 commit into
larksuite:mainfrom
hiSandog:fix/schema-input-validation-20261125-a47e2c
Open

hiSandog wants to merge 1 commit into
larksuite:mainfrom
hiSandog:fix/schema-input-validation-20261125-a47e2c

Conversation

@hiSandog

@hiSandog hiSandog commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Agents can inspect an API method's input schema, but cannot check a proposed input with the CLI before making a request. Add schema <method> --validate for offline validation using the same catalog, identity filtering, and command visibility as schema inspection.

schema <method> --validate <JSON | @file | ->
  resolve visible method
  read through invocation FileIO/stdin
  validate the published inputSchema
  → stdout: success envelope, exit 0
  → stderr: typed field errors, exit 2

Changes

  • Validate nested types, required properties, array items, enums, and inclusive numeric bounds. Preserve exact decimal comparisons, including integers beyond float64 precision and large exponents.
  • Reject duplicate keys, multiple JSON documents, and nesting beyond 64 containers. Report deterministic RFC 6901 JSON Pointers, cap diagnostics at 100 violations with an explicit truncation hint, and avoid echoing submitted field values.
  • Support inline JSON, @file, and stdin with invocation-scoped FileIO. Resolve the method before consuming input; preserve typed errors and their causes.
  • Add owner, command, and root-output regressions, fuzz coverage, and English/Chinese documentation. Existing inspection output is preserved.

The input is the emitted inputSchema object (params/data/file, where declared), not a raw request body. Unknown properties remain allowed; defaults and formats are annotations. Validation neither opens upload paths nor establishes authorization, dangerous-operation confirmation, or server-side acceptance. No dependencies or generated catalog files change.

Evidence

  • Before: the upstream CLI rejected schema ... --validate with exit 2 and unknown flag "--validate".

  • After: with isolated configuration and no supplied credentials, all three input sources succeed:

    lark-cli schema drive.files.list --validate '{"params":{"page_size":50,"direction":"ASC"}}'
    {"ok":true,"data":{"schema_path":"drive.files.list","valid":true}}
  • Invalid input: {"params":{"page_size":201,"direction":"PRIVATE"}} exits 2, leaves stdout empty, and reports /params/direction and /params/page_size in error.params without exposing the supplied enum value.

  • 20-second fuzz run passed with 6,402,312 executions. Regression tests cover exact numeric boundaries, nested arrays, duplicate keys, stdin/files, FileIO closure and policy failures, identity/visibility restrictions, catalog failures, and real root envelopes.

Test Plan

  • Focused schema and root-command regressions.
  • All unit-test packages passed with race detection across the main suite and a separate wrapper-package run (Go 1.23.12, macOS system linker).
  • make build, make vet, make fmt-check.
  • go mod tidy leaves go.mod / go.sum unchanged.
  • Pinned golangci-lint v2.1.6: 0 issues; diff-scoped source-contract guards and lint module tests.
  • Pinned go-licenses v2.0.1 check (standard non-Go-code inspection warnings only).
  • Post-commit make quality-gate, based on c5fbf1a52df77d5cb9cac2b1501770b2fb9af7d2.
  • Built CLI inline/file/stdin success, invalid/duplicate input failures, and unchanged inspection output.

Local race-test invocations:

env -u CODEX_SHELL -u CODEX_VERSION -u CODEX_PERMISSION_PROFILE \
  GOTOOLCHAIN=go1.23.12 make unit-test RACE_FLAG='-race -ldflags=-linkmode=external'
env -u CODEX_SHELL -u CODEX_VERSION -u CODEX_PERMISSION_PROFILE \
  GOTOOLCHAIN=go1.23.12 GOFLAGS=-ldflags=-linkmode=external \
  go test -race -gcflags='all=-N -l' -count=1 ./extension/command

The full make unit-test invocation passed every package except extension/command: its generated wrapper binary failed to load with macOS missing LC_UUID. That package passed separately with the system linker also applied to child builds. Applying that flag globally to the full suite instead breaks existing CGO-disabled cross-platform import checks, so the two runs are reported separately. Clearing agent-detection variables isolates existing agent-header tests. The host Go 1.26 race runtime crashed before test execution. Full integration/live-tenant suites were not run; this feature performs no API calls.

Merge Danger

Door: two-way — revert the additive flag and validator; no persisted-state migration.

Blast Radius: schema — new validation behavior and the shared method-resolution helper. Existing inspection, visibility, identity filtering, and typed-error contracts are covered by regressions.

Related Issues

Summary by CodeRabbit

  • New Features
    • Added --validate to check method input locally against its schema, without logging in or making API requests.
    • Validation checks types, required fields, array items, enums, and numeric bounds. Errors identify fields without revealing their values.
    • Results use standard success or error output, with documented exit codes and limits on input size and reported violations.
  • Documentation
    • Added English and Chinese guidance on validation inputs, behavior, output, and limitations.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The schema package now validates JSON input against supported method schemas. The schema command exposes offline validation through --validate, reports validation results, and preserves catalog rendering when validation is not selected. The README files document the option, input limits, and output behavior.

Changes: Schema Input Validation

Layer / File(s) Summary
Schema validation and numeric comparison
internal/schema/decimal.go, internal/schema/validate.go, internal/schema/validate_test.go
The schema package parses JSON with depth and duplicate-key checks, validates supported types and constraints, and reports capped violations with JSON Pointer paths. Decimal comparisons preserve numeric precision. Tests cover validation rules, limits, diagnostics, and numeric comparisons.
Schema command validation flow
cmd/schema/schema.go, cmd/schema/validate.go, cmd/schema/validate_test.go, cmd/schema_validation_test.go, README.md, README.zh.md
The command dispatches explicit --validate requests to method input validation and retains catalog rendering otherwise. Tests cover input sources, selectors, output, and error handling. The README files document usage and output behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SchemaCommand
  participant ValidateRun
  participant InputValidator
  User->>SchemaCommand: Select --validate for a method
  SchemaCommand->>ValidateRun: Dispatch validation request
  ValidateRun->>InputValidator: Check input against method schema
  InputValidator-->>ValidateRun: Return violations or valid result
  ValidateRun-->>User: Return success envelope or validation error
Loading
Merge Risk: Minimal · up to f18c2

This adds an opt-in offline schema --validate mode and leaves existing schema inspection unchanged. No concrete defect was found in the validator, the command wiring or the documentation, and the reported tests cover the main behaviors. The change is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(schema): add offline input validation" matches the main change: a new schema <method> --validate flag that validates input offline against the published inputSchema. It is short, spe…
Description check Passed The description follows the repository template. It has a Summary that states the motivation and scope, a Changes list, a Test Plan with checkboxes, and a Related Issues section stating None. It goes …
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 "feat(schema): add offline input validation" matches the main change: a new schema &lt;method&gt; --validate flag that validates input offline against the published inputSchema. It is short, specific, and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary that states the motivation and scope, a Changes list, a Test Plan with checkboxes, and a Related Issues section stating None. It goes beyond the template with Evidence and Merge Danger sections, which do not conflict with it. The Test Plan does not literally tick the 'Manual local verification' item in the template's form, but it reports built-CLI inline, file, and stdin checks, so the required information is present.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 18ca5ed4-4bab-4573-862d-855e4029d641
Commits

Reviewing files that changed from the base of the PR and between c5fbf1a and f18c2d7.

Files selected for processing: 9

  • README.md
  • README.zh.md
  • cmd/schema/schema.go
  • cmd/schema/validate.go
  • cmd/schema/validate_test.go
  • cmd/schema_validation_test.go
  • internal/schema/decimal.go
  • internal/schema/validate.go
  • internal/schema/validate_test.go

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

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Nov 25, 2026

This branch has not been deployed

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

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant