Module <cweb/cwagger.h> — API documentation (Cwagger)
Similar to Swagger/OpenAPI: you register endpoints at runtime; a built-in page can render the documentation.
Constants
CWAGGER_MAX_ENDPOINTS,CWAGGER_MAX_METHOD_LEN,CWAGGER_MAX_PATH_LEN,CWAGGER_MAX_DESCRIPTION_LEN,CWAGGER_MAX_SCHEMA_LEN
Types
cwagger_detail: optional JSON-schema-like strings for request/response/expected_arguments.cwagger_endpoint: HTTP method, path, short description,detail.cwagger_doc: path to doc route and array of endpoints.
Initialization and registration
void cwagger_init(const char *doc_path)
- Purpose: Sets the URL path (e.g.
"/cwagger") where the documentation page should be reachable.
int cwagger_add(const char *method, const char *path, const char *short_description, const cwagger_detail *detail)
- Purpose: Registers a documented endpoint.
- Parameters:
method—"GET","POST", …path— route path.short_description— one-line description.detail— optional (may beNULL); JSON descriptions for request/response.
- Return:
0on success, otherwise error code (e.g. full table).
Queries
const cwagger_doc *cwagger_get_doc(void)
- Purpose: Full documentation structure (read-only).
cwagger_endpoint *cwagger_get_endpoints(void) / const cwagger_endpoint *cwagger_get_endpoint(size_t index)
- Purpose: Access endpoint list or single element.
size_t cwagger_get_endpoint_count(void)
- Purpose: Number of registered endpoints.
const char *cwagger_get_doc_path(void)
- Purpose: Currently configured doc path.
HTTP handler
void cweb_cwaggerdoc_page(Request *req, Response *res)
- Purpose: Route handler: renders the Cwagger documentation page into
res. - Usage: Register as handler for the path configured with
cwagger_init(or via auto-routing if your project wires it that way).
See also
- routing.md — assigning routes
- http.md — request/response