Repository navigation
fix: load cluster stats schema #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix/cat-column-lists
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,17 +58,40 @@ export async function loadEsApisInFile (namespaceFile: string): Promise<EsApiDef | |
| if (!Array.isArray(arr)) { | ||
| throw new Error(`internal error: ${namespaceFile}.js did not export ${exportKey}`) | ||
| } | ||
| return Promise.all((arr as EsApiDefinition[]).map(resolveDefinition)) | ||
| return Promise.all((arr as EsApiDefinition[]).map(async (def) => { | ||
| return resolveDefinition(await attachMissingRequestSchema(namespaceFile, def)) | ||
| })) | ||
| })() | ||
| moduleCache.set(namespaceFile, cached) | ||
| return cached | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| } | ||
| } | ||
|
Comment on lines
+69
to
+88
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The root cause is upstream: the schemas-js generator emits Instead of patching this here, we should fix the code generator or ES spec so all schemas-js consumers get the fix. |
||
|
|
||
| /** Locates a single `EsApiDefinition` by its manifest entry. */ | ||
| export async function loadEsApi (meta: EsApiMeta): Promise<EsApiDefinition> { | ||
| const defs = await loadEsApisInFile(meta.namespaceFile) | ||
| const found = defs.find( | ||
| (d) => d.name === meta.name && (d.namespace ?? null) === meta.namespace | ||
| (d) => d.name === meta.name && (d.namespace ?? null) === (meta.namespace ?? null) | ||
| ) | ||
| if (found == null) { | ||
| const label = meta.namespace != null ? `${meta.namespace} ${meta.name}` : meta.name | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This attaches
cluster.stats.request.jsonas-is, which marksnode_idasx-found-in: "body"even though it is really a path param in/_cluster/stats/nodes/{node_id}. The resulting--node-idflag builds a broken request.So the node filter is silently dropped from the URL and sent as a GET body instead, while
--dry-runreports the inputs as valid.