Skip to content

Commit 8ec8972

Browse files
authored
Populate endpoint deprecation from request definition (#2640)
1 parent ce9d54c commit 8ec8972

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

compiler/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import addDescription from './steps/add-description'
2727
import validateModel from './steps/validate-model'
2828
import addContentType from './steps/add-content-type'
2929
import readDefinitionValidation from './steps/read-definition-validation'
30+
import addDeprecation from './steps/add-deprecation'
3031

3132
const nvmrc = readFileSync(join(__dirname, '..', '..', '.nvmrc'), 'utf8')
3233
const nodejsMajor = process.version.split('.').shift()?.slice(1) ?? ''
@@ -67,6 +68,7 @@ const compiler = new Compiler(specsFolder, outputFolder)
6768
compiler
6869
.generateModel()
6970
.step(addInfo)
71+
.step(addDeprecation)
7072
.step(addContentType)
7173
.step(readDefinitionValidation)
7274
.step(validateRestSpec)

compiler/src/steps/add-deprecation.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import * as model from '../model/metamodel'
21+
import { JsonSpec } from '../model/json-spec'
22+
23+
/**
24+
* Populates the `deprecation` field for endpoints from the value of the corresponding request definition.
25+
*/
26+
export default async function addContentType (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
27+
for (const endpoint of model.endpoints) {
28+
if (endpoint.deprecation != null) {
29+
continue
30+
}
31+
32+
if (endpoint.request == null) {
33+
continue
34+
}
35+
36+
const request = model.types.find(x => x.kind === 'request' && x.name === endpoint.request)
37+
if (request == null) {
38+
continue
39+
}
40+
41+
if (request.deprecation == null) {
42+
continue
43+
}
44+
45+
endpoint.deprecation = request.deprecation
46+
}
47+
48+
return model
49+
}

output/schema/schema.json

Lines changed: 20 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_types/query_dsl/abstractions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ export class QueryContainer {
165165
* @doc_id query-dsl-geo-distance-query
166166
*/
167167
geo_distance?: GeoDistanceQuery
168+
/**
169+
* @deprecated 7.12.0 Use geo-shape instead.
170+
*/
168171
geo_polygon?: GeoPolygonQuery
169172
/**
170173
* Filter documents indexed using either the `geo_shape` or the `geo_point` type.

0 commit comments

Comments
 (0)