From 06754b7072f615dea1b0a281ab423b77ebad17e9 Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Thu, 24 Oct 2024 08:11:24 -0400 Subject: [PATCH] Add specification for query rule test API (#3029) * Add query rules tester spec * code style + output * Update specification/query_rules/test/QueryRulesetTestRequest.ts Co-authored-by: Quentin Pradet * PR feedback --------- Co-authored-by: Laura Trotta Co-authored-by: Quentin Pradet (cherry picked from commit d14e088849c61e8113e611a9751d87b04f8f9b6c) --- output/openapi/elasticsearch-openapi.json | 47 +++-- .../elasticsearch-serverless-openapi.json | 47 +++-- output/schema/schema-serverless.json | 96 +++++++--- output/schema/schema.json | 166 ++++++++++++++++++ output/typescript/types.ts | 17 ++ .../_json_spec/query_rules.test.json | 32 ++++ .../test/QueryRulesetTestRequest.ts | 44 +++++ .../test/QueryRulesetTestResponse.ts | 39 ++++ 8 files changed, 428 insertions(+), 60 deletions(-) create mode 100644 specification/_json_spec/query_rules.test.json create mode 100644 specification/query_rules/test/QueryRulesetTestRequest.ts create mode 100644 specification/query_rules/test/QueryRulesetTestResponse.ts diff --git a/output/openapi/elasticsearch-openapi.json b/output/openapi/elasticsearch-openapi.json index 7314000993..5712739659 100644 --- a/output/openapi/elasticsearch-openapi.json +++ b/output/openapi/elasticsearch-openapi.json @@ -24068,22 +24068,15 @@ "schema": { "type": "object", "properties": { - "rules": { - "oneOf": [ - { - "$ref": "#/components/schemas/query_rules._types:QueryRule" - }, - { - "type": "array", - "items": { - "$ref": "#/components/schemas/query_rules._types:QueryRule" - } - } - ] + "match_criteria": { + "type": "object", + "additionalProperties": { + "type": "object" + } } }, "required": [ - "rules" + "match_criteria" ] } } @@ -24098,12 +24091,19 @@ "schema": { "type": "object", "properties": { - "result": { - "$ref": "#/components/schemas/_types:Result" + "total_matched_rules": { + "type": "number" + }, + "matched_rules": { + "type": "array", + "items": { + "$ref": "#/components/schemas/query_rules.test:QueryRulesetMatchedRule" + } } }, "required": [ - "result" + "total_matched_rules", + "matched_rules" ] } } @@ -79508,6 +79508,21 @@ "rule_criteria_types_counts" ] }, + "query_rules.test:QueryRulesetMatchedRule": { + "type": "object", + "properties": { + "ruleset_id": { + "$ref": "#/components/schemas/_types:Id" + }, + "rule_id": { + "$ref": "#/components/schemas/_types:Id" + } + }, + "required": [ + "ruleset_id", + "rule_id" + ] + }, "_global.rank_eval:RankEvalRequestItem": { "type": "object", "properties": { diff --git a/output/openapi/elasticsearch-serverless-openapi.json b/output/openapi/elasticsearch-serverless-openapi.json index 10929c7637..88afa05be8 100644 --- a/output/openapi/elasticsearch-serverless-openapi.json +++ b/output/openapi/elasticsearch-serverless-openapi.json @@ -14908,22 +14908,15 @@ "schema": { "type": "object", "properties": { - "rules": { - "oneOf": [ - { - "$ref": "#/components/schemas/query_rules._types:QueryRule" - }, - { - "type": "array", - "items": { - "$ref": "#/components/schemas/query_rules._types:QueryRule" - } - } - ] + "match_criteria": { + "type": "object", + "additionalProperties": { + "type": "object" + } } }, "required": [ - "rules" + "match_criteria" ] } } @@ -14938,12 +14931,19 @@ "schema": { "type": "object", "properties": { - "result": { - "$ref": "#/components/schemas/_types:Result" + "total_matched_rules": { + "type": "number" + }, + "matched_rules": { + "type": "array", + "items": { + "$ref": "#/components/schemas/query_rules.test:QueryRulesetMatchedRule" + } } }, "required": [ - "result" + "total_matched_rules", + "matched_rules" ] } } @@ -52758,6 +52758,21 @@ "rule_criteria_types_counts" ] }, + "query_rules.test:QueryRulesetMatchedRule": { + "type": "object", + "properties": { + "ruleset_id": { + "$ref": "#/components/schemas/_types:Id" + }, + "rule_id": { + "$ref": "#/components/schemas/_types:Id" + } + }, + "required": [ + "ruleset_id", + "rule_id" + ] + }, "_global.rank_eval:RankEvalRequestItem": { "type": "object", "properties": { diff --git a/output/schema/schema-serverless.json b/output/schema/schema-serverless.json index 504b1ef956..562b83f243 100644 --- a/output/schema/schema-serverless.json +++ b/output/schema/schema-serverless.json @@ -7765,7 +7765,7 @@ "name": "query_rules.put_ruleset", "request": { "name": "Request", - "namespace": "query_rules.put_ruleset" + "namespace": "query_rules.test" }, "requestBodyRequired": true, "requestMediaType": [ @@ -7773,7 +7773,7 @@ ], "response": { "name": "Response", - "namespace": "query_rules.put_ruleset" + "namespace": "query_rules.test" }, "responseMediaType": [ "application/json" @@ -35255,29 +35255,21 @@ "kind": "properties", "properties": [ { - "name": "rules", + "name": "match_criteria", "required": true, "type": { - "items": [ - { - "kind": "instance_of", - "type": { - "name": "QueryRule", - "namespace": "query_rules._types" - } - }, - { - "kind": "array_of", - "value": { - "kind": "instance_of", - "type": { - "name": "QueryRule", - "namespace": "query_rules._types" - } - } + "key": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" } - ], - "kind": "union_of" + }, + "kind": "dictionary_of", + "singleKey": false, + "value": { + "kind": "user_defined_value" + } } } ] @@ -35292,7 +35284,7 @@ "kind": "request", "name": { "name": "Request", - "namespace": "query_rules.put_ruleset" + "namespace": "query_rules.test" }, "path": [ { @@ -35309,31 +35301,45 @@ } ], "query": [], - "specLocation": "query_rules/put_ruleset/QueryRulesetPutRequest.ts#L23-L43" + "specLocation": "query_rules/test/QueryRulesetTestRequest.ts#L24-L44" }, { "body": { "kind": "properties", "properties": [ { - "name": "result", + "name": "total_matched_rules", "required": true, "type": { "kind": "instance_of", "type": { - "name": "Result", + "name": "integer", "namespace": "_types" } } + }, + { + "name": "matched_rules", + "required": true, + "type": { + "kind": "array_of", + "value": { + "kind": "instance_of", + "type": { + "name": "QueryRulesetMatchedRule", + "namespace": "query_rules.test" + } + } + } } ] }, "kind": "response", "name": { "name": "Response", - "namespace": "query_rules.put_ruleset" + "namespace": "query_rules.test" }, - "specLocation": "query_rules/put_ruleset/QueryRulesetPutResponse.ts#L22-L26" + "specLocation": "query_rules/test/QueryRulesetTestResponse.ts#L23-L28" }, { "attachedBehaviors": [ @@ -137480,6 +137486,40 @@ ], "specLocation": "query_rules/list_rulesets/types.ts#L23-L37" }, + { + "kind": "interface", + "name": { + "name": "QueryRulesetMatchedRule", + "namespace": "query_rules.test" + }, + "properties": [ + { + "description": "Ruleset unique identifier", + "name": "ruleset_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + }, + { + "description": "Rule unique identifier within that ruleset", + "name": "rule_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + } + ], + "specLocation": "query_rules/test/types.ts#L21-L30" + }, { "kind": "interface", "name": { diff --git a/output/schema/schema.json b/output/schema/schema.json index 087c57df0c..a7ce71bd3b 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -13753,6 +13753,44 @@ } ] }, + { + "availability": { + "serverless": { + "stability": "stable", + "visibility": "public" + }, + "stack": { + "since": "8.10.0", + "stability": "stable" + } + }, + "description": "Creates or updates a query ruleset.", + "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/master/test-query-ruleset.html", + "name": "query_rules.test", + "request": { + "name": "Request", + "namespace": "query_rules.test" + }, + "requestBodyRequired": true, + "requestMediaType": [ + "application/json" + ], + "response": { + "name": "Response", + "namespace": "query_rules.test" + }, + "responseMediaType": [ + "application/json" + ], + "urls": [ + { + "methods": [ + "POST" + ], + "path": "/_query_rules/{ruleset_id}/_test" + } + ] + }, { "availability": { "serverless": { @@ -182641,6 +182679,134 @@ }, "specLocation": "query_rules/put_ruleset/QueryRulesetPutResponse.ts#L22-L26" }, + { + "kind": "interface", + "name": { + "name": "QueryRulesetMatchedRule", + "namespace": "query_rules.test" + }, + "properties": [ + { + "description": "Ruleset unique identifier", + "name": "ruleset_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + }, + { + "description": "Rule unique identifier within that ruleset", + "name": "rule_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + } + ], + "specLocation": "query_rules/test/QueryRulesetTestResponse.ts#L30-L39" + }, + { + "kind": "request", + "attachedBehaviors": [ + "CommonQueryParameters" + ], + "body": { + "kind": "properties", + "properties": [ + { + "name": "match_criteria", + "required": true, + "type": { + "kind": "dictionary_of", + "key": { + "kind": "instance_of", + "type": { + "name": "string", + "namespace": "_builtins" + } + }, + "singleKey": false, + "value": { + "kind": "user_defined_value" + } + } + } + ] + }, + "description": "Creates or updates a query ruleset.", + "inherits": { + "type": { + "name": "RequestBase", + "namespace": "_types" + } + }, + "name": { + "name": "Request", + "namespace": "query_rules.test" + }, + "path": [ + { + "description": "The unique identifier of the query ruleset to be created or updated", + "name": "ruleset_id", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "Id", + "namespace": "_types" + } + } + } + ], + "query": [], + "specLocation": "query_rules/test/QueryRulesetTestRequest.ts#L24-L44" + }, + { + "kind": "response", + "body": { + "kind": "properties", + "properties": [ + { + "name": "total_matched_rules", + "required": true, + "type": { + "kind": "instance_of", + "type": { + "name": "integer", + "namespace": "_types" + } + } + }, + { + "name": "matched_rules", + "required": true, + "type": { + "kind": "array_of", + "value": { + "kind": "instance_of", + "type": { + "name": "QueryRulesetMatchedRule", + "namespace": "query_rules.test" + } + } + } + } + ] + }, + "name": { + "name": "Response", + "namespace": "query_rules.test" + }, + "specLocation": "query_rules/test/QueryRulesetTestResponse.ts#L23-L28" + }, { "kind": "interface", "name": { diff --git a/output/typescript/types.ts b/output/typescript/types.ts index 1f7abf22f9..f570d05b57 100644 --- a/output/typescript/types.ts +++ b/output/typescript/types.ts @@ -17193,6 +17193,23 @@ export interface QueryRulesPutRulesetResponse { result: Result } +export interface QueryRulesTestQueryRulesetMatchedRule { + ruleset_id: Id + rule_id: Id +} + +export interface QueryRulesTestRequest extends RequestBase { + ruleset_id: Id + body?: { + match_criteria: Record + } +} + +export interface QueryRulesTestResponse { + total_matched_rules: integer + matched_rules: QueryRulesTestQueryRulesetMatchedRule[] +} + export interface RollupDateHistogramGrouping { delay?: Duration field: Field diff --git a/specification/_json_spec/query_rules.test.json b/specification/_json_spec/query_rules.test.json new file mode 100644 index 0000000000..43167c765b --- /dev/null +++ b/specification/_json_spec/query_rules.test.json @@ -0,0 +1,32 @@ +{ + "query_rules.test": { + "documentation": { + "url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/test-query-ruleset.html", + "description": "Tests a query ruleset to identify the rules that would match input criteria" + }, + "stability": "experimental", + "visibility": "public", + "headers": { + "accept": ["application/json"], + "content_type": ["application/json"] + }, + "url": { + "paths": [ + { + "path": "/_query_rules/{ruleset_id}/_test", + "methods": ["POST"], + "parts": { + "ruleset_id": { + "type": "string", + "description": "The unique identifier of the ruleset to test." + } + } + } + ] + }, + "body": { + "description": "The match criteria to test against the ruleset", + "required": true + } + } +} diff --git a/specification/query_rules/test/QueryRulesetTestRequest.ts b/specification/query_rules/test/QueryRulesetTestRequest.ts new file mode 100644 index 0000000000..78f1e493bd --- /dev/null +++ b/specification/query_rules/test/QueryRulesetTestRequest.ts @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { Dictionary } from '@spec_utils/Dictionary' +import { UserDefinedValue } from '@spec_utils/UserDefinedValue' +import { RequestBase } from '@_types/Base' +import { Id } from '@_types/common' + +/** + * Creates or updates a query ruleset. + * @rest_spec_name query_rules.test + * @availability stack since=8.10.0 stability=stable + * @availability serverless stability=stable visibility=public + */ +export interface Request extends RequestBase { + path_parts: { + /** + * The unique identifier of the query ruleset to be created or updated + */ + ruleset_id: Id + } + /** + * The criteria we're testing for + */ + /** @codegen_name match_criteria */ + body: { + match_criteria: Dictionary + } +} diff --git a/specification/query_rules/test/QueryRulesetTestResponse.ts b/specification/query_rules/test/QueryRulesetTestResponse.ts new file mode 100644 index 0000000000..2423da3078 --- /dev/null +++ b/specification/query_rules/test/QueryRulesetTestResponse.ts @@ -0,0 +1,39 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Id } from '@_types/common' +import { integer } from '@_types/Numeric' + +export class Response { + body: { + total_matched_rules: integer + matched_rules: QueryRulesetMatchedRule[] + } +} + +export class QueryRulesetMatchedRule { + /** + * Ruleset unique identifier + */ + ruleset_id: Id + /** + * Rule unique identifier within that ruleset + */ + rule_id: Id +}