MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / oa_operation

Function oa_operation

internal/cbm/openapi.c:134–188  ·  view source on GitHub ↗

One operation: its Route, and its operationId's reference. */

Source from the content-addressed store, hash-verified

132
133/* One operation: its Route, and its operationId's reference. */
134static void oa_operation(CBMExtractCtx *ctx, const char *path, const char *method, TSNode op,
135 TSNode path_item, TSNode pair) {
136 CBMArena *a = ctx->arena;
137 char upper[OA_METHOD_MAX];
138 size_t ml = strlen(method);
139 for (size_t i = 0; i < ml && i + SKIP_ONE < sizeof(upper); i++) {
140 upper[i] = (char)toupper((unsigned char)method[i]);
141 upper[i + SKIP_ONE] = '\0';
142 }
143 size_t pl = strlen(path);
144 char *canon = (char *)cbm_arena_alloc(a, pl + SKIP_ONE);
145 const char *qn = canon ? cbm_arena_sprintf(a, "__route__%s__%s", upper,
146 cbm_route_canon_path(path, canon, pl + SKIP_ONE))
147 : NULL;
148 const char *op_id = oa_dup_scalar(ctx, oa_get(ctx, op, "operationId"));
149 const char **kv = (const char **)cbm_arena_alloc(a, CBM_SZ_7 * sizeof(char *));
150 const char *m = cbm_arena_strdup(a, upper);
151 if (!qn || !kv || !m) {
152 return;
153 }
154 kv[0] = "method";
155 kv[SKIP_ONE] = m;
156 kv[PAIR_LEN] = "source";
157 kv[CBM_SZ_3] = "openapi";
158 kv[CBM_SZ_4] = op_id ? "operation_id" : NULL;
159 kv[CBM_SZ_5] = op_id;
160 kv[CBM_SZ_6] = NULL;
161 CBMDefinition def;
162 memset(&def, 0, sizeof(def));
163 def.name = cbm_arena_strdup(a, path);
164 def.qualified_name = qn;
165 def.label = "Route";
166 def.file_path = ctx->rel_path;
167 def.start_line = ts_node_start_point(pair).row + SKIP_ONE;
168 def.end_line = ts_node_end_point(pair).row + SKIP_ONE;
169 def.extra_props = kv;
170 if (!def.name) {
171 return;
172 }
173 cbm_defs_push(&ctx->result->defs, a, def);
174 if (!op_id) {
175 return;
176 }
177 const char *controller = oa_controller(ctx, op, path_item);
178 CBMDocLink link = {
179 .source_qn = qn,
180 .raw = controller ? cbm_arena_sprintf(a, "%s.%s", controller, op_id) : op_id,
181 .line = def.start_line,
182 .def_line = def.start_line,
183 .syntax = CBM_DOCLINK_OPENAPI_OPERATION_ID,
184 };
185 if (link.raw) {
186 cbm_doclinks_push(&ctx->result->doc_links, a, link);
187 }
188}
189
190static bool oa_method(const char *k) {
191 static const char *const methods[] = {"get", "put", "post", "delete", "options",

Callers 1

cbm_extract_openapiFunction · 0.85

Calls 9

cbm_route_canon_pathFunction · 0.85
oa_dup_scalarFunction · 0.85
oa_getFunction · 0.85
cbm_defs_pushFunction · 0.85
oa_controllerFunction · 0.85
cbm_doclinks_pushFunction · 0.85
cbm_arena_allocFunction · 0.70
cbm_arena_sprintfFunction · 0.70
cbm_arena_strdupFunction · 0.70

Tested by

no test coverage detected