api_runner.py

Parses markdown API documentation to generate JSON configs and runs them.

Classes

class api_runner.ApiEndpoint

Data class representing a single API endpoint parsed from markdown.

path: str
description: str
method: str
url: str
content_type: str
headers: list[dict]
parameters: list[dict]
body_params: list[dict]
response_example: str
file_name: str
to_dict() dict

Serialize the endpoint to a dictionary.

__str__() str

Return a human-readable summary: METHOD path - description.

class api_runner.ApiRunner(api_dir='./', config_dir='config')

Orchestrates config generation and execution.

_load_auth_properties() dict

Load auth.properties from api_dir if it exists.

load_endpoints() None

Read all *.md files in api_dir and parse them into ApiEndpoint instances.

parse_markdown_file(file_path) ApiEndpoint | None

Parse a single markdown spec file.

Extraction rules:

  • Line 0 → path

  • Line 1 → description

  • Regex (GET|POST|PUT|DELETE|PATCH) (https?://\S+)method, url

  • Regex Content type\n\s*\|\s*([^\n]+)content_type

  • Headers table → list of dicts with name, type, description

  • Parameters table → list of dicts with name, type, required, description

  • Body payload table → list of dicts with name, type

  • Response section → response_example string

generate_config_files() None

Create JSON configs in config_dir for every loaded endpoint.

Default config structure:

{
  "endpoint": { ... },
  "config": {
    "headers": {},
    "path_params": {},
    "query_params": {},
    "body": {}
  }
}

Body defaults are typed based on the parameter type declared in markdown: object/array{}, number0, booleanFalse, everything else → "".

list_apis() None

Print all generated configs with method, path, and description.

run_api(api_name) bool

Execute a single API using its JSON config.

Special handling for auth-signin: creates a temporary ApiClient with an empty token to avoid auth prompts.

For non-auth APIs, injects access_token and id_token from auth.properties into the access-token and Authorization headers if they are empty in the config.

_handle_auth_signin_response(response) None

Extract tokens from a successful sign-in response and write them to auth.properties. Also calls _update_config_files_with_tokens().

_update_config_files_with_tokens(access_token, id_token) None

Iterate all JSON config files (except auth-signin.json) and set their Authorization and access-token header values.

run_all_apis() None

Run every config file in alphabetical order.

Functions

api_runner.print_usage()

Print the module docstring (usage information).

api_runner.main()

CLI entry point for commands: generate, list, run <api_name>, run-all.