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.propertiesfromapi_dirif it exists.
- load_endpoints() None
Read all
*.mdfiles inapi_dirand parse them intoApiEndpointinstances.
- parse_markdown_file(file_path) ApiEndpoint | None
Parse a single markdown spec file.
Extraction rules:
Line 0 →
pathLine 1 →
descriptionRegex
(GET|POST|PUT|DELETE|PATCH) (https?://\S+)→method,urlRegex
Content type\n\s*\|\s*([^\n]+)→content_typeHeaderstable → list of dicts withname,type,descriptionParameterstable → list of dicts withname,type,required,descriptionBody payloadtable → list of dicts withname,typeResponsesection →response_examplestring
- generate_config_files() None
Create JSON configs in
config_dirfor 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→{},number→0,boolean→False, 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 temporaryApiClientwith an empty token to avoid auth prompts.For non-auth APIs, injects
access_tokenandid_tokenfromauth.propertiesinto theaccess-tokenandAuthorizationheaders 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 theirAuthorizationandaccess-tokenheader 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.