Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for application/yaml response payloads. #363

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Corrected /_cat/indices response schema.
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Jun 27, 2024
commit a7e5e34dec0ca11666ccc4a66b1740ca7fd1ba4c
5 changes: 5 additions & 0 deletions spec/namespaces/cat.yaml
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 4 additions & 4 deletions spec/schemas/cat.indices.yaml
Original file line number Diff line number Diff line change
@@ -29,13 +29,13 @@ components:
type: string
docs.count:
description: available docs
oneOf:
anyOf:
- type: string
- nullable: true
type: string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably scope creeping but nullable is not a proper JSON schema keyword. Even if it was, this is redundant because nullable string already encapsulates non-nullable string.

In this case and a few below, we can repalce anyOf: ... with type: [string, null] according to this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this but it failed with some other error. Care to open an issue with some details to replace?

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
73 changes: 73 additions & 0 deletions tests/cat/indices.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions tools/src/tester/ChapterEvaluator.ts
Original file line number Diff line number Diff line change
@@ -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
}