|
cwist
Modern C web framework with libttak runtime
|
Runtime OpenAPI 3.1 endpoint (#408). More...
#include <cwist/openapi.h>#include <cwist/core/mem/alloc.h>#include <cjson/cJSON.h>#include <pthread.h>#include <string.h>#include <strings.h>#include "routes_internal.h"
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
Typedefs | |
| typedef struct openapi_note | openapi_note |
| typedef struct openapi_doc | openapi_doc |
Functions | |
| void | cwist_app_enable_openapi (cwist_app *app, const char *json_path, const cwist_openapi_meta_t *meta) |
| Serve the app's OpenAPI 3.1 document. | |
| void | cwist_openapi_annotate (cwist_app *app, const char *method, const char *path, const char *summary, const char *tags) |
| Attach a summary and tags to one operation of the document. | |
Runtime OpenAPI 3.1 endpoint (#408).
cwist_app_enable_openapi() mounts a GET route whose context is the app's document state: metadata plus cwist_openapi_annotate() entries. Every request walks the live route table, so a route added anywhere shows up with its path and method; annotations only add a summary and tags.
The route owns the state and frees it with the app. A small registry maps the app back to its state so cwist_openapi_annotate() can find it.
Definition in file openapi.c.
| void cwist_app_enable_openapi | ( | cwist_app * | app, |
| const char * | json_path, | ||
| const cwist_openapi_meta_t * | meta | ||
| ) |
Serve the app's OpenAPI 3.1 document.
Registers GET json_path. The document lists every HTTP route of app at request time (the spec route itself and WebSocket routes excepted), so routes added before or after this call are all included. A second call on the same app is ignored.
| app | Application to serve the document from. |
| json_path | URL path of the document; NULL means "/openapi.json". |
| meta | Document metadata; NULL uses the defaults. |
Definition at line 210 of file openapi.c.
References cap, cwist_alloc(), cwist_app_get_ex(), cwist_free(), and cwist_strdup().
| void cwist_openapi_annotate | ( | cwist_app * | app, |
| const char * | method, | ||
| const char * | path, | ||
| const char * | summary, | ||
| const char * | tags | ||
| ) |
Attach a summary and tags to one operation of the document.
Takes effect only after cwist_app_enable_openapi() on the same app. Annotating the same method and path again replaces the earlier values.
| app | Application owning the route. |
| method | HTTP method name, case-insensitive ("GET", "post", ...). |
| path | Route path exactly as registered (e.g. "/users/:id"). |
| summary | Operation summary, or NULL. |
| tags | Comma-separated tag list, or NULL. |
Definition at line 242 of file openapi.c.
References cap, cwist_alloc(), cwist_free(), CWIST_HTTP_UNKNOWN, and cwist_strdup().