diff --git a/commit/api/bruno.py b/commit/api/bruno.py new file mode 100644 index 0000000..904c0e7 --- /dev/null +++ b/commit/api/bruno.py @@ -0,0 +1,66 @@ +import frappe + +@frappe.whitelist() +def generate_bruno_file(data): + request_data = frappe.parse_json(data) + """ + Generates .bru file content for a single request based on the provided request data. + + :param request_data: A dictionary containing request information. + Expected keys are: + - name: The name of the request. + - arguments: A list of dictionaries containing argument information. + - def: The function definition. + - def_index: The index of the function definition. + - request_types: A list of request types (e.g., ['GET', 'POST']). + - xss_safe: A boolean indicating if the request is XSS safe. + - allow_guest: A boolean indicating if guests are allowed. + - other_decorators: A list of other decorators. + - index: An index number. + - block_start: The start of the block. + - block_end: The end of the block. + - file: The file path. + - api_path: The API path in the format 'raven.www.raven.get_context_for_dev'. + :return: A dictionary where keys are request types and values are the content of the corresponding .bru files. + """ + base_url_template = "{{baseUrl}}/api/method" + + def format_name(name): + return ' '.join(word.capitalize() for word in name.split('_')) + + name = format_name(request_data.get('name', 'Request')) + api_path = request_data.get('api_path', '') + request_types = request_data.get('request_types', ['GET']) or ['GET'] # Default to GET if empty + params = {arg['argument']: arg['default'] for arg in request_data.get('arguments', []) if arg['argument']} + + bru_files = {} + + for request_type in request_types: + seq = 1 + request_type_upper = request_type.upper() + request_type_lower = request_type.lower() + url = f"{base_url_template}/{api_path}" + + query_string = '&'.join([f'{k}={v}' for k, v in params.items() if v]) + full_url = f'{url}?{query_string}' if query_string else url + + bru_content = [] + + # Meta section + bru_content.append(f'meta {{\n name: {name}\n type: http\n seq: {seq}\n}}\n') + + # Request section + bru_content.append(f'{request_type_lower} {{\n url: {full_url}\n body: none\n auth: none\n}}\n') + + # Params section + if params: + bru_content.append(f'params:query {{\n') + for k, v in params.items(): + if v: + bru_content.append(f' {k}: {v}\n') + bru_content.append('}\n') + + bru_files[request_type_upper] = '\n'.join(bru_content) + frappe.local.response.filename = f'{name} {request_type}.bru' if len(request_types) > 1 else f'{name}.bru' + frappe.local.response.filecontent = bru_files[request_type_upper] + frappe.local.response.type = 'download' \ No newline at end of file diff --git a/dashboard/src/components/features/api_viewer/APIDetails.tsx b/dashboard/src/components/features/api_viewer/APIDetails.tsx index 8834889..7f5829b 100644 --- a/dashboard/src/components/features/api_viewer/APIDetails.tsx +++ b/dashboard/src/components/features/api_viewer/APIDetails.tsx @@ -3,6 +3,7 @@ import { ErrorBanner } from "@/components/common/ErrorBanner/ErrorBanner" import { FullPageLoader } from "@/components/common/FullPageLoader/FullPageLoader" import { Tabs } from "@/components/common/Tabs" import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { web_url } from "@/config/socket" import { APIData, Argument } from "@/types/APIData" import { XMarkIcon } from "@heroicons/react/24/outline" import { useFrappeGetCall } from "frappe-react-sdk" @@ -36,6 +37,13 @@ export const APIDetails = ({ project_branch, endpointData, selectedEndpoint, set } } + const rest = useMemo(() => { + if (data) { + const { allow_guest, xss_safe, documentation, block_end, block_start, index, ...rest } = data + return rest + } + }, [data]) + const requestTypeBorderColor = (requestType: string) => { switch (requestType) { case 'GET': @@ -56,13 +64,11 @@ export const APIDetails = ({ project_branch, endpointData, selectedEndpoint, set