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

feat(schema): schema changes for custom REST endpoints #1509

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
198 changes: 198 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,201 @@
]
}
},
"OpenApiType": {
"type": "object",
"description": "OpenAPI request or response param type.",
"oneOf": [
{
"properties": {
"type": {
"type": "string",
"enum": ["string", "number", "integer", "boolean"]
},
"nullable": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false,
"required": [
"type"
]
},
{
"properties": {
"type": {
"type": "string",
"const": "array"
},
"items": {
"$ref": "#/definitions/OpenApiType"
},
"nullable": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false,
"required": [
"type",
"items"
]
},
{
"properties": {
"type": {
"type": "string",
"const": "object"
},
"properties": {
"type": "object",
"patternProperties": {
"^.+$": {
"$ref": "#/definitions/OpenApiType"
}
}
}
},
"additionalProperties": false,
"required": [
"type",
"properties"
]
},
{
"properties": {
"anyOf": {
"type": "array",
"items": {
"$ref": "#/definitions/OpenApiType"
}
},
"nullable": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false,
"required": [
"anyOf"
]
},
{
"properties": {
"oneOf": {
"type": "array",
"items": {
"$ref": "#/definitions/OpenApiType"
}
},
"nullable": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false,
"required": [
"oneOf"
]
}
]
},
"RestHandlerActionParams": {
"type": "object",
"description": "Request or response parameters for a particular action.",
"additionalProperties": false,
"patternProperties": {
"^.+$": {
"$ref": "#/definitions/OpenApiType"
}
}
},
"RestHandlerParams": {
"type": "object",
"description": "Request or response parameters.",
"additionalProperties": false,
"properties": {
"list": {
"$ref": "#/definitions/RestHandlerActionParams"
},
"edit": {
"$ref": "#/definitions/RestHandlerActionParams"
},
"create": {
"$ref": "#/definitions/RestHandlerActionParams"
},
"remove": {
"$ref": "#/definitions/RestHandlerActionParams"
}
}
},
"RestHandler": {
"type": "object",
"description": "Rest handlers not automatically generated by UCC.",
"properties": {
"endpoint": {
"type": "string",
"description": "The endpoint for the custom rest handler."
},
"handlerType": {
"type": "string",
"description": "The type of the handler.",
"enum": ["EAI"]
},
"registerHandler": {
"type": "object",
"description": "Parameters needed to register the endpoint in web.conf and restmap.conf",
"properties": {
"file": {
"type": "string",
"description": "The file where the custom rest handler is located."
},
"actions": {
"type": "array",
"description": "The actions that the custom rest handler supports.",
"items": {
"type": "string",
"description": "The action that the custom rest handler supports.",
"enum": ["list", "edit", "create", "remove"]
}
}
},
"additionalProperties": false,
"required": [
"file",
"actions"
]
},
"requestParameters": {
"type": "object",
"description": "The parameters that the custom rest handler supports.",
"$ref": "#/definitions/RestHandlerParams"
},
"responseParameters": {
"type": "object",
"description": "The parameters that the custom rest handler returns.",
"$ref": "#/definitions/RestHandlerParams"
}
},
"additionalProperties": false,
"required": [
"endpoint",
"handlerType"
]
},
"Options": {
"type": "object",
"description": "Additional options for the addon",
"properties": {
"restHandlers": {
"type": "array",
"items": {
"$ref": "#/definitions/RestHandler"
}
}
},
"additionalProperties": false
},
"Pages": {
"type": "object",
"description": "Definition of addon pages (configuration, inputs, dashboard)",
Expand Down Expand Up @@ -3407,6 +3602,9 @@
"$ref": "#/definitions/Alerts"
},
"minItems": 1
},
"options": {
"$ref": "#/definitions/Options"
}
},
"required": [
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,46 @@ def test_interval_entity_options(schema_validate, config):
}
)
)


def test_rest_handler_without_ui(schema_validate, config):
crh = {
"endpoint": "some_endpoint",
"handlerType": "EAI",
"requestParameters": {
"create": {
"some_param": {"type": "string"},
"other_param": {"type": "number"},
"other_param_nullable": {
"type": "number",
"nullable": True,
},
},
"list": {
"array_param": {
"type": "array",
"items": {"type": "string"},
},
"obj_param": {
"type": "object",
"properties": {
"key": {"type": "string"},
},
},
},
},
"responseParameters": {
"list": {
"some_param": {"type": "string"},
},
},
}
config.setdefault("options", {})["restHandlers"] = [crh]
schema_validate(config)

crh["registerHandler"] = {
"file": "my_handler.py",
"actions": ["list", "create", "edit", "remove"],
}

schema_validate(config)
Loading