// wirecheck validates JSON values against docs/openapi.yaml for the // openapi_encodings contract (robot-docs/testing.md#cross-language-contracts). // // It reads one batch per line on stdin, a JSON array of {"schema", "value"} // cases, and writes one line per batch: an array holding, for each case, "" // when the value matches the component schema and the validation error // otherwise. The first argument is the repository root. package main import ( "bufio" "encoding/json" "fmt" "os" "albedo/cli/internal/testwire" ) type check struct { Schema string `json:"schema"` Value any `json:"value"` } func main() { if len(os.Args) != 2 { fmt.Fprintln(os.Stderr, "usage: wirecheck ") os.Exit(2) } contract, err := testwire.LoadContract(os.Args[1]) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } scanner := bufio.NewScanner(os.Stdin) scanner.Buffer(make([]byte, 0, 1<<20), 64<<20) out := bufio.NewWriter(os.Stdout) for scanner.Scan() { var batch []check if err := json.Unmarshal(scanner.Bytes(), &batch); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } results := make([]string, len(batch)) for index, item := range batch { if err := contract.ValidateComponent(item.Schema, item.Value); err != nil { results[index] = err.Error() } } encoded, _ := json.Marshal(results) _, _ = out.Write(append(encoded, '\n')) _ = out.Flush() } if err := scanner.Err(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }