From a7e5e34dec0ca11666ccc4a66b1740ca7fd1ba4c Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 26 Jun 2024 15:28:42 -0400 Subject: [PATCH] Corrected /_cat/indices response schema. Signed-off-by: dblock --- spec/namespaces/cat.yaml | 5 ++ spec/schemas/cat.indices.yaml | 8 +-- tests/cat/indices.yaml | 73 ++++++++++++++++++++++++++++ tools/src/tester/ChapterEvaluator.ts | 3 +- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 tests/cat/indices.yaml diff --git a/spec/namespaces/cat.yaml b/spec/namespaces/cat.yaml index e62e86ea..cf87eb99 100644 --- a/spec/namespaces/cat.yaml +++ b/spec/namespaces/cat.yaml @@ -869,6 +869,11 @@ components: type: array items: $ref: '../schemas/cat.indices.yaml#/components/schemas/IndicesRecord' + application/yaml: + schema: + type: array + items: + $ref: '../schemas/cat.indices.yaml#/components/schemas/IndicesRecord' cat.master@200: description: '' content: diff --git a/spec/schemas/cat.indices.yaml b/spec/schemas/cat.indices.yaml index c03496f7..974f4cbf 100644 --- a/spec/schemas/cat.indices.yaml +++ b/spec/schemas/cat.indices.yaml @@ -29,13 +29,13 @@ components: type: string docs.count: description: available docs - oneOf: + anyOf: - type: string - nullable: true type: string docs.deleted: description: deleted docs - oneOf: + anyOf: - type: string - nullable: true type: string @@ -47,13 +47,13 @@ components: type: string store.size: description: store size of primaries & replicas - oneOf: + anyOf: - type: string - nullable: true type: string pri.store.size: description: store size of primaries - oneOf: + anyOf: - type: string - nullable: true type: string diff --git a/tests/cat/indices.yaml b/tests/cat/indices.yaml new file mode 100644 index 00000000..f1a14b42 --- /dev/null +++ b/tests/cat/indices.yaml @@ -0,0 +1,73 @@ +$schema: ../../json_schemas/test_story.schema.yaml + +description: Test cat/indices endpoints. +prologues: + - synopsis: Create an index named `books` with mappings and settings. + path: /{index} + method: PUT + parameters: + index: books + request_body: + payload: {} +epilogues: + - path: /books + method: DELETE + status: [200, 404] +chapters: + - synopsis: Cat with a default text response. + method: GET + path: /_cat/indices + response: + status: 200 + content_type: text/plain + - synopsis: Cat with verbose output (v=true). + method: GET + path: /_cat/indices + parameters: + v: true + response: + status: 200 + content_type: text/plain + - synopsis: Cat with headers (h=header1,header2). + method: GET + path: /_cat/indices + parameters: + h: + - health + - status + response: + status: 200 + content_type: text/plain + - synopsis: Cat displaying all available headers (help=true). + method: GET + path: /_cat/indices + parameters: + help: true + response: + status: 200 + content_type: text/plain + - synopsis: Cat with sorted results. + method: GET + path: /_cat/indices + parameters: + s: + - status + response: + status: 200 + content_type: text/plain + - synopsis: Cat in different formats (format=json). + method: GET + path: /_cat/indices + parameters: + format: json + response: + status: 200 + content_type: application/json + - synopsis: Cat in different formats (format=yaml). + method: GET + path: /_cat/indices + parameters: + format: yaml + response: + status: 200 + content_type: application/yaml diff --git a/tools/src/tester/ChapterEvaluator.ts b/tools/src/tester/ChapterEvaluator.ts index 6206bfd5..28ba1191 100644 --- a/tools/src/tester/ChapterEvaluator.ts +++ b/tools/src/tester/ChapterEvaluator.ts @@ -106,13 +106,12 @@ export default class ChapterEvaluator { const schema = content?.schema if (schema == null && content != null) return { result: Result.PASSED } if (schema == null) return { result: Result.FAILED, message: `Schema for "${response.status}: ${response.content_type}" response not found in the spec.` } - console.log(this.#deserialize_payload(response.payload, content_type)) return this._schema_validator.validate(schema, this.#deserialize_payload(response.payload, content_type)) } #deserialize_payload(payload: any, content_type: string): any { if (payload === undefined) return undefined - switch(content_type) { + switch (content_type) { case 'application/yaml': return YAML.parse(payload as string) default: return payload }