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

Function extractFlaskRestful

src/resolution/frameworks/python.ts:503–540  ·  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

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

Callers 1

extractFunction · 0.85

Calls 3

mapMethod · 0.80
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected