Skip to content

Commit

Permalink
WIP: Add support for application/smile.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jul 8, 2024
1 parent 370dab3 commit ee84a4f
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added test for search with seq_no_primary_term ([#367](https://github.com/opensearch-project/opensearch-api-specification/pull/367))
- Added a linter for parameter sorting ([#369](https://github.com/opensearch-project/opensearch-api-specification/pull/369))
- Added support for `application/cbor` responses ([#371](https://github.com/opensearch-project/opensearch-api-specification/pull/371))
- Added support for `application/smile` responses ([#](https://github.com/opensearch-project/opensearch-api-specification/pull/))

### Changed

Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"json-diff-ts": "^4.0.1",
"json-schema-to-typescript": "^14.0.4",
"qs": "^6.12.1",
"smile-js": "^0.5.0",
"ts-jest": "^29.1.2"
}
}
10 changes: 10 additions & 0 deletions spec/namespaces/cat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,11 @@ components:
type: array
items:
$ref: '../schemas/cat.health.yaml#/components/schemas/HealthRecord'
application/smile:
schema:
type: array
items:
$ref: '../schemas/cat.health.yaml#/components/schemas/HealthRecord'
cat.help@200:
description: ''
content:
Expand All @@ -892,6 +897,11 @@ components:
type: array
items:
$ref: '../schemas/cat.indices.yaml#/components/schemas/IndicesRecord'
application/smile:
schema:
type: array
items:
$ref: '../schemas/cat.indices.yaml#/components/schemas/IndicesRecord'
cat.master@200:
description: ''
content:
Expand Down
13 changes: 13 additions & 0 deletions tests/cat/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ chapters:
status: yellow
node.data: '1'
discovered_cluster_manager: 'true'
- synopsis: Cat in different formats (format=smile).
method: GET
path: /_cat/health
parameters:
format: smile
response:
status: 200
content_type: application/yaml
payload:
- node.total: '1'
status: yellow
node.data: '1'
discovered_cluster_manager: 'true'
8 changes: 8 additions & 0 deletions tests/cat/indices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ chapters:
response:
status: 200
content_type: application/cbor
- synopsis: Cat in different formats (format=smile).
method: GET
path: /_cat/indices
parameters:
format: cbor
response:
status: 200
content_type: application/smile
2 changes: 2 additions & 0 deletions tools/src/tester/ChapterReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { to_json, to_ndjson } from '../helpers'
import qs from 'qs'
import YAML from 'yaml'
import CBOR from 'cbor'
import SMILE from 'smile-js'

export default class ChapterReader {
private readonly _client: OpenSearchHttpClient
Expand Down Expand Up @@ -92,6 +93,7 @@ export default class ChapterReader {
case 'application/json': return payload.length == 0 ? {} : JSON.parse(this.#deserialize_payload_data(payload as string))
case 'application/yaml': return payload.length == 0 ? {} : YAML.parse(this.#deserialize_payload_data(payload as string))
case 'application/cbor': return payload.length == 0 ? {} : CBOR.decode(payload as string)
case 'application/smile': return payload.length == 0 ? {} : SMILE.parse(payload)

Check failure on line 96 in tools/src/tester/ChapterReader.ts

View workflow job for this annotation

GitHub Actions / test

Unsafe argument of type `any` assigned to a parameter of type `Uint8Array`
default: return this.#deserialize_payload_data(payload as string)
}
}
Expand Down
14 changes: 14 additions & 0 deletions tools/tests/tester/ChapterReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ describe('ChapterReader', () => {
expect(result.content_type).toEqual("application/cbor")
expect(result.payload).toEqual(["x", { "y": 1 }])
})

it('application/smile', async () => {
mocked_axios.request.mockResolvedValue({
status: 200,
headers: {
'content-type': 'application/smile'
},
data: new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xe6, 0x82, 0xa8, 0xe5, 0xa5, 0xbd]).buffer
});

const result = await reader.read({ id: 'id', path: 'path', method: 'POST' }, new StoryOutputs())
expect(result.content_type).toEqual("application/smile")
expect(result.payload).toEqual(["x", { "y": 1 }])
})
})
})

16 changes: 16 additions & 0 deletions tools/tests/tester/fixtures/evals/passed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ chapters:
result: PASSED
payload_schema:
result: PASSED
- title: This GET /_cat/health chapter returns application/smile and should pass.
overall:
result: PASSED
request:
parameters:
format:
result: PASSED
request_body:
result: PASSED
response:
status:
result: PASSED
payload_body:
result: PASSED
payload_schema:
result: PASSED
epilogues:
- title: DELETE /books
overall:
Expand Down
5 changes: 5 additions & 0 deletions tools/tests/tester/fixtures/specs/excerpt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ components:
type: array
items:
type: object
application/smile:
schema:
type: array
items:
type: object
indices.delete@200:
description: ''
content:
Expand Down
10 changes: 10 additions & 0 deletions tools/tests/tester/fixtures/stories/passed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ chapters:
content_type: application/cbor
payload:
- node.total: '1'
- synopsis: This GET /_cat/health chapter returns application/smile and should pass.
path: /_cat/health
parameters:
format: cbor
method: GET
response:
status: 200
content_type: application/smile
payload:
- node.total: '1'

0 comments on commit ee84a4f

Please sign in to comment.