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: GET methods and responses allow to get data #742

Merged
merged 1 commit into from
Apr 25, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import copy
from enum import Flag, auto
from functools import lru_cache
from typing import List, Tuple, Dict, Any, Optional, Union
from typing import List, Tuple, Dict, Any, Optional
from splunk_add_on_ucc_framework import global_config as global_config_lib
from splunk_add_on_ucc_framework import app_manifest as app_manifest_lib
from splunk_add_on_ucc_framework.commands.openapi_generator.oas import (
Expand Down Expand Up @@ -154,8 +154,8 @@ def __add_schemas_object(
"type": "singleSelect",
"options": {
"autoCompleteFields": [
{"value": "0"},
{"value": "1"},
{"value": "False"},
{"value": "True"},
]
},
}
Expand Down Expand Up @@ -186,31 +186,41 @@ def __add_schemas_object(
# consider changing to 'cache' once python is upgraded to >=3.9
@lru_cache(maxsize=None)
def __get_media_type_object_with_schema_ref(
*, schema_name: str, schema_type: Optional[str] = None
*, schema_name: str, for_responses: bool = False
) -> oas.MediaTypeObject:
ref_dict = {"$ref": f"#/components/schemas/{schema_name}"}
schema: Union[oas.SchemaObject, Dict] = (
oas.SchemaObject(
type=schema_type,
items=ref_dict,
)
if schema_type
else ref_dict
if for_responses:
schema_name = __create_schema_name(name=schema_name, without=["name"])
schema: Optional[Dict[str, Any]] = (
{"$ref": f"#/components/schemas/{schema_name}"}
if not for_responses
else {
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"content": {"$ref": f"#/components/schemas/{schema_name}"},
},
},
}
},
}
)
return oas.MediaTypeObject(schema=schema)


def __get_path_get(
*, name: str, description: str, schema_type: Optional[str] = None
) -> oas.OperationObject:
def __get_path_get(*, name: str, description: str) -> oas.OperationObject:
return oas.OperationObject(
description=description,
responses={
"200": oas.ResponseObject(
description=description,
content={
"application/json": __get_media_type_object_with_schema_ref(
schema_name=name, schema_type=schema_type
schema_name=name, for_responses=True
),
},
)
Expand All @@ -220,7 +230,7 @@ def __get_path_get(

def __get_path_get_for_list(*, name: str) -> oas.OperationObject:
description = f"Get list of items for {name}"
return __get_path_get(name=name, description=description, schema_type="array")
return __get_path_get(name=name, description=description)


def __get_path_get_for_item(*, name: str) -> oas.OperationObject:
Expand All @@ -247,7 +257,7 @@ def __get_path_post(
description=description,
content={
"application/json": __get_media_type_object_with_schema_ref(
schema_name=name
schema_name=name, for_responses=True
),
},
)
Expand Down Expand Up @@ -282,7 +292,7 @@ def __get_path_delete(*, name: str) -> oas.OperationObject:
description=description,
content={
"application/json": __get_media_type_object_with_schema_ref(
schema_name=name, schema_type="array"
schema_name=name, for_responses=True
),
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,22 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/account"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/account_without_name"
}
}
}
}
}
}
}
Expand All @@ -265,7 +278,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/account"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/account_without_name"
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -308,7 +337,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/account"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/account_without_name"
}
}
}
}
}
}
}
}
Expand All @@ -324,7 +369,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/account"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/account_without_name"
}
}
}
}
}
}
}
}
Expand All @@ -350,9 +411,22 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/account"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/account_without_name"
}
}
}
}
}
}
}
Expand Down Expand Up @@ -395,9 +469,22 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/proxy"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/proxy_without_name"
}
}
}
}
}
}
}
Expand All @@ -414,7 +501,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/proxy"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/proxy_without_name"
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -457,9 +560,22 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/logging"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/logging_without_name"
}
}
}
}
}
}
}
Expand All @@ -476,7 +592,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/logging"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/logging_without_name"
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -519,9 +651,22 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/custom_abc"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/custom_abc_without_name"
}
}
}
}
}
}
}
Expand All @@ -538,7 +683,23 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/custom_abc"
"type": "object",
"properties": {
"entry": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"content": {
"$ref": "#/components/schemas/custom_abc_without_name"
}
}
}
}
}
}
}
}
Expand Down