Skip to content

Commit

Permalink
Populate endpoint deprecation from request definition (#2640)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd authored Jun 24, 2024
1 parent ce9d54c commit 8ec8972
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
2 changes: 2 additions & 0 deletions compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? ''
Expand Down Expand Up @@ -67,6 +68,7 @@ const compiler = new Compiler(specsFolder, outputFolder)
compiler
.generateModel()
.step(addInfo)
.step(addDeprecation)
.step(addContentType)
.step(readDefinitionValidation)
.step(validateRestSpec)
Expand Down
49 changes: 49 additions & 0 deletions compiler/src/steps/add-deprecation.ts
Original file line number Diff line number Diff line change
@@ -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<string, JsonSpec>): Promise<model.Model> {
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
}
28 changes: 20 additions & 8 deletions output/schema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions specification/_types/query_dsl/abstractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8ec8972

Please sign in to comment.