Skip to content

Commit 585c94d

Browse files
committed
Enforce doc_id tag on public APIs (#5198)
* Enforce doc_id tag on public APIs * Fix tests * Add doc_id test (cherry picked from commit 01182b0) # Conflicts: # output/schema/schema.json # specification/_doc_ids/table.csv # specification/esql/get_query/GetQueryRequest.ts # specification/esql/list_queries/ListQueriesRequest.ts # specification/indices/delete_data_stream_options/IndicesDeleteDataStreamOptionsRequest.ts # specification/indices/get_data_stream_options/IndicesGetDataStreamOptionsRequest.ts # specification/indices/put_data_stream_options/IndicesPutDataStreamOptionsRequest.ts
1 parent 84a2ed0 commit 585c94d

File tree

13 files changed

+79
-1
lines changed

13 files changed

+79
-1
lines changed

compiler/src/model/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,11 @@ export function hoistRequestAnnotations (
724724
assert(jsDocs, false, `Unhandled tag: '${tag}' with value: '${value}' on request ${request.name.name}`)
725725
}
726726
})
727+
728+
if (endpoint.availability.stack?.visibility !== 'private') {
729+
assert(jsDocs, tags.doc_id !== '' && tags.doc_id !== null && tags.doc_id !== undefined,
730+
`Request ${request.name.name} needs a @doc_id annotation`)
731+
}
727732
}
728733

729734
/** Lifts jsDoc type annotations to fixed properties on Type */

compiler/test/body-codegen-name/specification/_global/index/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* @rest_spec_name index
2222
* @availability stack since=0.0.0 stability=stable
23+
* @doc_id docs-index
2324
*/
2425
export interface Request {
2526
body: Foo

compiler/test/duplicate-body-codegen-name/specification/_global/index/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* @rest_spec_name index
2222
* @availability stack since=0.0.0 stability=stable
23+
* @doc_id docs-index
2324
*/
2425
export interface Request {
2526
path_parts: {

compiler/test/no-body/specification/_global/info/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* @rest_spec_name info
2222
* @availability stack since=0.0.0 stability=stable
23+
* @doc_id api-root
2324
*/
2425
export interface Request {
2526
body: {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
/**
21+
* @rest_spec_name index
22+
* @availability stack since=0.0.0 stability=stable
23+
*/
24+
export interface Request {
25+
body: {
26+
foo: string
27+
}
28+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../../../../specification/tsconfig.json",
3+
"typeRoots": ["./**/*.ts"],
4+
"include": ["./**/*.ts"]
5+
}

compiler/test/no-doc-id/test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 { join } from 'path'
21+
import test from 'ava'
22+
import Compiler from '../../src/compiler'
23+
import * as Model from '../../src/model/metamodel'
24+
25+
const specsFolder = join(__dirname, 'specification')
26+
const outputFolder = join(__dirname, 'output')
27+
28+
test("Body cannot be defined if the API methods don't allow it", t => {
29+
const compiler = new Compiler(specsFolder, outputFolder)
30+
const error = t.throws(() => compiler.generateModel())
31+
t.is(error?.message, "Request Request needs a @doc_id annotation")
32+
})

compiler/test/request-availability/specification/_global/index/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @rest_spec_name index
2222
* @availability serverless visibility=private stability=experimental
2323
* @availability stack stability=beta since=1.2.3 visibility=feature_flag feature_flag=abc
24+
* @doc_id docs-index
2425
*/
2526
export interface Request<TDocument> {
2627
path_parts: {

compiler/test/request-fields/specification/_global/index/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/**
2121
* @rest_spec_name index
2222
* @availability stack stability=stable since=0.0.0
23+
* @doc_id docs-index
2324
*/
2425
export interface Request<TDocument> {
2526
path_parts: {

compiler/test/types/specification/_global/info/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
/**
2121
* @rest_spec_name info
2222
* @availability stack since=0.0.0 stability=stable
23+
* @doc_id api-root
2324
*/
2425
export interface Request {}

0 commit comments

Comments
 (0)