Repository navigation
fix: load cluster stats schema - #841
margaretjgu wants to merge 3 commits into
Conversation
|
👋 This PR can use the first-failure repair loop on GitHub Actions and Buildkite. Labels
Comments
|
|
What failed: The test 'uses the request schema when the tool definition has no input' fails because attachMissingRequestSchema silently skips attaching the request schema when the loaded JSON does not have a top-level Resolution: change src/es/apis.ts to remove the Build: https://buildkite.com/elastic/elastic-cli/builds/2495 |
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
Startup perf: PR vs merge-base ✅
|
| `@elastic/schemas/es/json/${namespaceFile}.request.json`, | ||
| ) | ||
| if (input == null || typeof input !== 'object' || Array.isArray(input) || input['properties'] == null) return def | ||
| return { ...def, input } |
There was a problem hiding this comment.
This attaches cluster.stats.request.json as-is, which marks node_id as x-found-in: "body" even though it is really a path param in /_cluster/stats/nodes/{node_id}. The resulting --node-id flag builds a broken request.
So the node filter is silently dropped from the URL and sent as a GET body instead, while --dry-run reports the inputs as valid.
| /** | ||
| * The tool definition for `cluster.stats` ships without `input` because an | ||
| * optional path param is not on the selected URL. The request schema is still | ||
| * published next to it, and that schema has the query params (`filter_path`, | ||
| * `human`, `timeout`). | ||
| */ | ||
| async function attachMissingRequestSchema (namespaceFile: string, def: EsApiDefinition): Promise<EsApiDefinition> { | ||
| if (def.input != null) return def | ||
| try { | ||
| const input = await requireSchemaModule<Record<string, unknown>>( | ||
| `@elastic/schemas/es/json/${namespaceFile}.request.json`, | ||
| ) | ||
| if (input == null || typeof input !== 'object' || Array.isArray(input) || input['properties'] == null) return def | ||
| return { ...def, input } | ||
| } catch (err) { | ||
| const code = (err as NodeJS.ErrnoException).code | ||
| if (code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') return def | ||
| throw err | ||
| } | ||
| } |
There was a problem hiding this comment.
The root cause is upstream: the schemas-js generator emits cluster_stats_definitions without input, and the request schema it would use has the wrong x-found-in for node_id.
Instead of patching this here, we should fix the code generator or ES spec so all schemas-js consumers get the fix.
Load the cluster stats request schema when the tool definition has no input. Relates to #839.