File size: 7,942 Bytes
2fe81ea 60d8dca 65b0171 60d8dca ef85da9 2fe81ea 65b0171 ef85da9 65b0171 ef85da9 65b0171 ef85da9 65b0171 2fe81ea 60d8dca 2fe81ea ef85da9 497daee f5035b9 ef85da9 2fe81ea 60d8dca 2fe81ea 65b0171 78299b3 65b0171 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
import swaggerJSDoc from 'swagger-jsdoc';
import path from 'path';
import fs from 'fs';
// Swagger JSDoc needs the source TypeScript files (not compiled JS) to read JSDoc comments
// When running from dist/, we need to look for src/ at the project root
// When running from src/, we use relative path
// Check if we're running from dist (compiled) or src (development)
const isRunningFromDist = __dirname.includes('dist');
const projectRoot = isRunningFromDist
? path.resolve(__dirname, '../..') // Go up from dist/docs to project root
: path.resolve(__dirname, '..'); // Go up from src/docs to project root
// Always use source TypeScript files from src/routes
const routesPath = path.join(projectRoot, 'src/routes/*.ts');
console.log(`π Swagger looking for routes at: ${routesPath}`);
console.log(`π Running from: ${isRunningFromDist ? 'dist' : 'src'}`);
console.log(`π Project root: ${projectRoot}`);
// Check if route files exist (for debugging)
try {
const routesDir = path.join(projectRoot, 'src/routes');
if (fs.existsSync(routesDir)) {
const files = fs.readdirSync(routesDir);
console.log(`π Found ${files.length} route files in ${routesDir}`);
const tsFiles = files.filter(f => f.endsWith('.ts'));
console.log(`π TypeScript route files: ${tsFiles.length}`);
} else {
console.warn(`β οΈ Routes directory not found: ${routesDir}`);
}
// Also check if the glob pattern resolves correctly
const testPattern = path.join(projectRoot, 'src/routes/*.ts');
console.log(`π Using pattern: ${testPattern}`);
} catch (error) {
console.warn('β οΈ Could not check routes directory:', error);
}
export const swaggerSpec = swaggerJSDoc({
definition: {
openapi: '3.0.0',
info: {
title: 'Zurri API',
version: '1.0.0',
description: 'Zurri Agents Marketplace API with Wallet Point System',
},
servers: [
{
url: process.env.API_BASE_URL || '/api',
description: 'API Server'
},
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
schemas: {
Agent: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'uuid',
},
name: {
type: 'string',
example: 'PixelPainter',
},
description: {
type: 'string',
example: 'I turn prompts into AI art!',
},
endpoint: {
type: 'string',
format: 'uri',
example: 'https://api.pixelpainter.ai/run',
},
avatar: {
type: 'string',
format: 'uri',
nullable: true,
description: 'IPFS gateway URL for avatar image',
},
category: {
type: 'string',
example: 'image generation',
},
reputation: {
type: 'number',
format: 'float',
example: 4.8,
},
capabilities: {
type: 'array',
items: {
type: 'string',
},
example: ['text-to-image', 'image-editing'],
},
pointsPerTask: {
type: 'number',
format: 'float',
example: 10,
},
status: {
type: 'string',
enum: ['pending', 'approved', 'rejected', 'suspended'],
},
usageCount: {
type: 'integer',
example: 0,
},
rating: {
type: 'number',
format: 'float',
nullable: true,
},
ratingCount: {
type: 'integer',
example: 0,
},
creatorId: {
type: 'string',
format: 'uuid',
},
createdAt: {
type: 'string',
format: 'date-time',
},
updatedAt: {
type: 'string',
format: 'date-time',
},
},
},
ChatMessage: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'uuid',
},
role: {
type: 'string',
enum: ['user', 'assistant', 'system'],
description: 'Message role (user = user message, assistant = agent response, system = system message)',
},
content: {
type: 'string',
description: 'Message content',
},
agentId: {
type: 'string',
format: 'uuid',
},
userId: {
type: 'string',
format: 'uuid',
nullable: true,
},
conversationId: {
type: 'string',
nullable: true,
description: 'Conversation ID this message belongs to',
},
metadata: {
type: 'object',
description: 'Additional message metadata (files, IPFS hashes, etc.)',
additionalProperties: true,
},
createdAt: {
type: 'string',
format: 'date-time',
},
},
},
ChatResponse: {
type: 'object',
properties: {
response: {
type: 'string',
description: 'Agent\'s response message',
},
conversationId: {
type: 'string',
description: 'Conversation ID for this chat session',
},
metadata: {
type: 'object',
description: 'Additional response metadata from agent',
additionalProperties: true,
},
},
},
User: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'uuid',
description: 'User ID',
},
email: {
type: 'string',
format: 'email',
description: 'User email address',
},
name: {
type: 'string',
nullable: true,
description: 'User display name',
},
isAdmin: {
type: 'boolean',
default: false,
description: 'Whether user has admin privileges',
},
isCreator: {
type: 'boolean',
default: false,
description: 'Whether user can create and manage agents',
},
isActive: {
type: 'boolean',
default: true,
description: 'Whether user account is active',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'Account creation timestamp',
},
updatedAt: {
type: 'string',
format: 'date-time',
description: 'Last update timestamp',
},
},
},
},
},
security: [{ bearerAuth: [] }],
},
apis: [routesPath],
});
// Log Swagger spec generation
try {
const spec = swaggerSpec as any; // Type assertion for logging
const paths = spec.paths ? Object.keys(spec.paths) : [];
console.log(`π Swagger spec generated with ${paths.length} endpoints`);
if (paths.length === 0) {
console.warn('β οΈ No endpoints found in Swagger spec. Check route files.');
}
} catch (error) {
console.error('β Error generating Swagger spec:', error);
}
|