From 8ec8972861315b10a5c8218920a5ecb6e4809667 Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Mon, 24 Jun 2024 15:47:20 +0200 Subject: [PATCH] Populate endpoint deprecation from request definition (#2640) --- compiler/src/index.ts | 2 + compiler/src/steps/add-deprecation.ts | 49 +++++++++++++++++++ output/schema/schema.json | 28 ++++++++--- .../_types/query_dsl/abstractions.ts | 3 ++ 4 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 compiler/src/steps/add-deprecation.ts diff --git a/compiler/src/index.ts b/compiler/src/index.ts index d74b66300a..cdf6827bfb 100644 --- a/compiler/src/index.ts +++ b/compiler/src/index.ts @@ -27,6 +27,7 @@ import addDescription from './steps/add-description' import validateModel from './steps/validate-model' import addContentType from './steps/add-content-type' import readDefinitionValidation from './steps/read-definition-validation' +import addDeprecation from './steps/add-deprecation' const nvmrc = readFileSync(join(__dirname, '..', '..', '.nvmrc'), 'utf8') const nodejsMajor = process.version.split('.').shift()?.slice(1) ?? '' @@ -67,6 +68,7 @@ const compiler = new Compiler(specsFolder, outputFolder) compiler .generateModel() .step(addInfo) + .step(addDeprecation) .step(addContentType) .step(readDefinitionValidation) .step(validateRestSpec) diff --git a/compiler/src/steps/add-deprecation.ts b/compiler/src/steps/add-deprecation.ts new file mode 100644 index 0000000000..718bf6b9cb --- /dev/null +++ b/compiler/src/steps/add-deprecation.ts @@ -0,0 +1,49 @@ +/* + * 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 * as model from '../model/metamodel' +import { JsonSpec } from '../model/json-spec' + +/** + * Populates the `deprecation` field for endpoints from the value of the corresponding request definition. + */ +export default async function addContentType (model: model.Model, jsonSpec: Map): Promise { + for (const endpoint of model.endpoints) { + if (endpoint.deprecation != null) { + continue + } + + if (endpoint.request == null) { + continue + } + + const request = model.types.find(x => x.kind === 'request' && x.name === endpoint.request) + if (request == null) { + continue + } + + if (request.deprecation == null) { + continue + } + + endpoint.deprecation = request.deprecation + } + + return model +} diff --git a/output/schema/schema.json b/output/schema/schema.json index eb828d9da4..41a522dbff 100644 --- a/output/schema/schema.json +++ b/output/schema/schema.json @@ -9360,6 +9360,10 @@ "stability": "experimental" } }, + "deprecation": { + "description": "", + "version": "8.4.0" + }, "description": "Performs a kNN search.", "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html", "name": "knn_search", @@ -11948,6 +11952,10 @@ "stability": "stable" } }, + "deprecation": { + "description": "Posting data directly to anomaly detection jobs is deprecated, in a future major version a datafeed will be required.", + "version": "7.11.0" + }, "description": "Sends data to an anomaly detection job for analysis.\n\nIMPORTANT: For each job, data can be accepted from only a single connection at a time.\nIt is not currently possible to post data to multiple jobs using wildcards or a comma-separated list.", "docUrl": "https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html", "name": "ml.post_data", @@ -74965,7 +74973,7 @@ "name": "CombinedFieldsOperator", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/abstractions.ts#L496-L499" + "specLocation": "_types/query_dsl/abstractions.ts#L499-L502" }, { "inherits": { @@ -75061,7 +75069,7 @@ } } ], - "specLocation": "_types/query_dsl/abstractions.ts#L452-L486" + "specLocation": "_types/query_dsl/abstractions.ts#L455-L489" }, { "kind": "enum", @@ -75079,7 +75087,7 @@ "name": "CombinedFieldsZeroTerms", "namespace": "_types.query_dsl" }, - "specLocation": "_types/query_dsl/abstractions.ts#L501-L510" + "specLocation": "_types/query_dsl/abstractions.ts#L504-L513" }, { "inherits": { @@ -75757,7 +75765,7 @@ } ], "shortcutProperty": "field", - "specLocation": "_types/query_dsl/abstractions.ts#L512-L526" + "specLocation": "_types/query_dsl/abstractions.ts#L515-L529" }, { "kind": "interface", @@ -75815,7 +75823,7 @@ } } ], - "specLocation": "_types/query_dsl/abstractions.ts#L416-L433" + "specLocation": "_types/query_dsl/abstractions.ts#L419-L436" }, { "kind": "enum", @@ -79544,7 +79552,7 @@ } } ], - "specLocation": "_types/query_dsl/abstractions.ts#L439-L450" + "specLocation": "_types/query_dsl/abstractions.ts#L442-L453" }, { "docId": "query-dsl", @@ -79754,6 +79762,10 @@ } }, { + "deprecation": { + "description": "Use geo-shape instead.", + "version": "7.12.0" + }, "name": "geo_polygon", "required": false, "type": { @@ -80579,7 +80591,7 @@ } } ], - "specLocation": "_types/query_dsl/abstractions.ts#L101-L414", + "specLocation": "_types/query_dsl/abstractions.ts#L101-L417", "variants": { "kind": "container", "nonExhaustive": true @@ -83128,7 +83140,7 @@ } } ], - "specLocation": "_types/query_dsl/abstractions.ts#L488-L494" + "specLocation": "_types/query_dsl/abstractions.ts#L491-L497" }, { "kind": "enum", diff --git a/specification/_types/query_dsl/abstractions.ts b/specification/_types/query_dsl/abstractions.ts index 5396b18623..372c5d5cff 100644 --- a/specification/_types/query_dsl/abstractions.ts +++ b/specification/_types/query_dsl/abstractions.ts @@ -165,6 +165,9 @@ export class QueryContainer { * @doc_id query-dsl-geo-distance-query */ geo_distance?: GeoDistanceQuery + /** + * @deprecated 7.12.0 Use geo-shape instead. + */ geo_polygon?: GeoPolygonQuery /** * Filter documents indexed using either the `geo_shape` or the `geo_point` type.