Skip to content

Commit

Permalink
Support outputs on tests (#324)
Browse files Browse the repository at this point in the history
* Support outputs in tests

Signed-off-by: miguel-vila <miguelvilag@gmail.com>
  • Loading branch information
miguel-vila committed Jun 11, 2024
1 parent ba3f5b2 commit 53bdbd9
Show file tree
Hide file tree
Showing 20 changed files with 1,040 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added code coverage to tools' tests ([#323](https://github.com/opensearch-project/opensearch-api-specification/pull/323))
- Added a YAML linter ([#312](https://github.com/opensearch-project/opensearch-api-specification/pull/312))
- Added linter to validate order of spec operations ([#325](https://github.com/opensearch-project/opensearch-api-specification/pull/326)) ([#326](https://github.com/opensearch-project/opensearch-api-specification/pull/326))
- Added support to read outputs from requests in tests([#324](https://github.com/opensearch-project/opensearch-api-specification/pull/324))

### Changed

Expand Down
18 changes: 17 additions & 1 deletion json_schemas/test_story.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ definitions:
ChapterRequest:
type: object
properties:
id:
type: string
description: A unique identifier for the chapter, useful for accessing outputs.
path:
type: string
method:
Expand All @@ -77,9 +80,22 @@ definitions:
$ref: '#/definitions/Parameter'
request_body:
$ref: '#/definitions/RequestBody'
output:
$ref: '#/definitions/Output'
required: [path, method]
additionalProperties: false

Output:
description: |
Describes output for a chapter.
The keys are the names for the variable in the chapter output.
The values are paths to the values in the response.
The values should be in the form:
- `payload.<payload-path>` for the payload
- `headers.<header-name>` for the headers
type: object
additionalProperties:
type: string

RequestBody:
type: object
Expand Down Expand Up @@ -143,4 +159,4 @@ definitions:
- type: boolean
- type: string
- type: number
- type: boolean
- type: boolean
270 changes: 270 additions & 0 deletions spec/namespaces/ml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
openapi: 3.1.0
info:
title: OpenSearch ML API
description: OpenSearch ML API
version: 1.0.0
paths:
/_plugins/_ml/model_groups/_register:
post:
operationId: ml.register_model_group.0
x-operation-group: ml.register_model_group
description: Registers a model group.
requestBody:
$ref: '#/components/requestBodies/ml.register_model_group'
responses:
'200':
$ref: '#/components/responses/ml.register_model_group@200'
/_plugins/_ml/model_groups/{model_group_id}:
get:
operationId: ml.get_model_group.0
x-operation-group: ml.get_model_group
description: Retrieves a model group.
parameters:
- $ref: '#/components/parameters/ml.get_model_group::path.model_group_id'
responses:
'200':
$ref: '#/components/responses/ml.get_model_group@200'
delete:
operationId: ml.delete_model_group.0
x-operation-group: ml.delete_model_group
description: Deletes a model group.
parameters:
- $ref: '#/components/parameters/ml.delete_model_group::path.model_group_id'
responses:
'200':
$ref: '#/components/responses/ml.delete_model_group@200'
/_plugins/_ml/models/_register:
post:
operationId: ml.register_model.0
x-operation-group: ml.register_model
description: Registers a model.
requestBody:
$ref: '#/components/requestBodies/ml.register_model'
responses:
'200':
$ref: '#/components/responses/ml.register_model@200'
/_plugins/_ml/models/{model_id}:
delete:
operationId: ml.delete_model.0
x-operation-group: ml.delete_model
description: Deletes a model.
parameters:
- $ref: '#/components/parameters/ml.delete_model::path.model_id'
responses:
'200':
$ref: '#/components/responses/ml.delete_model@200'
/_plugins/_ml/tasks/{task_id}:
get:
operationId: ml.get_task.0
x-operation-group: ml.get_task
description: Retrieves a task.
parameters:
- $ref: '#/components/parameters/ml.get_task::path.task_id'
responses:
'200':
$ref: '#/components/responses/ml.get_task@200'
/_plugins/_ml/models/_search:
get:
operationId: ml.search_models.0
x-operation-group: ml.search_models
description: Searches for models.
requestBody:
$ref: '#/components/requestBodies/ml.search_models'
responses:
'200':
$ref: '#/components/responses/ml.search_models@200'
components:
requestBodies:
ml.register_model_group:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: The model group name.
description:
type: string
description: The model group description.
access_mode:
type: string
description: The model group access mode.
enum: [private, public, restricted]
backend_roles:
type: array
items:
type: string
description: The backend roles.
add_all_backend_roles:
type: boolean
description: The add all backend roles.
required:
- name
ml.register_model:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: The model name.
version:
type: string
description: The model version.
model_format:
type: string
description: The portable format of the model file.
enum: [TORCH_SCRIPT, ONNX]
description:
type: string
description: The model description.
model_group_id:
type: string
description: The ID of the model group to which to register the model.
required:
- name
- version
- model_format
ml.search_models:
content:
application/json:
schema:
type: object
properties:
query:
type: object
# TODO: Define the query schema
description: The query.
size:
type: integer
description: The number of models to return.
required:
- query
- size
responses:
ml.register_model_group@200:
content:
application/json:
schema:
type: object
properties:
model_group_id:
type: string
description: The model group ID.
status:
type: string
description: The status.
required:
- model_group_id
- status
ml.get_model_group@200:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description: The model group name.
latest_version:
type: number
description: The latest version.
description:
type: string
description: The model group description.
access:
type: string
description: The model group access.
required:
- name
- latest_version
- description
- access
ml.delete_model_group@200:
content:
application/json:
schema:
type: object
ml.register_model@200:
content:
application/json:
schema:
type: object
properties:
task_id:
type: string
description: The task ID.
model_id:
type: string
description: The model ID.
status:
type: string
description: The status.
required:
# model_id doesn't seem to be required in the response
# it can be eventually retrieved through the task_id
- task_id
- status
ml.delete_model@200:
content:
application/json:
schema:
type: object
ml.get_task@200:
content:
application/json:
schema:
type: object
properties:
model_id:
type: string
description: The model ID.
state:
type: string
description: The state.
enum:
- CREATED
- RUNNING
- COMPLETED
- FAILED
- CANCELLED
- COMPLETED_WITH_ERROR
required:
- state
ml.search_models@200:
content:
application/json:
schema:
type: object
properties:
hits:
$ref: '../schemas/ml._common.yaml#/components/schemas/SearchModelHits'
required:
- hits
parameters:
ml.get_model_group::path.model_group_id:
name: model_group_id
in: path
required: true
schema:
type: string
ml.delete_model_group::path.model_group_id:
name: model_group_id
in: path
required: true
schema:
type: string
ml.delete_model::path.model_id:
name: model_id
in: path
required: true
schema:
type: string
ml.get_task::path.task_id:
name: task_id
in: path
required: true
schema:
type: string
47 changes: 47 additions & 0 deletions spec/schemas/ml._common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
openapi: 3.1.0
info:
title: Schemas of ml category
description: Schemas of ml category
version: 1.0.0
paths: {}
components:
schemas:
SearchModelHits:
type: object
properties:
total:
$ref: '#/components/schemas/HitsTotal'
hits:
type: array
items:
$ref: '#/components/schemas/SearchModelHitsHit'
required:
- total
- hits
HitsTotal:
type: object
properties:
value:
type: integer
description: The total number of hits.
relation:
type: string
description: The relation.
required:
- value
- relation
SearchModelHitsHit:
type: object
properties:
_index:
type: string
description: The index.
_id:
type: string
description: The hit ID.
model_id:
type: string
description: The model ID.
required:
- _id
- model_id
Loading

0 comments on commit 53bdbd9

Please sign in to comment.