diff --git a/CHANGELOG.md b/CHANGELOG.md index 023c18b2f..b323df068 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 `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 diff --git a/spec/namespaces/_core.yaml b/spec/namespaces/_core.yaml index 9c5077ee6..79d1343e7 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@404' 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@404' /{index}/_explain/{id}: get: operationId: explain.0 @@ -2857,6 +2861,11 @@ components: application/json: schema: $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' + delete@404: + content: + application/json: + schema: + $ref: '../schemas/_common.yaml#/components/schemas/WriteResponseBase' delete_all_pits@200: content: application/json: @@ -2945,6 +2954,11 @@ components: 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_all_pits@200: content: application/json: 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 1a58bf8d7..33b6ea830 100644 --- a/spec/schemas/_common.yaml +++ b/spec/schemas/_common.yaml @@ -2265,3 +2265,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 f0440ec75..2e3763cc4 100644 --- a/spec/schemas/indices._common.yaml +++ b/spec/schemas/indices._common.yaml @@ -983,3 +983,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..5396a52bf 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 nonexistent document. + path: /{index}/_doc/{id} + method: GET + parameters: + index: movies + id: '1' + response: + status: 404 + - synopsis: Delete a nonexistent 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..943aa9ca4 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 a nonexistent index `movies`. + path: /{index} + method: DELETE + parameters: + index: movies + response: + status: 404 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..38a0b82fc 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 mock_payload = { '_data': '1', 'result': 'updated' }; + const mock_error = { + response: { + status: 404, + headers: { + 'content-type': 'application/json' + }, + data: JSON.stringify(mock_payload), + statusText: 'Not Found' + } + }; + + mocked_axios.request.mockRejectedValue(mock_error); + + const result = await reader.read({ + id: 'id', + path: 'path', + method: 'POST' + }, new StoryOutputs()); + + expect(result).toStrictEqual({ + status: 404, + content_type: 'application/json', + payload: mock_payload, + message: 'Not Found' + }); + }); }) describe('deserialize_payload', () => {