From 5869c243bd81a8da48ff0d257fd944fa343be540 Mon Sep 17 00:00:00 2001 From: vatsal Date: Fri, 27 Sep 2024 22:21:39 -0700 Subject: [PATCH 1/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- spec/namespaces/_core.yaml | 4 ++++ spec/namespaces/indices.yaml | 7 +++++++ spec/schemas/_common.yaml | 4 ++++ spec/schemas/indices._common.yaml | 26 ++++++++++++++++++++++++++ tests/default/indices/doc.yaml | 16 ++++++++++++++++ tests/default/indices/index.yaml | 10 +++++++++- 6 files changed, 66 insertions(+), 1 deletion(-) diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index a9e7b8b0d..2649471d3 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -1368,6 +1368,8 @@ paths: responses: '200': $ref: '#/components/responses/get@200' + '404': + $ref: '#/components/responses/get@200' head: operationId: exists.0 x-operation-group: exists @@ -1468,6 +1470,8 @@ paths: responses: '200': $ref: '#/components/responses/delete@200' + '404': + $ref: '#/components/responses/delete@200' /{index}/_explain/{id}: get: operationId: explain.0 diff --git a/spec/namespaces/indices.yaml b/spec/namespaces/indices.yaml index dcd758619..ad4a4c8dd 100644 --- a/spec/namespaces/indices.yaml +++ b/spec/namespaces/indices.yaml @@ -1044,6 +1044,8 @@ paths: responses: '200': $ref: '#/components/responses/indices.delete@200' + '404': + $ref: '#/components/responses/indices.delete@404' /{index}/_alias: get: operationId: indices.get_alias.2 @@ -2400,6 +2402,11 @@ components: application/json: schema: $ref: '../schemas/_common.yaml#/components/schemas/IndicesResponseBase' + indices.delete@404: + content: + application/json: + schema: + $ref: '../schemas/indices._common.yaml#/components/schemas/IndexErrorCause' indices.delete_alias@200: content: application/json: diff --git a/spec/schemas/_common.yaml b/spec/schemas/_common.yaml index c3e9468d3..24a131cc5 100644 --- a/spec/schemas/_common.yaml +++ b/spec/schemas/_common.yaml @@ -2241,3 +2241,7 @@ components: BatchSize: type: integer format: int64 + ResourceType: + type: string + enum: + - index_or_alias diff --git a/spec/schemas/indices._common.yaml b/spec/schemas/indices._common.yaml index 90d6776d6..6d5ec90bb 100644 --- a/spec/schemas/indices._common.yaml +++ b/spec/schemas/indices._common.yaml @@ -1010,3 +1010,29 @@ components: - mappings - order - settings + IndexErrorCause: + type: object + properties: + type: + description: The type of error + type: string + reason: + description: A human-readable explanation of the error, in english + type: string + root_cause: + type: array + items: + $ref: '#/components/schemas/IndexErrorCause' + index: + $ref: '_common.yaml#/components/schemas/IndexName' + index_uuid: + $ref: '_common.yaml#/components/schemas/Uuid' + resource.id: + $ref: '_common.yaml#/components/schemas/IndexName' + resource.type: + $ref: '_common.yaml#/components/schemas/ResourceType' + required: + - type + additionalProperties: + title: metadata + description: Additional details about the error. diff --git a/tests/default/indices/doc.yaml b/tests/default/indices/doc.yaml index 6eb5a8a5d..cffe8ff21 100644 --- a/tests/default/indices/doc.yaml +++ b/tests/default/indices/doc.yaml @@ -57,3 +57,19 @@ chapters: id: '1' response: status: 200 + - synopsis: Retrieve a non existing document. + path: /{index}/_doc/{id} + method: GET + parameters: + index: movies + id: '1' + response: + status: 404 + - synopsis: Delete a non existing document. + path: /{index}/_doc/{id} + method: DELETE + parameters: + index: movies + id: '1' + response: + status: 404 diff --git a/tests/default/indices/index.yaml b/tests/default/indices/index.yaml index 4b34c8937..1564db477 100644 --- a/tests/default/indices/index.yaml +++ b/tests/default/indices/index.yaml @@ -84,4 +84,12 @@ chapters: version: '>= 2.0' parameters: index: books,games - cluster_manager_timeout: 10s + cluster_manager_timeout: 10s + + - synopsis: Delete non existing index `movies`. + path: /{index} + method: DELETE + parameters: + index: movies + response: + status: 404 From 3b4b43331afde8782a65ad40c86a404818e50d1b Mon Sep 17 00:00:00 2001 From: vatsal Date: Mon, 30 Sep 2024 18:58:54 -0700 Subject: [PATCH 2/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- tools/src/tester/ChapterReader.ts | 2 +- tools/tests/tester/ChapterReader.test.ts | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/src/tester/ChapterReader.ts b/tools/src/tester/ChapterReader.ts index 26dd02753..f85e6fdc6 100644 --- a/tools/src/tester/ChapterReader.ts +++ b/tools/src/tester/ChapterReader.ts @@ -62,7 +62,7 @@ export default class ChapterReader { response.status = e.response.status response.content_type = e.response.headers['content-type']?.split(';')[0] const payload = this.#deserialize_payload(e.response.data, response.content_type) - if (payload !== undefined) response.payload = payload.error + if (payload !== undefined) response.payload = payload.error ?? payload response.message = payload.error?.reason ?? e.response.statusText this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload !== undefined ? to_json(response.payload) : response.message}`) } diff --git a/tools/tests/tester/ChapterReader.test.ts b/tools/tests/tester/ChapterReader.test.ts index 7e1776bb2..0a385d12b 100644 --- a/tools/tests/tester/ChapterReader.test.ts +++ b/tools/tests/tester/ChapterReader.test.ts @@ -219,6 +219,35 @@ describe('ChapterReader', () => { }] ]) }) + + it('sets payload to entire response when payload.error is missing', async () => { + const mockPayload = { '_data': '1', 'result': 'updated' }; + const mockError = { + response: { + status: 404, + headers: { + 'content-type': 'application/json' + }, + data: JSON.stringify(mockPayload), + statusText: 'Not Found' + } + }; + + mocked_axios.request.mockRejectedValue(mockError); + + const result = await reader.read({ + id: 'id', + path: 'path', + method: 'POST' + }, new StoryOutputs()); + + expect(result).toStrictEqual({ + status: 404, + content_type: 'application/json', + payload: mockPayload, + message: 'Not Found' + }); + }); }) describe('deserialize_payload', () => { From d75ca09fa3535cc8ed517b3917455ab8cb15769b Mon Sep 17 00:00:00 2001 From: vatsal Date: Mon, 30 Sep 2024 19:10:44 -0700 Subject: [PATCH 3/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb4ed38f..687b04e7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `/_plugins/_ml/agents/_register`, `/_plugins/_ml/connectors/_create`, `DELETE /_plugins/_ml/agents/{agent_id}`, `DELETE /_plugins/_ml/connectors/{connector_id}` ([#228](https://github.com/opensearch-project/opensearch-api-specification/issues/228)) - Added the `context` query param to the `put_script` APIs ([#586](https://github.com/opensearch-project/opensearch-api-specification/pull/586)) - Added `persian_stem` filter ([#592](https://github.com/opensearch-project/opensearch-api-specification/pull/592)) +- Added `DELETE /{index}`, `GET /{index}/_doc/{id}`, `DELETE /{index}/_doc/{id}` ([#589](https://github.com/opensearch-project/opensearch-api-specification/pull/589)) ### Changed From 20e89d9700b78d939b7caf27b4be716f626d71b0 Mon Sep 17 00:00:00 2001 From: vatsal Date: Mon, 30 Sep 2024 19:12:32 -0700 Subject: [PATCH 4/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 687b04e7c..d589ee0bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,7 +99,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added `/_plugins/_ml/agents/_register`, `/_plugins/_ml/connectors/_create`, `DELETE /_plugins/_ml/agents/{agent_id}`, `DELETE /_plugins/_ml/connectors/{connector_id}` ([#228](https://github.com/opensearch-project/opensearch-api-specification/issues/228)) - Added the `context` query param to the `put_script` APIs ([#586](https://github.com/opensearch-project/opensearch-api-specification/pull/586)) - Added `persian_stem` filter ([#592](https://github.com/opensearch-project/opensearch-api-specification/pull/592)) -- Added `DELETE /{index}`, `GET /{index}/_doc/{id}`, `DELETE /{index}/_doc/{id}` ([#589](https://github.com/opensearch-project/opensearch-api-specification/pull/589)) +- Added `404` response for `DELETE /{index}`, `GET /{index}/_doc/{id}`, `DELETE /{index}/_doc/{id}` ([#589](https://github.com/opensearch-project/opensearch-api-specification/pull/589)) ### Changed From 5be99e63d0e9b703732b17b1c808dd4e6c7a3fb0 Mon Sep 17 00:00:00 2001 From: vatsal Date: Thu, 3 Oct 2024 00:18:27 -0700 Subject: [PATCH 5/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- tools/tests/tester/ChapterReader.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/tests/tester/ChapterReader.test.ts b/tools/tests/tester/ChapterReader.test.ts index 0a385d12b..38a0b82fc 100644 --- a/tools/tests/tester/ChapterReader.test.ts +++ b/tools/tests/tester/ChapterReader.test.ts @@ -221,19 +221,19 @@ describe('ChapterReader', () => { }) it('sets payload to entire response when payload.error is missing', async () => { - const mockPayload = { '_data': '1', 'result': 'updated' }; - const mockError = { + const mock_payload = { '_data': '1', 'result': 'updated' }; + const mock_error = { response: { status: 404, headers: { 'content-type': 'application/json' }, - data: JSON.stringify(mockPayload), + data: JSON.stringify(mock_payload), statusText: 'Not Found' } }; - mocked_axios.request.mockRejectedValue(mockError); + mocked_axios.request.mockRejectedValue(mock_error); const result = await reader.read({ id: 'id', @@ -244,7 +244,7 @@ describe('ChapterReader', () => { expect(result).toStrictEqual({ status: 404, content_type: 'application/json', - payload: mockPayload, + payload: mock_payload, message: 'Not Found' }); }); From c1039de9e2fb731b9dedee6c9cd169cd702750e3 Mon Sep 17 00:00:00 2001 From: vatsal Date: Thu, 3 Oct 2024 13:24:03 -0700 Subject: [PATCH 6/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- spec/namespaces/_core.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 2649471d3..23c408d5c 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -1369,7 +1369,7 @@ paths: '200': $ref: '#/components/responses/get@200' '404': - $ref: '#/components/responses/get@200' + $ref: '#/components/responses/get@404' head: operationId: exists.0 x-operation-group: exists @@ -1471,7 +1471,7 @@ paths: '200': $ref: '#/components/responses/delete@200' '404': - $ref: '#/components/responses/delete@200' + $ref: '#/components/responses/delete@404' /{index}/_explain/{id}: get: operationId: explain.0 @@ -2841,11 +2841,12 @@ components: creation_time: type: integer format: int64 - delete@200: + delete@200: &WriteResponseBase content: application/json: schema: $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' + delete@404: *WriteResponseBase delete_all_pits@200: content: application/json: @@ -2929,11 +2930,12 @@ components: required: - fields - indices - get@200: + get@200: &getResult content: application/json: schema: $ref: '../schemas/_core.get.yaml#/components/schemas/GetResult' + get@404: *getResult get_all_pits@200: content: application/json: From db5705b18a61cd13f1882eb8dd349f0d4bee3eea Mon Sep 17 00:00:00 2001 From: vatsal Date: Fri, 4 Oct 2024 17:29:24 -0700 Subject: [PATCH 7/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- spec/namespaces/_core.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 23c408d5c..1fa488539 100644 --- a/spec/namespaces/_core.yaml +++ b/spec/namespaces/_core.yaml @@ -2841,12 +2841,16 @@ components: creation_time: type: integer format: int64 - delete@200: &WriteResponseBase + delete@200: + content: + application/json: + schema: + $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' + delete@404: content: application/json: schema: $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' - delete@404: *WriteResponseBase delete_all_pits@200: content: application/json: @@ -2930,12 +2934,16 @@ components: required: - fields - indices - get@200: &getResult + get@200: + content: + application/json: + schema: + $ref: '../schemas/_core.get.yaml#/components/schemas/GetResult' + get@404: content: application/json: schema: $ref: '../schemas/_core.get.yaml#/components/schemas/GetResult' - get@404: *getResult get_all_pits@200: content: application/json: From c7bae5dcbbf737983e327cbc2d622b7a4346d24c Mon Sep 17 00:00:00 2001 From: vatsal Date: Fri, 4 Oct 2024 18:21:37 -0700 Subject: [PATCH 8/8] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- tests/default/indices/doc.yaml | 4 ++-- tests/default/indices/index.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/default/indices/doc.yaml b/tests/default/indices/doc.yaml index cffe8ff21..5396a52bf 100644 --- a/tests/default/indices/doc.yaml +++ b/tests/default/indices/doc.yaml @@ -57,7 +57,7 @@ chapters: id: '1' response: status: 200 - - synopsis: Retrieve a non existing document. + - synopsis: Retrieve a nonexistent document. path: /{index}/_doc/{id} method: GET parameters: @@ -65,7 +65,7 @@ chapters: id: '1' response: status: 404 - - synopsis: Delete a non existing document. + - synopsis: Delete a nonexistent document. path: /{index}/_doc/{id} method: DELETE parameters: diff --git a/tests/default/indices/index.yaml b/tests/default/indices/index.yaml index 1564db477..943aa9ca4 100644 --- a/tests/default/indices/index.yaml +++ b/tests/default/indices/index.yaml @@ -86,7 +86,7 @@ chapters: index: books,games cluster_manager_timeout: 10s - - synopsis: Delete non existing index `movies`. + - synopsis: Delete a nonexistent index `movies`. path: /{index} method: DELETE parameters: