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

Function cbm_extract_openapi

internal/cbm/openapi.c:201–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201void cbm_extract_openapi(CBMExtractCtx *ctx) {
202 if (!ctx || !ctx->result || !ctx->source || ts_node_is_null(ctx->root) ||
203 (ctx->language != CBM_LANG_OPENAPI && ctx->language != CBM_LANG_YAML &&
204 ctx->language != CBM_LANG_JSON)) {
205 return;
206 }
207 TSNode root = oa_mapping(ctx->root);
208 if (ts_node_is_null(oa_get(ctx, root, "openapi")) &&
209 ts_node_is_null(oa_get(ctx, root, "swagger"))) {
210 return; /* no API description */
211 }
212 TSNode paths = oa_mapping(oa_get(ctx, root, "paths"));
213 char path[OA_SCALAR_MAX];
214 char key[OA_SCALAR_MAX];
215 uint32_t np = ts_node_is_null(paths) ? 0 : ts_node_named_child_count(paths);
216 for (uint32_t i = 0; i < np; i++) {
217 TSNode pp = ts_node_named_child(paths, i);
218 if (!oa_pair(pp) ||
219 !oa_scalar(ctx, ts_node_child_by_field_name(pp, "key", CBM_SZ_3), path, sizeof(path)) ||
220 path[0] != '/') {
221 continue;
222 }
223 TSNode item = oa_mapping(ts_node_child_by_field_name(pp, "value", CBM_SZ_5));
224 uint32_t nm = ts_node_is_null(item) ? 0 : ts_node_named_child_count(item);
225 for (uint32_t j = 0; j < nm; j++) {
226 TSNode mp = ts_node_named_child(item, j);
227 if (!oa_pair(mp) ||
228 !oa_scalar(ctx, ts_node_child_by_field_name(mp, "key", CBM_SZ_3), key,
229 sizeof(key)) ||
230 !oa_method(key)) {
231 continue;
232 }
233 TSNode op = oa_mapping(ts_node_child_by_field_name(mp, "value", CBM_SZ_5));
234 if (!ts_node_is_null(op)) {
235 oa_operation(ctx, path, key, op, item, mp);
236 }
237 }
238 }
239}

Callers 1

extract_file_ex_bodyFunction · 0.85

Calls 6

oa_mappingFunction · 0.85
oa_getFunction · 0.85
oa_pairFunction · 0.85
oa_scalarFunction · 0.85
oa_methodFunction · 0.85
oa_operationFunction · 0.85

Tested by

no test coverage detected