From 0118dc90377ab1ee4e480d0c76f4cd00f7b422c0 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 1 Apr 2024 09:58:24 -0400 Subject: [PATCH] api docs and schema updates --- .../bin/codemod/extract_functions.py | 44 +++++++++++++++++++ .../bin/codemod/extract_functions.sh | 23 ++++++++++ .../src/spiffworkflow_backend/api.yml | 24 +++++++--- 3 files changed, 84 insertions(+), 7 deletions(-) create mode 100755 spiffworkflow-backend/bin/codemod/extract_functions.py create mode 100755 spiffworkflow-backend/bin/codemod/extract_functions.sh diff --git a/spiffworkflow-backend/bin/codemod/extract_functions.py b/spiffworkflow-backend/bin/codemod/extract_functions.py new file mode 100755 index 000000000..852355987 --- /dev/null +++ b/spiffworkflow-backend/bin/codemod/extract_functions.py @@ -0,0 +1,44 @@ +# extract_functions.py + +import ast +import sys + + +def extract_function_body(filename, function_name): + file_lines = None + with open(filename, "r") as file: + file_lines = file.read() + tree = ast.parse(file_lines, filename=filename) + # file_lines = file.readlines() + # # convert file_lines to string + # file_lines = "".join(file_lines) + + # Dictionary to store function bodies + function_bodies = {} + + # Find the target function and its dependencies + for node in ast.walk(tree): + if isinstance(node, ast.FunctionDef): + if node.name == function_name: + function_bodies[node.name] = ast.get_source_segment(file_lines, node) + + # Extract dependencies + # for n in ast.walk(node): + # if isinstance(n, ast.Call): + # function_bodies[n.func.id] = extract_function_body(filename, n.func.id) + + return function_bodies + + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python extract_functions.py ") + sys.exit(1) + + filename = sys.argv[1] + function_name = sys.argv[2] + function_bodies = extract_function_body(filename, function_name) + for func_name, func_body in function_bodies.items(): + print(f"Function: {func_name}") + print(func_body) + print() diff --git a/spiffworkflow-backend/bin/codemod/extract_functions.sh b/spiffworkflow-backend/bin/codemod/extract_functions.sh new file mode 100755 index 000000000..1e16c4260 --- /dev/null +++ b/spiffworkflow-backend/bin/codemod/extract_functions.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +function error_handler() { + >&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}." + exit "$2" +} +trap 'error_handler ${LINENO} $?' ERR +set -o errtrace -o errexit -o nounset -o pipefail + +function_name=$1 +filename=$2 + +python spiffworkflow-backend/bin/codemod/extract_functions.py "$filename" "$function_name" +function_body=$(python spiffworkflow-backend/bin/codemod/extract_functions.py "$filename" "$function_name") + +# Extract function calls and recursively extract their bodies +while IFS= read -r line; do + if [[ "$line" =~ ^Function:\ (.*)$ ]]; then + called_function="${BASH_REMATCH[1]}" + echo "$line" + echo "$function_body" | grep -q "Function: $called_function" || ./extract_functions.sh "$called_function" "$filename" + fi +done <<<"$function_body" diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 942185d1f..9ed003cb3 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -324,16 +324,26 @@ paths: tags: - Active User operationId: spiffworkflow_backend.routes.active_users_controller.active_user_updates - summary: An SSE (Server Sent Events) endpoint that returns what users are also currently viewing the same page as you. + summary: An endpoint that updates the active user's last seen timestamp and returns other active users on the same page. responses: "200": - description: list of users + description: List of active users on the same page. content: application/json: schema: type: array items: - $ref: "#/components/schemas/User" + type: object + properties: + user_id: + type: integer + description: The unique identifier of the user. + username: + type: string + description: The username of the active user. + last_seen: + type: integer + description: The last seen timestamp in seconds. /active-users/unregister/{last_visited_identifier}: parameters: @@ -347,10 +357,10 @@ paths: tags: - Active User operationId: spiffworkflow_backend.routes.active_users_controller.active_user_unregister - summary: Unregisters a user from a page. To be used when the /active-users/updates endpoint is closed. + summary: Unregisters a user from being active on a page. responses: "200": - description: The current user has unregistered. + description: The current user has been successfully unregistered from the page. content: application/json: schema: @@ -392,7 +402,7 @@ paths: $ref: "#/components/schemas/ProcessGroup" post: operationId: spiffworkflow_backend.routes.process_groups_controller.process_group_create - summary: Add process group + summary: Creates a new process group with the provided details. tags: - Process Groups requestBody: @@ -402,7 +412,7 @@ paths: $ref: "#/components/schemas/ProcessGroup" responses: "201": - description: Processs Group + description: The newly created process group. content: application/json: schema: