Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 'use client'; /** * Endpoint Detail View * Displays full documentation for an API endpoint */ import React from 'react'; import { ApiEndpoint, ApiParameter, ApiBodyField, ApiResponseSchema } from '@/types/api-docs'; import { getMethodColor } from '@/lib/api-docs/executor'; import { Icon } from '@/components/ui/icons'; interface EndpointDetailProps { endpoint: ApiEndpoint; onTest: () => void; } export default function EndpointDetail({ endpoint, onTest }: EndpointDetailProps) { return ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden"> {/* Header */} <div className="p-6 border-b border-gray-200 dark:border-gray-700"> <div className="flex items-start justify-between"> <div> <div className="flex items-center gap-3 mb-2"> <span className={`text-sm font-mono font-bold px-2 py-1 rounded ${getMethodColor( endpoint.method )}`} > {endpoint.method} </span> <code className="text-lg font-mono text-gray-800 dark:text-gray-200">{endpoint.path}</code> </div> <h2 className="text-xl font-semibold text-gray-900 dark:text-gray-100">{endpoint.summary}</h2> {endpoint.description && ( <p className="text-gray-600 dark:text-gray-400 mt-2">{endpoint.description}</p> )} </div> <button onClick={onTest} className="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors flex items-center gap-2" > <Icon name="bolt" size={16} /> Try it out </button> </div> {/* Tags */} <div className="flex items-center gap-2 mt-4"> {endpoint.requiresAuth && ( <span className="inline-flex items-center gap-1 px-2 py-1 bg-amber-100 dark:bg-amber-900/50 text-amber-800 dark:text-amber-300 text-xs rounded"> <Icon name="lock-closed" size={12} /> Requires Auth </span> )} {endpoint.adminOnly && ( <span className="inline-flex items-center gap-1 px-2 py-1 bg-red-100 dark:bg-red-900/50 text-red-800 dark:text-red-300 text-xs rounded"> <Icon name="shield-check" size={12} /> Admin Only </span> )} {endpoint.tags?.map((tag) => ( <span key={tag} className="px-2 py-1 bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 text-xs rounded" > {tag} </span> ))} </div> </div> {/* Parameters */} {endpoint.parameters && endpoint.parameters.length > 0 && ( <div className="p-6 border-b border-gray-200 dark:border-gray-700"> <h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Parameters</h3> <ParametersTable parameters={endpoint.parameters} /> </div> )} {/* Request Body */} {endpoint.requestBody && ( <div className="p-6 border-b border-gray-200 dark:border-gray-700"> <h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Request Body</h3> <div className="mb-2 text-sm text-gray-600 dark:text-gray-400"> Content-Type: <code className="bg-gray-100 dark:bg-gray-700 px-1 rounded">{endpoint.requestBody.contentType}</code> </div> {endpoint.requestBody.description && ( <p className="text-gray-600 dark:text-gray-400 mb-4">{endpoint.requestBody.description}</p> )} <BodyFieldsTable fields={endpoint.requestBody.fields} /> {endpoint.requestBody.example && ( <div className="mt-4"> <h4 className="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Example</h4> <pre className="bg-gray-900 text-gray-100 p-4 rounded-lg overflow-x-auto text-sm"> {JSON.stringify(endpoint.requestBody.example, null, 2)} </pre> </div> )} </div> )} {/* Responses */} <div className="p-6"> <h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Responses</h3> <div className="space-y-4"> {endpoint.responses.map((response, index) => ( <ResponseCard key={index} response={response} /> ))} </div> </div> </div> ); } function ParametersTable({ parameters }: { parameters: ApiParameter[] }) { return ( <div className="overflow-x-auto"> <table className="w-full text-sm"> <thead> <tr className="border-b border-gray-200 dark:border-gray-700"> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Name</th> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Location</th> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Type</th> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Required</th> <th className="text-left py-2 font-medium text-gray-700 dark:text-gray-300">Description</th> </tr> </thead> <tbody> {parameters.map((param) => ( <tr key={param.name} className="border-b border-gray-100 dark:border-gray-700/50"> <td className="py-3 pr-4"> <code className="text-indigo-600 dark:text-indigo-400 font-mono">{param.name}</code> </td> <td className="py-3 pr-4"> <span className="px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400 rounded text-xs"> {param.location} </span> </td> <td className="py-3 pr-4"> <span className="text-gray-600 dark:text-gray-400">{param.type}</span> {param.enum && ( <div className="text-xs text-gray-500 dark:text-gray-500 mt-1"> enum: {param.enum.join(' | ')} </div> )} </td> <td className="py-3 pr-4"> {param.required ? ( <span className="text-red-600 dark:text-red-400 font-medium">Yes</span> ) : ( <span className="text-gray-400 dark:text-gray-500">No</span> )} </td> <td className="py-3"> <span className="text-gray-600 dark:text-gray-400">{param.description}</span> {param.example !== undefined && ( <div className="text-xs text-gray-500 dark:text-gray-500 mt-1"> Example: <code className="bg-gray-100 dark:bg-gray-700 px-1 rounded">{String(param.example)}</code> </div> )} </td> </tr> ))} </tbody> </table> </div> ); } function BodyFieldsTable({ fields }: { fields: ApiBodyField[] }) { return ( <div className="overflow-x-auto"> <table className="w-full text-sm"> <thead> <tr className="border-b border-gray-200 dark:border-gray-700"> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Field</th> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Type</th> <th className="text-left py-2 pr-4 font-medium text-gray-700 dark:text-gray-300">Required</th> <th className="text-left py-2 font-medium text-gray-700 dark:text-gray-300">Description</th> </tr> </thead> <tbody> {fields.map((field) => ( <tr key={field.name} className="border-b border-gray-100 dark:border-gray-700/50"> <td className="py-3 pr-4"> <code className="text-indigo-600 dark:text-indigo-400 font-mono">{field.name}</code> </td> <td className="py-3 pr-4"> <span className="text-gray-600 dark:text-gray-400">{field.type}</span> {field.enum && ( <div className="text-xs text-gray-500 dark:text-gray-500 mt-1"> enum: {field.enum.join(' | ')} </div> )} </td> <td className="py-3 pr-4"> {field.required ? ( <span className="text-red-600 dark:text-red-400 font-medium">Yes</span> ) : ( <span className="text-gray-400 dark:text-gray-500">No</span> )} </td> <td className="py-3"> <span className="text-gray-600 dark:text-gray-400">{field.description}</span> </td> </tr> ))} </tbody> </table> </div> ); } function ResponseCard({ response }: { response: ApiResponseSchema }) { const statusColor = response.status >= 200 && response.status < 300 ? 'bg-green-100 dark:bg-green-900/50 text-green-800 dark:text-green-300' : response.status >= 400 ? 'bg-red-100 dark:bg-red-900/50 text-red-800 dark:text-red-300' : 'bg-yellow-100 dark:bg-yellow-900/50 text-yellow-800 dark:text-yellow-300'; return ( <div className="border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden"> <div className="flex items-center gap-3 px-4 py-3 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-700"> <span className={`px-2 py-0.5 rounded text-sm font-mono font-bold ${statusColor}`}> {response.status} </span> <span className="text-gray-700 dark:text-gray-300">{response.description}</span> </div> {response.example !== undefined && ( <pre className="bg-gray-900 text-gray-100 p-4 overflow-x-auto text-sm m-0"> {String(JSON.stringify(response.example, null, 2))} </pre> )} </div> ); } |