feat(xo-server/rest-api): expose actions' params schema
This commit is contained in:
parent
8e65ef7dbc
commit
5cabf9916a
@ -279,12 +279,45 @@ The following query parameters are supported to customize the created VDI:
|
||||
|
||||
To see the actions available on a given object, get the collection at `/rest/v0/<type>/<uuid>/actions`.
|
||||
|
||||
The field `params` contains the [JSON schema](https://json-schema.org/) for the parameters. Use `fields=params` to see it when fetching the collection.
|
||||
|
||||
For example, to list all actions on a given VM:
|
||||
|
||||
```sh
|
||||
curl \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.example.org/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions'
|
||||
'https://xo.example.org/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions?fields=params'
|
||||
```
|
||||
|
||||
Example response:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/clean_reboot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/clean_shutdown"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/hard_reboot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/hard_shutdown"
|
||||
},
|
||||
{
|
||||
"params": {
|
||||
"name_label": {
|
||||
"type": "string",
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/snapshot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/start"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Start an action
|
||||
|
@ -285,12 +285,45 @@ The following query parameters are supported to customize the created VDI:
|
||||
|
||||
To see the actions available on a given object, get the collection at `/rest/v0/<type>/<uuid>/actions`.
|
||||
|
||||
The field `params` contains the [JSON schema](https://json-schema.org/) for the parameters. Use `fields=params` to see it when fetching the collection.
|
||||
|
||||
For example, to list all actions on a given VM:
|
||||
|
||||
```sh
|
||||
curl \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.company.lan/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions'
|
||||
'https://xo.company.lan/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions?fields=params'
|
||||
```
|
||||
|
||||
Example response:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/clean_reboot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/clean_shutdown"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/hard_reboot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/hard_shutdown"
|
||||
},
|
||||
{
|
||||
"params": {
|
||||
"name_label": {
|
||||
"type": "string",
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/snapshot"
|
||||
},
|
||||
{
|
||||
"href": "/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac/actions/start"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Start an action
|
||||
|
@ -230,6 +230,7 @@ export default class RestApi {
|
||||
}
|
||||
|
||||
const withParams = (fn, paramsSchema) => {
|
||||
fn.params = paramsSchema
|
||||
fn.validateParams = compileXoJsonSchema({ type: 'object', properties: cloneDeep(paramsSchema) })
|
||||
return fn
|
||||
}
|
||||
@ -594,7 +595,11 @@ export default class RestApi {
|
||||
'/:collection/:object/actions',
|
||||
wrap((req, res) => {
|
||||
const { actions } = req.collection
|
||||
return sendObjects(actions === undefined ? [] : Array.from(Object.keys(actions), id => ({ id })), req, res)
|
||||
return sendObjects(
|
||||
actions === undefined ? [] : Array.from(Object.keys(actions), id => ({ ...actions[id], id })),
|
||||
req,
|
||||
res
|
||||
)
|
||||
})
|
||||
)
|
||||
api.post('/:collection/:object/actions/:action', json(), (req, res, next) => {
|
||||
|
Loading…
Reference in New Issue
Block a user