diff --git a/compiler/src/model/utils.ts b/compiler/src/model/utils.ts index f17e45973f..cd88832e03 100644 --- a/compiler/src/model/utils.ts +++ b/compiler/src/model/utils.ts @@ -724,6 +724,11 @@ export function hoistRequestAnnotations ( assert(jsDocs, false, `Unhandled tag: '${tag}' with value: '${value}' on request ${request.name.name}`) } }) + + if (endpoint.availability.stack?.visibility !== 'private') { + assert(jsDocs, tags.doc_id !== '' && tags.doc_id !== null && tags.doc_id !== undefined, + `Request ${request.name.name} needs a @doc_id annotation`) + } } /** Lifts jsDoc type annotations to fixed properties on Type */ diff --git a/compiler/test/body-codegen-name/specification/_global/index/request.ts b/compiler/test/body-codegen-name/specification/_global/index/request.ts index e2336b40d5..b18e03f3b7 100644 --- a/compiler/test/body-codegen-name/specification/_global/index/request.ts +++ b/compiler/test/body-codegen-name/specification/_global/index/request.ts @@ -20,6 +20,7 @@ /** * @rest_spec_name index * @availability stack since=0.0.0 stability=stable + * @doc_id docs-index */ export interface Request { body: Foo diff --git a/compiler/test/duplicate-body-codegen-name/specification/_global/index/request.ts b/compiler/test/duplicate-body-codegen-name/specification/_global/index/request.ts index 2b86f0b488..7b3193bc6a 100644 --- a/compiler/test/duplicate-body-codegen-name/specification/_global/index/request.ts +++ b/compiler/test/duplicate-body-codegen-name/specification/_global/index/request.ts @@ -20,6 +20,7 @@ /** * @rest_spec_name index * @availability stack since=0.0.0 stability=stable + * @doc_id docs-index */ export interface Request { path_parts: { diff --git a/compiler/test/no-body/specification/_global/info/request.ts b/compiler/test/no-body/specification/_global/info/request.ts index 4211111f7d..ddf89ba1cf 100644 --- a/compiler/test/no-body/specification/_global/info/request.ts +++ b/compiler/test/no-body/specification/_global/info/request.ts @@ -20,6 +20,7 @@ /** * @rest_spec_name info * @availability stack since=0.0.0 stability=stable + * @doc_id api-root */ export interface Request { body: { diff --git a/compiler/test/no-doc-id/specification/_global/info/request.ts b/compiler/test/no-doc-id/specification/_global/info/request.ts new file mode 100644 index 0000000000..3d33c90fdd --- /dev/null +++ b/compiler/test/no-doc-id/specification/_global/info/request.ts @@ -0,0 +1,28 @@ +/* + * 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. + */ + +/** + * @rest_spec_name index + * @availability stack since=0.0.0 stability=stable + */ +export interface Request { + body: { + foo: string + } +} diff --git a/compiler/test/no-doc-id/specification/tsconfig.json b/compiler/test/no-doc-id/specification/tsconfig.json new file mode 100644 index 0000000000..a983782068 --- /dev/null +++ b/compiler/test/no-doc-id/specification/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../../../specification/tsconfig.json", + "typeRoots": ["./**/*.ts"], + "include": ["./**/*.ts"] +} diff --git a/compiler/test/no-doc-id/test.ts b/compiler/test/no-doc-id/test.ts new file mode 100644 index 0000000000..e88625f9c7 --- /dev/null +++ b/compiler/test/no-doc-id/test.ts @@ -0,0 +1,32 @@ +/* + * 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 { join } from 'path' +import test from 'ava' +import Compiler from '../../src/compiler' +import * as Model from '../../src/model/metamodel' + +const specsFolder = join(__dirname, 'specification') +const outputFolder = join(__dirname, 'output') + +test("Body cannot be defined if the API methods don't allow it", t => { + const compiler = new Compiler(specsFolder, outputFolder) + const error = t.throws(() => compiler.generateModel()) + t.is(error?.message, "Request Request needs a @doc_id annotation") +}) diff --git a/compiler/test/request-availability/specification/_global/index/request.ts b/compiler/test/request-availability/specification/_global/index/request.ts index fc01b2ce91..b69746c3e3 100644 --- a/compiler/test/request-availability/specification/_global/index/request.ts +++ b/compiler/test/request-availability/specification/_global/index/request.ts @@ -21,6 +21,7 @@ * @rest_spec_name index * @availability serverless visibility=private stability=experimental * @availability stack stability=beta since=1.2.3 visibility=feature_flag feature_flag=abc + * @doc_id docs-index */ export interface Request { path_parts: { diff --git a/compiler/test/request-fields/specification/_global/index/request.ts b/compiler/test/request-fields/specification/_global/index/request.ts index 62f4132f05..3a766fbabf 100644 --- a/compiler/test/request-fields/specification/_global/index/request.ts +++ b/compiler/test/request-fields/specification/_global/index/request.ts @@ -20,6 +20,7 @@ /** * @rest_spec_name index * @availability stack stability=stable since=0.0.0 + * @doc_id docs-index */ export interface Request { path_parts: { diff --git a/compiler/test/types/specification/_global/info/request.ts b/compiler/test/types/specification/_global/info/request.ts index baa16a9e5d..7813b1aba3 100644 --- a/compiler/test/types/specification/_global/info/request.ts +++ b/compiler/test/types/specification/_global/info/request.ts @@ -20,5 +20,6 @@ /** * @rest_spec_name info * @availability stack since=0.0.0 stability=stable + * @doc_id api-root */ export interface Request {} diff --git a/compiler/test/types/test.ts b/compiler/test/types/test.ts index 2761108f21..787eabeb78 100644 --- a/compiler/test/types/test.ts +++ b/compiler/test/types/test.ts @@ -92,7 +92,7 @@ test('type_alias', t => { test('request', t => { const definition = model.types.find(t => t.kind === 'request') as Model.Request t.assert(definition) - t.true(definition?.specLocation.endsWith('test/types/specification/_global/info/request.ts#L20-L24')) + t.true(definition?.specLocation.endsWith('test/types/specification/_global/info/request.ts#L20-L25')) t.deepEqual(definition?.name, { name: 'Request', namespace: '_global.info' diff --git a/compiler/test/writes-to-output/specification/_global/index/request.ts b/compiler/test/writes-to-output/specification/_global/index/request.ts index 30c5436179..622a012cfd 100644 --- a/compiler/test/writes-to-output/specification/_global/index/request.ts +++ b/compiler/test/writes-to-output/specification/_global/index/request.ts @@ -20,5 +20,6 @@ /** * @rest_spec_name index * @availability stack since=0.0.0 stability=stable + * @doc_id docs-index */ export interface Request {} \ No newline at end of file diff --git a/compiler/test/wrong-namespace/specification/_global/foobar/request.ts b/compiler/test/wrong-namespace/specification/_global/foobar/request.ts index baa16a9e5d..7813b1aba3 100644 --- a/compiler/test/wrong-namespace/specification/_global/foobar/request.ts +++ b/compiler/test/wrong-namespace/specification/_global/foobar/request.ts @@ -20,5 +20,6 @@ /** * @rest_spec_name info * @availability stack since=0.0.0 stability=stable + * @doc_id api-root */ export interface Request {}