MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractFlaskRestful

Function extractFlaskRestful

src/resolution/frameworks/python.ts:504–541  ·  view source on GitHub ↗

* Flask-RESTful: `api.add_resource(ResourceClass, '/path'[, '/path2'])` * (and variants like redash's `add_org_resource`). The ResourceClass holds the * HTTP-verb methods (get/post/…), so the route references the class — its verb * methods resolve as the handlers via the class. Method is ANY (the

(filePath: string, safe: string)

Source from the content-addressed store, hash-verified

502 * decides which verbs it serves).
503 */
504function extractFlaskRestful(filePath: string, safe: string): FrameworkExtractionResult {
505 const nodes: Node[] = [];
506 const references: UnresolvedRef[] = [];
507 const now = Date.now();
508 const re = /\.add\w*[Rr]esource\s*\(\s*(\w+)\s*,\s*((?:['"][^'"]+['"]\s*,?\s*)+)/g;
509 let m: RegExpExecArray | null;
510 while ((m = re.exec(safe)) !== null) {
511 const className = m[1]!;
512 const paths = (m[2]!.match(/['"]([^'"]+)['"]/g) || []).map((s) => s.slice(1, -1));
513 const line = lineAt(safe, m.index);
514 for (const routePath of paths) {
515 const routeNode: Node = {
516 id: `route:${filePath}:${line}:ANY:${routePath}`,
517 kind: 'route',
518 name: `ANY ${routePath}`,
519 qualifiedName: `${filePath}::ANY:${routePath}`,
520 filePath,
521 startLine: line,
522 endLine: line,
523 startColumn: 0,
524 endColumn: 0,
525 language: 'python',
526 updatedAt: now,
527 };
528 nodes.push(routeNode);
529 references.push({
530 fromNodeId: routeNode.id,
531 referenceName: className,
532 referenceKind: 'references',
533 line,
534 column: 0,
535 filePath,
536 language: 'python',
537 });
538 }
539 }
540 return { nodes, references };
541}
542
543/**
544 * Flask's imperative registration: `bp.add_url_rule('/path', 'name',

Callers 1

extractFunction · 0.85

Calls 4

lineAtFunction · 0.90
mapMethod · 0.80
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected