diff --git a/PLAN.md b/PLAN.md index 5157da4a..4137f5ce 100644 --- a/PLAN.md +++ b/PLAN.md @@ -1,262 +1,81 @@ -# Plan: `wait_for` Feature - DX Design +# Plan: Better Error Messages & Debuggability -## Overview - -A new `wait_for` block that repeatedly polls an endpoint until a condition is satisfied. Designed for async server operations that require time to complete (job processing, webhooks, eventual consistency, etc.). - -## DX Design - -### Basic Syntax - -```yaml -yapi: v1 -url: ${url}/jobs/${job_id} -method: GET - -wait_for: - until: - - .status == "completed" - period: 2s - timeout: 60s -``` - -### Fixed Period (Simple) - -```yaml -wait_for: - until: - - .status == "completed" - period: 2s # Fixed time between attempts - timeout: 60s # Total time limit -``` - -### Exponential Backoff - -```yaml -wait_for: - until: - - .status == "completed" - backoff: - seed: 1s # Initial wait time - multiplier: 2 # Each attempt waits multiplier * previous - timeout: 60s # Total time limit -``` - -Backoff example with `seed: 1s, multiplier: 2`: -- Attempt 1 → wait 1s -- Attempt 2 → wait 2s -- Attempt 3 → wait 4s -- Attempt 4 → wait 8s -- ...continues until timeout - -### Behavior - -1. Execute the request -2. If `until` conditions pass → success, stop polling -3. If `until` conditions fail OR request errors (5xx, network) → wait (period or backoff), retry -4. If `timeout` exceeded → fail with timeout error - -**Error handling**: Intermediate failures (5xx, network errors, 4xx) are treated as "not ready yet" and polling continues. Only timeout causes failure. - -**Timing**: Either `period` OR `backoff` must be specified (mutually exclusive). +## Context +Implementing WISHLIST.md items #1, #2, and #4 (removing #3 since `yapi send` already exists). --- -## Use Cases - -### 1. Single Request - Job Completion - -```yaml -yapi: v1 -url: ${url}/jobs/${job_id} -method: GET +## 1. WISHLIST.md cleanup +Remove item #3 (yapi send) since it's already shipped. -wait_for: - until: - - .status == "completed" or .status == "failed" - period: 2s - timeout: 120s - -expect: - status: 200 - assert: - - .status == "completed" # Final assertion after wait_for succeeds -``` - -### 2. Chain Step - Async Workflow - -```yaml -yapi: v1 -chain: - - name: create_job - url: ${url}/jobs - method: POST - body: - type: "data_export" - expect: - status: 202 - assert: - - .job_id != null - - - name: wait_for_job - url: ${url}/jobs/${create_job.job_id} - method: GET - wait_for: - until: - - .status == "completed" - backoff: - seed: 1s - multiplier: 2 - timeout: 300s - expect: - status: 200 - assert: - - .download_url != null - - - name: download_result - url: ${wait_for_job.download_url} - method: GET - output_file: ./export.csv -``` - -### 3. Webhook/Callback Waiting +--- -```yaml -yapi: v1 -chain: - - name: trigger_webhook - url: ${url}/webhooks/trigger - method: POST +## 2. Warn on bare `$word.word` variable syntax (WISHLIST #1) - - name: check_received - url: ${url}/webhooks/received - method: GET - wait_for: - until: - - . | length > 0 - - .[0].payload.event == "user.created" - period: 1s - timeout: 30s -``` +The problem: `$step.field` (no braces) silently passes as a literal string instead of being substituted. Only `${step.field}` works. -### 4. Database Eventual Consistency +**Changes:** -```yaml -yapi: v1 -chain: - - name: create_user - url: ${url}/users - method: POST - body: - email: "test@example.com" - expect: - status: 201 +- **`cli/internal/vars/vars.go`**: Add a `BareChainRef` regex that matches `$word.word` patterns that are NOT inside `${...}`. +- **`cli/internal/vars/vars.go`**: Add `FindBareRefs(s string) []string` that returns the bare refs found. +- **`cli/internal/validation/analyzer.go`**: In `analyzeParsed()`, call a new `warnBareChainRefs(text)` validation function that scans the raw YAML text for bare `$word.word` patterns and emits `SeverityWarning` diagnostics with line numbers and an actionable message like: + `"possible bare variable reference '$step.field' -- did you mean '${step.field}'? Only the ${...} form is substituted."` - - name: verify_searchable - url: ${url}/users/search?email=test@example.com - method: GET - wait_for: - until: - - . | length == 1 - period: 500ms - timeout: 10s -``` +This catches the problem at config analysis time (before execution), so users see the warning immediately -- even in `yapi validate`. --- -## Interaction with Existing Features - -### With `expect` +## 3. Show resolved request details in verbose chain execution (WISHLIST #2) -`wait_for` runs first. Once `until` conditions pass, `expect` runs on the final response: +The problem: When a chain step fails, you can't see what values were actually sent because variable substitution is invisible. -```yaml -wait_for: - until: - - .status != "pending" # Wait until not pending - period: 1s - timeout: 30s +**Changes:** -expect: - status: 200 - assert: - - .status == "completed" # Then verify it's completed (not failed) -``` +- **`cli/internal/runner/runner.go`**: Add `Verbose bool` field to `runner.Options`. +- **`cli/internal/runner/runner.go`**: In `RunChain()`, after `interpolateConfig()` succeeds and before executing, if `opts.Verbose` is true, print the resolved config to stderr: + - Resolved URL (with method) + - Resolved headers + - Resolved body (JSON-serialized if map, or raw if string) + - Uses `fmt.Fprintf(os.Stderr, ...)` with `[VERBOSE]` prefix, consistent with the existing Logger pattern. +- **`cli/cmd/yapi/run.go`**: Set `opts.Verbose = ctx.verbose` when building runner.Options in `executeRunE()`. -### With `timeout` - -The existing `timeout` field is per-request. `wait_for.timeout` is total polling time: - -```yaml -timeout: 5s # Each poll attempt times out after 5s +--- -wait_for: - until: - - .ready == true - period: 2s - timeout: 60s # Total polling time limit -``` +## 4. Print step responses in verbose chain mode (WISHLIST #4) -### With `delay` +The problem: In chain execution, you only see the final failing step's output, not intermediate step responses. -`delay` happens before `wait_for` starts: +**Changes:** -```yaml -delay: 5s # Wait 5s before starting to poll +- **`cli/internal/runner/runner.go`**: In `RunChain()`, after each step executes, if `opts.Verbose` is true, print the step's response details to stderr: + - Status code + - Response body (truncated at 1000 chars for readability) + - Duration -wait_for: - until: - - .status == "done" - period: 2s - timeout: 30s -``` + This replaces the need for a per-step `debug: true` field -- verbose mode shows everything, which is simpler and avoids new config surface area. --- -## Output During Polling +## 5. Example files: `examples/debugging/` -When running with verbose/default output: +Create example `.yapi.yml` files that demonstrate the improved debugging experience: -``` -[POLL] Attempt 1 - conditions not met, retrying in 2s... -[POLL] Attempt 2 - conditions not met, retrying in 2s... -[POLL] Attempt 3 - request failed (503), retrying in 2s... -[POLL] Attempt 4 - conditions met! -``` +- **`bare-variable-warning.yapi.yml`**: A chain that uses `$step.field` (bare) to trigger the new warning. +- **`chain-verbose-demo.yapi.yml`**: A multi-step chain against jsonplaceholder with variables that shows how `--verbose` reveals resolved values. +- **`assertion-failure-demo.yapi.yml`**: A request with an `expect:` block that will fail, showing the detailed assertion error output. +- **`missing-key-demo.yapi.yml`**: A chain that references a nonexistent JSON key, showing the precise error path. --- -## Config Schema - -```go -type Backoff struct { - Seed string `yaml:"seed"` // Initial wait, e.g., "1s" - Multiplier float64 `yaml:"multiplier"` // e.g., 2 -} - -type WaitFor struct { - Until []string `yaml:"until"` // Required: JQ assertions - Period string `yaml:"period,omitempty"` // Fixed interval, e.g., "2s" - Backoff *Backoff `yaml:"backoff,omitempty"` // Exponential backoff - Timeout string `yaml:"timeout"` // Required: total time limit -} -``` - -Added to `ConfigV1`: -```go -type ConfigV1 struct { - // ... existing fields ... - WaitFor *WaitFor `yaml:"wait_for,omitempty"` -} -``` - ---- +## Files changed -## Validation Rules +| File | Change | +|------|--------| +| `WISHLIST.md` | Remove item #3 | +| `cli/internal/vars/vars.go` | Add `BareChainRef` regex + `FindBareRefs()` function | +| `cli/internal/validation/analyzer.go` | Add `warnBareChainRefs()`, call from `analyzeParsed()` | +| `cli/internal/runner/runner.go` | Add `Verbose` to `Options`, add verbose logging in `RunChain()` | +| `cli/cmd/yapi/run.go` | Thread `verbose` into `runner.Options` | +| `examples/debugging/*.yapi.yml` | 4 new example files | -1. `until` is required and must have at least one assertion -2. `timeout` is required and must be valid Go duration -3. Exactly one of `period` OR `backoff` must be specified (mutually exclusive) -4. If `period`: must be valid Go duration -5. If `backoff`: `seed` must be valid Go duration, `multiplier` must be > 1 -6. All `until` expressions must be valid JQ +**No new dependencies. No config schema changes. No breaking changes.** diff --git a/WISHLIST.md b/WISHLIST.md new file mode 100644 index 00000000..ecd921c8 --- /dev/null +++ b/WISHLIST.md @@ -0,0 +1,21 @@ +# YAPI Wishlist + +Issues encountered while writing MIDI clip note tests against the Ableton Live Remote Script. + +## 1. Chain variable syntax not documented clearly + +YAPI uses `${step.result.field}` (curly braces required), but the old docs and some examples show `$step.result.field` (bare dollar sign). The bare form is silently passed as a literal string rather than substituted, which makes debugging painful — the Remote Script receives the string `"$create_track.result.index"` instead of `3`. + +**Wish:** Either support both forms, or emit a clear warning when a string matching `$word.word` is found without braces. + +## 2. No way to inspect resolved variable values + +When a chain step fails, the output shows the raw response but not the resolved parameter values that were sent. If variable substitution silently fails (e.g., wrong syntax), you can't tell from the output. + +**Wish:** Show the resolved request body in verbose/debug mode so you can verify what was actually sent over the wire. + +## 3. No way to print step results mid-chain for debugging + +When a chain step fails, you get the response for the failing step but not intermediate steps (unless you scroll through the full output). Being able to mark a step as `debug: true` to print its full response would help. + +**Wish:** `debug: true` on chain steps to always print the full response body, or a `--verbose` flag that prints all step responses. diff --git a/cli/cmd/yapi/run.go b/cli/cmd/yapi/run.go index e07b9040..7abf6f64 100644 --- a/cli/cmd/yapi/run.go +++ b/cli/cmd/yapi/run.go @@ -206,6 +206,7 @@ func (app *rootCommand) executeRunE(ctx runContext) error { NoColor: app.noColor, BinaryOutput: app.binaryOutput, Insecure: app.insecure, + Verbose: ctx.verbose, ConfigFilePath: ctx.path, StrictEnv: ctx.strictEnv, } diff --git a/cli/internal/runner/runner.go b/cli/internal/runner/runner.go index 0ed1cee3..b911b2af 100644 --- a/cli/internal/runner/runner.go +++ b/cli/internal/runner/runner.go @@ -16,6 +16,7 @@ import ( "yapi.run/cli/internal/domain" "yapi.run/cli/internal/executor" "yapi.run/cli/internal/filter" + "yapi.run/cli/internal/vars" ) const ( @@ -44,6 +45,7 @@ type Options struct { NoColor bool BinaryOutput bool Insecure bool + Verbose bool // Show resolved request/response details during execution EnvOverrides map[string]string // Environment variables from project config ProjectRoot string // Path to project root (for validation) ProjectEnv string // Selected environment name (for validation) @@ -342,12 +344,20 @@ func RunChain(ctx context.Context, factory ExecutorFactory, base *config.ConfigV // 1. Merge step with base config to get full config merged := base.Merge(step) + // 1b. Warn about bare $word.word patterns that won't be substituted + warnBareChainRefsInConfig(step.Name, &merged) + // 2. Interpolate variables in the merged config interpolatedConfig, err := interpolateConfig(chainCtx, &merged) if err != nil { return nil, fmt.Errorf("step '%s': %w", step.Name, err) } + // 2b. Verbose: show resolved request details + if opts.Verbose { + logResolvedConfig(i+1, step.Name, interpolatedConfig) + } + // 3. Handle Delay (wait before executing step) if interpolatedConfig.Delay != "" { d, err := time.ParseDuration(interpolatedConfig.Delay) @@ -392,6 +402,11 @@ func RunChain(ctx context.Context, factory ExecutorFactory, base *config.ConfigV } } + // 6b. Verbose: show response details + if opts.Verbose { + logStepResponse(i+1, step.Name, result) + } + // 7. Assert Expectations expectRes := CheckExpectationsWithEnv(step.Expect, result, opts.EnvOverrides) @@ -409,6 +424,83 @@ func RunChain(ctx context.Context, factory ExecutorFactory, base *config.ConfigV return chainResult, nil } +const verboseMaxLen = 1000 + +// truncateStr truncates s for verbose output at a valid UTF-8 boundary. +func truncateStr(s string) string { + if len(s) <= verboseMaxLen { + return s + } + // Walk back to avoid splitting a multi-byte UTF-8 character + cut := verboseMaxLen + for cut > 0 && s[cut-1]&0xC0 == 0x80 { + cut-- + } + if cut > 0 && s[cut-1]&0x80 != 0 { + cut-- // skip the leading byte of the split character + } + return s[:cut] + fmt.Sprintf("... (%d bytes total)", len(s)) +} + +// logResolvedConfig prints the resolved request config to stderr for debugging. +func logResolvedConfig(stepNum int, stepName string, cfg *config.ConfigV1) { + fmt.Fprintf(os.Stderr, "[VERBOSE] Step %d (%s) resolved request:\n", stepNum, stepName) + if cfg.Method != "" || cfg.URL != "" { + fmt.Fprintf(os.Stderr, "[VERBOSE] %s %s\n", cfg.Method, cfg.URL) + } + if cfg.Path != "" { + fmt.Fprintf(os.Stderr, "[VERBOSE] Path: %s\n", cfg.Path) + } + for k, v := range cfg.Headers { + fmt.Fprintf(os.Stderr, "[VERBOSE] Header: %s: %s\n", k, v) + } + if cfg.Body != nil { + bodyJSON, err := json.Marshal(cfg.Body) + if err == nil { + fmt.Fprintf(os.Stderr, "[VERBOSE] Body: %s\n", truncateStr(string(bodyJSON))) + } + } + if cfg.JSON != "" { + fmt.Fprintf(os.Stderr, "[VERBOSE] JSON: %s\n", truncateStr(cfg.JSON)) + } + if cfg.Data != "" { + fmt.Fprintf(os.Stderr, "[VERBOSE] Data: %s\n", truncateStr(cfg.Data)) + } +} + +// logStepResponse prints response details to stderr for debugging. +func logStepResponse(stepNum int, stepName string, result *Result) { + fmt.Fprintf(os.Stderr, "[VERBOSE] Step %d (%s) response:\n", stepNum, stepName) + fmt.Fprintf(os.Stderr, "[VERBOSE] Status: %d\n", result.StatusCode) + fmt.Fprintf(os.Stderr, "[VERBOSE] Duration: %s\n", result.Duration) + if result.Body != "" { + fmt.Fprintf(os.Stderr, "[VERBOSE] Body: %s\n", truncateStr(result.Body)) + } +} + +// warnBareChainRefsInConfig checks a config's string fields for bare $word.word patterns +// and prints warnings to stderr during chain execution. +func warnBareChainRefsInConfig(stepName string, cfg *config.ConfigV1) { + check := func(field, value string) { + refs := vars.FindBareRefs(value) + for _, ref := range refs { + fmt.Fprintf(os.Stderr, "[WARN] step '%s' %s: possible bare variable '%s' -- did you mean '${%s}'?\n", + stepName, field, ref, ref[1:]) + } + } + + check("url", cfg.URL) + check("path", cfg.Path) + check("json", cfg.JSON) + check("data", cfg.Data) + for k, v := range cfg.Headers { + check(fmt.Sprintf("header '%s'", k), v) + } + for k, v := range cfg.Query { + check(fmt.Sprintf("query '%s'", k), v) + } +} + // interpolateConfig expands chain variables in a config func interpolateConfig(chainCtx *ChainContext, cfg *config.ConfigV1) (*config.ConfigV1, error) { result := *cfg // Copy diff --git a/cli/internal/validation/analyzer.go b/cli/internal/validation/analyzer.go index 6e055e6b..27cdcfef 100644 --- a/cli/internal/validation/analyzer.go +++ b/cli/internal/validation/analyzer.go @@ -260,6 +260,8 @@ func analyzeParsed(text string, parseRes *config.ParseResult, project *config.Pr diags = append(diags, validateEnvVarsWithEnvFiles(text, envFileVarNames)...) } + diags = append(diags, warnBareChainRefs(text)...) + return &Analysis{ Chain: parseRes.Chain, Base: parseRes.Base, @@ -304,6 +306,8 @@ func analyzeParsed(text string, parseRes *config.ParseResult, project *config.Pr diags = append(diags, ValidateChainAssertions(text, parseRes.WaitFor.Until, "wait_for")...) } + diags = append(diags, warnBareChainRefs(text)...) + return &Analysis{ Request: req, Diagnostics: diags, @@ -521,6 +525,35 @@ func scanForUndefinedRefs(text, value string, definedSteps map[string]bool, curr return diags } +// warnBareChainRefs scans YAML text for bare $word.word patterns that look like +// chain variable references but aren't wrapped in ${...}, which means they won't +// be substituted. Emits a warning diagnostic for each occurrence. +func warnBareChainRefs(text string) []Diagnostic { + var diags []Diagnostic + lines := strings.Split(text, "\n") + + for lineNum, line := range lines { + trimmed := strings.TrimSpace(line) + // Skip comments and graphql blocks (which use $var syntax legitimately) + if strings.HasPrefix(trimmed, "#") { + continue + } + + bareRefs := vars.FindBareRefs(line) + for _, ref := range bareRefs { + col := strings.Index(line, ref) + diags = append(diags, Diagnostic{ + Severity: SeverityWarning, + Field: "", + Message: fmt.Sprintf("possible bare variable reference '%s' -- did you mean '${%s}'? Only the ${...} form is substituted", ref, ref[1:]), + Line: lineNum, + Col: col, + }) + } + } + return diags +} + // EnvVarInfo holds information about an env var reference for hover/diagnostics type EnvVarInfo struct { Name string diff --git a/cli/internal/vars/vars.go b/cli/internal/vars/vars.go index f1e58f8a..63eb68f8 100644 --- a/cli/internal/vars/vars.go +++ b/cli/internal/vars/vars.go @@ -31,6 +31,26 @@ func HasEnvVars(s string) bool { return EnvOnly.MatchString(s) } +// BareChainRef matches bare $word.word patterns (without braces) that look like +// chain variable references. Negative lookbehind for { ensures we don't match ${...}. +// We use a two-step approach: find all $word.word patterns, then exclude those inside ${}. +var BareChainRef = regexp.MustCompile(`\$([A-Za-z_][A-Za-z0-9_]*\.[A-Za-z0-9_.]+)`) + +// FindBareRefs returns bare chain-style references ($step.field) that are NOT +// wrapped in ${...}. These are likely user mistakes since only ${...} is substituted. +func FindBareRefs(s string) []string { + var results []string + for _, loc := range BareChainRef.FindAllStringIndex(s, -1) { + start := loc[0] + // Check that this is not inside ${...} by looking for a preceding { + if start > 0 && s[start-1] == '{' { + continue + } + results = append(results, s[start:loc[1]]) + } + return results +} + // ExpandString replaces all ${VAR} occurrences in input using the resolver. func ExpandString(input string, resolver Resolver) (string, error) { var capturedErr error diff --git a/cli/internal/vars/vars_test.go b/cli/internal/vars/vars_test.go index fd5e3a81..fc3d8a3a 100644 --- a/cli/internal/vars/vars_test.go +++ b/cli/internal/vars/vars_test.go @@ -59,6 +59,39 @@ func TestExpandString(t *testing.T) { } } +func TestFindBareRefs(t *testing.T) { + tests := []struct { + name string + input string + want []string + }{ + {"no refs", "hello world", nil}, + {"bare ref", "$step.field", []string{"$step.field"}}, + {"wrapped ref not matched", "${step.field}", nil}, + {"bare among text", "url: http://example.com/$step.id/path", []string{"$step.id"}}, + {"multiple bare refs", "$a.b and $c.d", []string{"$a.b", "$c.d"}}, + {"mixed bare and wrapped", "$bare.ref and ${wrapped.ref}", []string{"$bare.ref"}}, + {"no dot no match", "$FOO", nil}, + {"deep ref", "$step.response.body", []string{"$step.response.body"}}, + {"dollar amount", "$100", nil}, + {"bcrypt hash", "$2a$12$hash", nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := FindBareRefs(tt.input) + if len(got) != len(tt.want) { + t.Fatalf("FindBareRefs(%q) = %v, want %v", tt.input, got, tt.want) + } + for i := range got { + if got[i] != tt.want[i] { + t.Errorf("FindBareRefs(%q)[%d] = %q, want %q", tt.input, i, got[i], tt.want[i]) + } + } + }) + } +} + func FuzzExpandString(f *testing.F) { // Seed with various variable patterns (only ${VAR} form supported) f.Add("hello world") diff --git a/examples/debugging/assertion-failure-demo.yapi.yml b/examples/debugging/assertion-failure-demo.yapi.yml new file mode 100644 index 00000000..84f72eef --- /dev/null +++ b/examples/debugging/assertion-failure-demo.yapi.yml @@ -0,0 +1,27 @@ +# Demonstrates detailed assertion failure messages. +# +# This request intentionally asserts wrong values so you can see +# the error output format with expected vs actual values. +# +# Run with: +# yapi run assertion-failure-demo.yapi.yml +# +# Expected output: +# [PASS] .userId != null +# [FAIL] .id == 999 +# [FAIL] .title == "wrong title" +# +# assertion failed +# Expected: .id to equal 999 +# Actual: .id = 1 +# Expression: .id == 999 + +yapi: v1 +url: https://jsonplaceholder.typicode.com/todos/1 +method: GET +expect: + status: 200 + assert: + - .userId != null + - .id == 999 + - .title == "wrong title" diff --git a/examples/debugging/bare-variable-warning.yapi.yml b/examples/debugging/bare-variable-warning.yapi.yml new file mode 100644 index 00000000..08a36c8a --- /dev/null +++ b/examples/debugging/bare-variable-warning.yapi.yml @@ -0,0 +1,26 @@ +# Demonstrates the bare variable warning. +# +# This chain uses $step.field (bare dollar sign) instead of ${step.field}. +# The bare form is NOT substituted -- it's passed as the literal string +# "$get_todo.userId". yapi now warns about this at validation time. +# +# Run with: +# yapi validate bare-variable-warning.yapi.yml +# yapi run bare-variable-warning.yapi.yml +# +# Expected output: +# [WARN] line 25: possible bare variable reference '$get_todo.userId' +# -- did you mean '${get_todo.userId}'? Only the ${...} form is substituted + +yapi: v1 +chain: + - name: get_todo + url: https://jsonplaceholder.typicode.com/todos/1 + method: GET + expect: + status: 200 + + - name: get_user + # BUG: This should be ${get_todo.userId} -- note the missing braces! + url: https://jsonplaceholder.typicode.com/users/$get_todo.userId + method: GET diff --git a/examples/debugging/chain-verbose-demo.yapi.yml b/examples/debugging/chain-verbose-demo.yapi.yml new file mode 100644 index 00000000..3fb38007 --- /dev/null +++ b/examples/debugging/chain-verbose-demo.yapi.yml @@ -0,0 +1,37 @@ +# Demonstrates --verbose mode for chain debugging. +# +# This chain fetches a todo, then uses its userId to fetch the user. +# With --verbose, you can see exactly what URL/body was sent after +# variable substitution, plus each step's response body. +# +# Run with: +# yapi run chain-verbose-demo.yapi.yml --verbose +# +# Verbose output will show: +# [VERBOSE] Step 1 (get_todo) resolved request: +# [VERBOSE] GET https://jsonplaceholder.typicode.com/todos/1 +# [VERBOSE] Step 1 (get_todo) response: +# [VERBOSE] Status: 200 +# [VERBOSE] Body: {"userId":1,"id":1,"title":"delectus aut autem",...} +# [VERBOSE] Step 2 (get_user) resolved request: +# [VERBOSE] GET https://jsonplaceholder.typicode.com/users/1 +# ... + +yapi: v1 +chain: + - name: get_todo + url: https://jsonplaceholder.typicode.com/todos/1 + method: GET + expect: + status: 200 + assert: + - .userId != null + + - name: get_user + url: https://jsonplaceholder.typicode.com/users/${get_todo.userId} + method: GET + expect: + status: 200 + assert: + - .name != null + - .email != null diff --git a/examples/debugging/missing-key-demo.yapi.yml b/examples/debugging/missing-key-demo.yapi.yml new file mode 100644 index 00000000..fa8cf895 --- /dev/null +++ b/examples/debugging/missing-key-demo.yapi.yml @@ -0,0 +1,23 @@ +# Demonstrates the error when referencing a nonexistent JSON key. +# +# The second step references ${get_todo.nonexistent_field}, which +# doesn't exist in the response. yapi provides a precise error +# showing exactly which key was missing and at what path. +# +# Run with: +# yapi run missing-key-demo.yapi.yml +# +# Expected output: +# step 'get_user': url: key 'nonexistent_field' not found at path 'nonexistent_field' + +yapi: v1 +chain: + - name: get_todo + url: https://jsonplaceholder.typicode.com/todos/1 + method: GET + expect: + status: 200 + + - name: get_user + url: https://jsonplaceholder.typicode.com/users/${get_todo.nonexistent_field} + method: GET