43/**
44* Extract security scheme names from operation security
45* @param security - Security requirements from OpenAPI operation
46* @returns Array of security scheme names
47*/
56/**
57* Check if operation requires authentication
58* @param security - Security requirements from OpenAPI operation
59* @returns True if authentication is required
60*/
70/**
71* Get security summary for an operation
72* @param security - Security requirements from OpenAPI operation
73* @returns Security summary object
74*/
1/**
2* F:\zApps\valtown.servers\APIServer\src\utils\jwt.helpers.ts
3* Shared utility functions for JWT generation and verification using 'jose'.
4*/
api_ianmenethil_comindex.ts1 match
1// F:\zApps\valtown.servers\APIServer\src\types\index.ts
2/**
3* Central export file for all types
8990getDescription(): string {
91return "Converts Swagger/OpenAPI specifications to Postman collections";
92}
93
1// F:\zApps\valtown.servers\APIServer\src\services\internalJWT.service.ts
2import { Context } from "hono";
3import { joseErrors, signJwt, verifyJwt } from "@/utils/jwtUtils.ts";
15*
16* This service provides:
17* - JWT token generation for internal API calls (using jose via jwt.helpers)
18* - Token validation and verification (using jose via jwt.helpers)
19* - Request correlation and audit trails
api_ianmenethil_comcacheService.ts2 matches
1/**
2F:\zApps\valtown.servers\APIServer\src\services\cache.service.ts
3* cache-service.ts ā Enhanced caching service for the secure API server.
4* Supports multiple storage backends: Val.town Blob, Val.town SQL, and in-memory.
5*/
api_ianmenethil_comrouteLogger.ts12 matches
1/**
2* F:\zApps\valtown.servers\APIServer\src\openapi\route.logger.ts
3* Handles formatted console output of registered routes grouped by security type.
4*/
11} from "../utils/tableFormatter.ts";
12import { extractSecuritySchemes, getMiddlewareGroup } from "../utils/middlewareMapper.ts";
13import { convertOpenApiPathToHono } from "./pathUtils.ts";
1415// Basic OpenAPI types for logging functionality
16interface OpenAPIOperation {
17operationId?: string;
18security?: Array<Record<string, string[]>>;
19}
2021interface OpenAPIPath {
22[method: string]: OpenAPIOperation;
23}
2425interface OpenAPISpec {
26paths: Record<string, OpenAPIPath>;
27}
2829/**
30* Logs all registered routes in a formatted table grouped by security type
31* @param spec - The OpenAPI specification containing route definitions
32* @param middlewareGroups - Registry of middleware groups for each security type
33*/
34export function logAllRoutes(
35spec: OpenAPISpec,
36middlewareGroups: Record<string, Array<unknown>>,
37): void {
56// Categorize routes by security group
57for (const [path, pathSpec] of Object.entries(spec.paths)) {
58for (const [method, operation] of Object.entries(pathSpec as OpenAPIPath)) {
59if (
60!["get", "post", "put", "delete", "patch"].includes(
6667const middlewareGroup = getMiddlewareGroup(operation.security);
68const honoPath = convertOpenApiPathToHono(path);
69const securitySchemes = extractSecuritySchemes(operation.security);
70
api_ianmenethil_comrouteGenerator.ts15 matches
1/**
2* route-generator.ts ā OpenAPI route generation and management.
3* Generates Hono routes from OpenAPI specifications with full service integration.
4*/
56import { Context, Hono, MiddlewareHandler } from "hono";
7import { HTTPException } from "hono/http-exception";
8import { loadOpenAPISpec } from "./loader.ts";
9import { convertOpenApiPathToHono } from "./pathUtils.ts";
10import { createServiceRouter, getServiceHandler } from "../core/serviceRegistry.ts";
11import { HandlerResolver } from "../core/controllerRegistry.ts";
30type SecurityRequirement = Record<string, string[]>;
3132export class OpenAPIRouteGenerator {
33private spec: any;
34private app: Hono<{ Variables: Variables }>;
4142async loadAndGenerateRoutes(specPath: string) {
43this.spec = await loadOpenAPISpec(specPath);
44this.serviceRouter = await createServiceRouter();
45const routes = this.extractRoutes();
47this.registerRoute(route);
48}
49console.log(`ā Generated ${routes.length} routes from OpenAPI spec`);
50return routes;
51}
54const routes: RouteInfo[] = [];
55if (!this.spec?.paths) {
56console.warn("[OpenAPIRouteGenerator] No paths found in OpenAPI spec");
57return routes;
58}
69const operationObj = operation as any;
70routes.push({
71path: convertOpenApiPathToHono(path),
72method: method.toLowerCase(), // Ensure method is lowercase for Hono registration
73operationId: operationObj.operationId ||
203} else {
204console.warn(
205`[OpenAPIRouteGenerator] Invalid or unsupported HTTP method: ${route.method} for path ${route.path}`,
206);
207}
251252printRouteSummary(routes: RouteInfo[]) {
253console.log("\nš ===== OPENAPI ROUTE SUMMARY =====");
254console.log(`š£ļø Generated Routes (${routes.length} total):`);
255console.log(
350const descriptions: Record<string, string> = {};
351if (!this.spec?.components?.securitySchemes) {
352console.warn("[OpenAPIRouteGenerator] No security schemes found in OpenAPI spec");
353return descriptions;
354}
358const scheme = schemeDefinition as any;
359let description = scheme.description || "No description available";
360if (scheme.type === "apiKey") {
361const location = scheme.in === "header"
362? `Header: ${scheme.name}`
385}
386387export async function generateRoutesFromOpenAPI(
388app: Hono<{ Variables: Variables }>,
389specPath: string,
390) {
391const generator = new OpenAPIRouteGenerator(app);
392const routes = await generator.loadAndGenerateRoutes(specPath);
393generator.printRouteSummary(routes);
api_ianmenethil_comloader.ts12 matches
1// F:\zApps\valtown.servers\APIServer\src\openapi\openapi.loader.ts
2import { resolve } from "path";
3import { parse } from "yaml";
45interface OpenAPIDocument {
6openapi: string;
7info: any;
8servers: any[];
11}
1213export class OpenAPILoader {
14private cache: Map<string, any> = new Map();
15private rootPath: string;
19}
2021async loadSpec(): Promise<OpenAPIDocument> {
22const mainSpec = await this.loadYamlFile("openapi.yaml");
23const resolvedSpec = await this.resolveReferences(mainSpec, "openapi.yaml");
24console.log(
25`OpenAPI specification loaded and references resolved. Total references: ${this.cache.size} -- Total paths: ${
26Object.keys(resolvedSpec.paths || {}).length
27}`,
28);
29return resolvedSpec as OpenAPIDocument;
30}
31107}
108109// Export a function to load the OpenAPI spec
110export async function loadOpenAPISpec(rootPath: string): Promise<OpenAPIDocument> {
111const loader = new OpenAPILoader(rootPath);
112return await loader.loadSpec();
113}
api_ianmenethil_compathUtils.ts10 matches
1/**
2F:\zApps\valtown.servers\APIServer\src\openapi\openapi.path.helper.ts
3* Handles conversion between OpenAPI and Hono path formats.
4*/
578/**
9* Convert OpenAPI path format to Hono path format
10* {id} -> :id
11*/
12export function convertOpenApiPathToHono(openApiPath: string): string {
13return openApiPath.replace(/\{([^}]+)\}/g, ":$1");
14}
1516/**
17* Convert Hono path format to OpenAPI path format
18* :id -> {id}
19*/
20export function convertHonoPathToOpenApi(honoPath: string): string {
21return honoPath.replace(/:([^/]+)/g, "{$1}");
22}
2324/**
25* Extract parameters from OpenAPI path
26*/
27export function extractOpenApiParams(
28pathTemplate: string,
29actualPath: string,
30): Record<string, string> | null {
31const honoPath = convertOpenApiPathToHono(pathTemplate);
32const match = matchPath(honoPath, actualPath);
33return match ? match.params : null;