Skip to content

Commit

Permalink
Added support for request headers. (#461)
Browse files Browse the repository at this point in the history
* Renamed request_body to request.

Signed-off-by: dblock <[email protected]>

* Added npm run generate-types.

Signed-off-by: dblock <[email protected]>

* Added support for request headers.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Aug 4, 2024
1 parent ac8659d commit 59a7ff4
Show file tree
Hide file tree
Showing 77 changed files with 335 additions and 209 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added `plugins` to NodeInfoSettings ([#442](https://github.com/opensearch-project/opensearch-api-specification/pull/442))
- Added test coverage ([#443](https://github.com/opensearch-project/opensearch-api-specification/pull/443))
- Added `--opensearch-version` to `merger` that excludes schema elements per semver ([#428](https://github.com/opensearch-project/opensearch-api-specification/pull/428))
- Added `retry` to `tester` to support asynchronous tasks ([453](https://github.com/opensearch-project/opensearch-api-specification/pull/453))
- Added `retry` to `tester` to support asynchronous tasks ([#453](https://github.com/opensearch-project/opensearch-api-specification/pull/453))
- Added passing OPENSEARCH_JAVA_OPTS into the docker container used for tests ([#454](https://github.com/opensearch-project/opensearch-api-specification/pull/454))
- Added a warning on mulitple paths being tested in the same file ([#452](https://github.com/opensearch-project/opensearch-api-specification/pull/452))
- Added validation of titles and descriptions in info and schema objects ([#463](https://github.com/opensearch-project/opensearch-api-specification/pull/463))
- Added `/_plugins/_query/settings` ([#456](https://github.com/opensearch-project/opensearch-api-specification/pull/456))
- Added `/_plugins/_ppl`, `explain` and `stats` ([#460](https://github.com/opensearch-project/opensearch-api-specification/pull/460))
- Added tests against OpenSearch 3.0 ([#459](https://github.com/opensearch-project/opensearch-api-specification/pull/459))
- Added support for request headers in tests [#461](https://github.com/opensearch-project/opensearch-api-specification/pull/461)

### Changed

Expand Down
13 changes: 8 additions & 5 deletions TESTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ chapters:
- synopsis: Create an index named `books` with mappings and settings.
path: /{index} # The test will fail if "PUT /{index}" operation is not found in the spec.
method: PUT
parameters: # All parameters are validated against their schemas in the spec
parameters: # All parameters are validated against their schemas in the spec.
index: books
request_body: # The request body is validated against the schema of the requestBody in the spec
payload:
request: # The request.
headers: # Optional headers.
user-agent: OpenSearch API Spec/1.0
payload: # The request body is validated against the schema of the requestBody in the spec.
mappings:
properties:
name:
Expand All @@ -88,7 +90,8 @@ chapters:
settings:
number_of_shards: 5
number_of_replicas: 2
response: # The response body is validated against the schema of the corresponding response in the spec
response: # The response.
payload: # Matching response payload. The entire payload is validated against the schema of the corresponding response in the spec.
status: 200 # This is the expected status code of the response. Any other status code will fail the test.
- synopsis: Retrieve the mappings and settings of the `books` index.
Expand All @@ -113,7 +116,7 @@ Consider the following chapters in [ml/model_groups](tests/ml/model_groups.yaml)
id: create_model_group # Only needed if you want to refer to this chapter in another chapter.
path: /_plugins/_ml/model_groups/_register
method: POST
request_body:
request:
payload:
name: NLP_Group
description: Model group for NLP models.
Expand Down
17 changes: 13 additions & 4 deletions json_schemas/test_story.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ definitions:
type: object
additionalProperties:
$ref: '#/definitions/Parameter'
request_body:
$ref: '#/definitions/RequestBody'
request:
$ref: '#/definitions/Request'
output:
$ref: '#/definitions/Output'
version:
Expand Down Expand Up @@ -119,15 +119,18 @@ definitions:
required:
- count

RequestBody:
Request:
type: object
properties:
content_type:
type: string
default: application/json
headers:
type: object
additionalProperties:
$ref: '#/definitions/Header'
payload:
$ref: '#/definitions/Payload'
required: [payload]
additionalProperties: false

ExpectedResponse:
Expand Down Expand Up @@ -163,6 +166,12 @@ definitions:
required: [content_type, payload, status]
additionalProperties: false

Header:
anyOf:
- type: string
- type: number
- type: boolean

Payload:
anyOf:
- type: object
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"coverage:spec": "ts-node tools/src/coverage/coverage.ts",
"dump-cluster-spec": "ts-node tools/src/dump-cluster-spec/dump-cluster-spec.ts",
"generate-types": "ts-node tools/src/tester/_generate_story_types.ts",
"lint:spec": "ts-node tools/src/linter/lint.ts",
"lint": "eslint . --report-unused-disable-directives",
"lint--fix": "eslint . --fix --report-unused-disable-directives",
Expand Down
4 changes: 2 additions & 2 deletions tests/_core/bulk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ chapters:
- synopsis: Create an index.
path: /_bulk
method: POST
request_body:
request:
content_type: application/x-ndjson
payload:
- {create: {_index: movies}}
- {director: Bennett Miller, title: Moneyball, year: 2011}
- synopsis: Bulk document CRUD.
path: /_bulk
method: POST
request_body:
request:
content_type: application/x-ndjson
payload:
- {create: {_index: books, _id: book_1392214}}
Expand Down
2 changes: 1 addition & 1 deletion tests/_core/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: PUT
parameters:
index: movies
request_body:
request:
payload:
mappings:
properties:
Expand Down
16 changes: 8 additions & 8 deletions tests/_core/reindex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ prologues:
parameters:
index: movies
refresh: true
request_body:
request:
payload:
title: Beauty and the Beast
year: 91
Expand All @@ -26,7 +26,7 @@ chapters:
- synopsis: Reindex from movies to films.
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index: movies
Expand All @@ -39,7 +39,7 @@ chapters:
- synopsis: Reindex a subset of documents (match).
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index: movies
Expand All @@ -55,7 +55,7 @@ chapters:
- synopsis: Reindex a subset of documents (no match).
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index: movies
Expand All @@ -71,7 +71,7 @@ chapters:
- synopsis: Combine two indexes.
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index:
Expand All @@ -86,7 +86,7 @@ chapters:
- synopsis: Reindex only unique documents.
path: /_reindex
method: POST
request_body:
request:
payload:
conflicts: proceed
source:
Expand All @@ -101,7 +101,7 @@ chapters:
- synopsis: Transform documents during reindex.
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index: movies
Expand All @@ -120,7 +120,7 @@ chapters:
parameters:
max_docs: 1
slices: 1
request_body:
request:
payload:
source:
index: movies
Expand Down
8 changes: 4 additions & 4 deletions tests/_core/reindex/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ epilogues:
prologues:
- path: /_ingest/pipeline/transform-and-count
method: PUT
request_body:
request:
payload:
description: |
Splits the `title`` field into a `words` list.
Expand All @@ -35,7 +35,7 @@ prologues:
parameters:
index: movies
refresh: true
request_body:
request:
payload:
title: Beauty and the Beast
year: 91
Expand All @@ -44,7 +44,7 @@ chapters:
- synopsis: Transform documents using a pipeline.
path: /_reindex
method: POST
request_body:
request:
payload:
source:
index: movies
Expand All @@ -67,7 +67,7 @@ chapters:
method: POST
parameters:
index: videos
request_body:
request:
payload:
query:
match_all: {}
Expand Down
12 changes: 6 additions & 6 deletions tests/_core/search/_source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand All @@ -22,7 +22,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
_source: true
query:
Expand All @@ -48,7 +48,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
_source: false
query:
Expand All @@ -70,7 +70,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
_source:
- director
Expand All @@ -97,7 +97,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
_source:
includes: director
Expand All @@ -123,7 +123,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
_source:
includes: '*'
Expand Down
2 changes: 1 addition & 1 deletion tests/_core/search/cancel_after_time_interval.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand Down
6 changes: 3 additions & 3 deletions tests/_core/search/geo_distance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Test search endpoint with geo_distance query.
prologues:
- path: /map
method: PUT
request_body:
request:
payload:
mappings:
properties:
Expand All @@ -14,7 +14,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
field:
lat: 74
Expand All @@ -30,7 +30,7 @@ chapters:
parameters:
index: map
method: GET
request_body:
request:
payload:
query:
geo_distance:
Expand Down
6 changes: 3 additions & 3 deletions tests/_core/search/match.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand All @@ -22,7 +22,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
size: 1
query:
Expand All @@ -34,7 +34,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
size: 1
query:
Expand Down
4 changes: 2 additions & 2 deletions tests/_core/search/multi_match.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand All @@ -22,7 +22,7 @@ chapters:
parameters:
index: movies
method: POST
request_body:
request:
payload:
size: 1
query:
Expand Down
2 changes: 1 addition & 1 deletion tests/_core/search/phase_took.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand Down
2 changes: 1 addition & 1 deletion tests/_core/search/seq_no_primary_term.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ prologues:
method: POST
parameters:
refresh: true
request_body:
request:
payload:
director: Bennett Miller
title: Moneyball
Expand Down
Loading

0 comments on commit 59a7ff4

Please sign in to comment.