javi-forge 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/ci-local/ci-local.sh +20 -8
  2. package/package.json +1 -1
  3. package/ai-config/.skillignore +0 -15
  4. package/ai-config/AUTO_INVOKE.md +0 -300
  5. package/ai-config/agents/_TEMPLATE.md +0 -93
  6. package/ai-config/agents/business/api-designer.md +0 -1657
  7. package/ai-config/agents/business/business-analyst.md +0 -1331
  8. package/ai-config/agents/business/product-strategist.md +0 -206
  9. package/ai-config/agents/business/project-manager.md +0 -178
  10. package/ai-config/agents/business/requirements-analyst.md +0 -1277
  11. package/ai-config/agents/business/technical-writer.md +0 -1679
  12. package/ai-config/agents/creative/ux-designer.md +0 -205
  13. package/ai-config/agents/data-ai/ai-engineer.md +0 -487
  14. package/ai-config/agents/data-ai/analytics-engineer.md +0 -953
  15. package/ai-config/agents/data-ai/data-engineer.md +0 -173
  16. package/ai-config/agents/data-ai/data-scientist.md +0 -672
  17. package/ai-config/agents/data-ai/mlops-engineer.md +0 -814
  18. package/ai-config/agents/data-ai/prompt-engineer.md +0 -772
  19. package/ai-config/agents/development/angular-expert.md +0 -620
  20. package/ai-config/agents/development/backend-architect.md +0 -795
  21. package/ai-config/agents/development/database-specialist.md +0 -212
  22. package/ai-config/agents/development/frontend-specialist.md +0 -686
  23. package/ai-config/agents/development/fullstack-engineer.md +0 -668
  24. package/ai-config/agents/development/golang-pro.md +0 -338
  25. package/ai-config/agents/development/java-enterprise.md +0 -400
  26. package/ai-config/agents/development/javascript-pro.md +0 -422
  27. package/ai-config/agents/development/nextjs-pro.md +0 -474
  28. package/ai-config/agents/development/python-pro.md +0 -570
  29. package/ai-config/agents/development/react-pro.md +0 -487
  30. package/ai-config/agents/development/rust-pro.md +0 -246
  31. package/ai-config/agents/development/spring-boot-4-expert.md +0 -326
  32. package/ai-config/agents/development/typescript-pro.md +0 -336
  33. package/ai-config/agents/development/vue-specialist.md +0 -605
  34. package/ai-config/agents/infrastructure/cloud-architect.md +0 -472
  35. package/ai-config/agents/infrastructure/deployment-manager.md +0 -358
  36. package/ai-config/agents/infrastructure/devops-engineer.md +0 -455
  37. package/ai-config/agents/infrastructure/incident-responder.md +0 -519
  38. package/ai-config/agents/infrastructure/kubernetes-expert.md +0 -705
  39. package/ai-config/agents/infrastructure/monitoring-specialist.md +0 -674
  40. package/ai-config/agents/infrastructure/performance-engineer.md +0 -658
  41. package/ai-config/agents/orchestrator.md +0 -241
  42. package/ai-config/agents/quality/accessibility-auditor.md +0 -1204
  43. package/ai-config/agents/quality/code-reviewer-compact.md +0 -123
  44. package/ai-config/agents/quality/code-reviewer.md +0 -363
  45. package/ai-config/agents/quality/dependency-manager.md +0 -743
  46. package/ai-config/agents/quality/e2e-test-specialist.md +0 -1005
  47. package/ai-config/agents/quality/performance-tester.md +0 -1086
  48. package/ai-config/agents/quality/security-auditor.md +0 -133
  49. package/ai-config/agents/quality/test-engineer.md +0 -453
  50. package/ai-config/agents/specialists/api-designer.md +0 -87
  51. package/ai-config/agents/specialists/backend-architect.md +0 -73
  52. package/ai-config/agents/specialists/code-reviewer.md +0 -77
  53. package/ai-config/agents/specialists/db-optimizer.md +0 -75
  54. package/ai-config/agents/specialists/devops-engineer.md +0 -83
  55. package/ai-config/agents/specialists/documentation-writer.md +0 -78
  56. package/ai-config/agents/specialists/frontend-developer.md +0 -75
  57. package/ai-config/agents/specialists/performance-analyst.md +0 -82
  58. package/ai-config/agents/specialists/refactor-specialist.md +0 -74
  59. package/ai-config/agents/specialists/security-auditor.md +0 -74
  60. package/ai-config/agents/specialists/test-engineer.md +0 -81
  61. package/ai-config/agents/specialists/ux-consultant.md +0 -76
  62. package/ai-config/agents/specialized/agent-generator.md +0 -1190
  63. package/ai-config/agents/specialized/blockchain-developer.md +0 -149
  64. package/ai-config/agents/specialized/code-migrator.md +0 -892
  65. package/ai-config/agents/specialized/context-manager.md +0 -978
  66. package/ai-config/agents/specialized/documentation-writer.md +0 -1078
  67. package/ai-config/agents/specialized/ecommerce-expert.md +0 -1756
  68. package/ai-config/agents/specialized/embedded-engineer.md +0 -1714
  69. package/ai-config/agents/specialized/error-detective.md +0 -1034
  70. package/ai-config/agents/specialized/fintech-specialist.md +0 -1659
  71. package/ai-config/agents/specialized/freelance-project-planner-v2.md +0 -1988
  72. package/ai-config/agents/specialized/freelance-project-planner-v3.md +0 -2136
  73. package/ai-config/agents/specialized/freelance-project-planner-v4.md +0 -4503
  74. package/ai-config/agents/specialized/freelance-project-planner.md +0 -722
  75. package/ai-config/agents/specialized/game-developer.md +0 -1963
  76. package/ai-config/agents/specialized/healthcare-dev.md +0 -1620
  77. package/ai-config/agents/specialized/mobile-developer.md +0 -188
  78. package/ai-config/agents/specialized/parallel-plan-executor.md +0 -506
  79. package/ai-config/agents/specialized/plan-executor.md +0 -485
  80. package/ai-config/agents/specialized/solo-dev-planner-modular/00-INDEX.md +0 -485
  81. package/ai-config/agents/specialized/solo-dev-planner-modular/01-CORE.md +0 -3493
  82. package/ai-config/agents/specialized/solo-dev-planner-modular/02-SELF-CORRECTION.md +0 -778
  83. package/ai-config/agents/specialized/solo-dev-planner-modular/03-PROGRESSIVE-SETUP.md +0 -918
  84. package/ai-config/agents/specialized/solo-dev-planner-modular/04-DEPLOYMENT.md +0 -1537
  85. package/ai-config/agents/specialized/solo-dev-planner-modular/05-TESTING.md +0 -2633
  86. package/ai-config/agents/specialized/solo-dev-planner-modular/06-OPERATIONS.md +0 -5610
  87. package/ai-config/agents/specialized/solo-dev-planner-modular/INSTALL.md +0 -335
  88. package/ai-config/agents/specialized/solo-dev-planner-modular/QUICK-REFERENCE.txt +0 -215
  89. package/ai-config/agents/specialized/solo-dev-planner-modular/README.md +0 -260
  90. package/ai-config/agents/specialized/solo-dev-planner-modular/START-HERE.md +0 -379
  91. package/ai-config/agents/specialized/solo-dev-planner-modular/WORKFLOW-DIAGRAM.md +0 -355
  92. package/ai-config/agents/specialized/solo-dev-planner-modular/solo-dev-planner.md +0 -279
  93. package/ai-config/agents/specialized/template-writer.md +0 -347
  94. package/ai-config/agents/specialized/test-runner.md +0 -99
  95. package/ai-config/agents/specialized/vibekanban-smart-worker.md +0 -244
  96. package/ai-config/agents/specialized/wave-executor.md +0 -138
  97. package/ai-config/agents/specialized/workflow-optimizer.md +0 -1114
  98. package/ai-config/commands/git/changelog.md +0 -32
  99. package/ai-config/commands/git/ci-local.md +0 -70
  100. package/ai-config/commands/git/commit.md +0 -35
  101. package/ai-config/commands/git/fix-issue.md +0 -23
  102. package/ai-config/commands/git/pr-create.md +0 -42
  103. package/ai-config/commands/git/pr-review.md +0 -50
  104. package/ai-config/commands/git/worktree.md +0 -39
  105. package/ai-config/commands/refactoring/cleanup.md +0 -24
  106. package/ai-config/commands/refactoring/dead-code.md +0 -40
  107. package/ai-config/commands/refactoring/extract.md +0 -31
  108. package/ai-config/commands/testing/e2e.md +0 -30
  109. package/ai-config/commands/testing/tdd.md +0 -36
  110. package/ai-config/commands/testing/test-coverage.md +0 -30
  111. package/ai-config/commands/testing/test-fix.md +0 -24
  112. package/ai-config/commands/workflow/generate-agents-md.md +0 -85
  113. package/ai-config/commands/workflow/planning.md +0 -47
  114. package/ai-config/commands/workflows/compound.md +0 -89
  115. package/ai-config/commands/workflows/diagnose.md +0 -70
  116. package/ai-config/commands/workflows/discover.md +0 -86
  117. package/ai-config/commands/workflows/plan.md +0 -77
  118. package/ai-config/commands/workflows/review.md +0 -78
  119. package/ai-config/commands/workflows/work.md +0 -75
  120. package/ai-config/config.yaml +0 -18
  121. package/ai-config/hooks/_TEMPLATE.md +0 -96
  122. package/ai-config/hooks/block-dangerous-commands.md +0 -75
  123. package/ai-config/hooks/commit-guard.md +0 -90
  124. package/ai-config/hooks/context-loader.md +0 -73
  125. package/ai-config/hooks/improve-prompt.md +0 -91
  126. package/ai-config/hooks/learning-log.md +0 -72
  127. package/ai-config/hooks/model-router.md +0 -86
  128. package/ai-config/hooks/secret-scanner.md +0 -64
  129. package/ai-config/hooks/skill-validator.md +0 -102
  130. package/ai-config/hooks/task-artifact.md +0 -114
  131. package/ai-config/hooks/validate-workflow.md +0 -100
  132. package/ai-config/prompts/base.md +0 -71
  133. package/ai-config/prompts/modes/debug.md +0 -34
  134. package/ai-config/prompts/modes/deploy.md +0 -40
  135. package/ai-config/prompts/modes/research.md +0 -32
  136. package/ai-config/prompts/modes/review.md +0 -33
  137. package/ai-config/prompts/review-policy.md +0 -79
  138. package/ai-config/skills/_TEMPLATE.md +0 -157
  139. package/ai-config/skills/backend/api-gateway/SKILL.md +0 -254
  140. package/ai-config/skills/backend/bff-concepts/SKILL.md +0 -239
  141. package/ai-config/skills/backend/bff-spring/SKILL.md +0 -364
  142. package/ai-config/skills/backend/chi-router/SKILL.md +0 -396
  143. package/ai-config/skills/backend/error-handling/SKILL.md +0 -255
  144. package/ai-config/skills/backend/exceptions-spring/SKILL.md +0 -323
  145. package/ai-config/skills/backend/fastapi/SKILL.md +0 -302
  146. package/ai-config/skills/backend/gateway-spring/SKILL.md +0 -390
  147. package/ai-config/skills/backend/go-backend/SKILL.md +0 -457
  148. package/ai-config/skills/backend/gradle-multimodule/SKILL.md +0 -274
  149. package/ai-config/skills/backend/graphql-concepts/SKILL.md +0 -352
  150. package/ai-config/skills/backend/graphql-spring/SKILL.md +0 -398
  151. package/ai-config/skills/backend/grpc-concepts/SKILL.md +0 -283
  152. package/ai-config/skills/backend/grpc-spring/SKILL.md +0 -445
  153. package/ai-config/skills/backend/jwt-auth/SKILL.md +0 -412
  154. package/ai-config/skills/backend/notifications-concepts/SKILL.md +0 -259
  155. package/ai-config/skills/backend/recommendations-concepts/SKILL.md +0 -261
  156. package/ai-config/skills/backend/search-concepts/SKILL.md +0 -263
  157. package/ai-config/skills/backend/search-spring/SKILL.md +0 -375
  158. package/ai-config/skills/backend/spring-boot-4/SKILL.md +0 -172
  159. package/ai-config/skills/backend/websockets/SKILL.md +0 -532
  160. package/ai-config/skills/data-ai/ai-ml/SKILL.md +0 -423
  161. package/ai-config/skills/data-ai/analytics-concepts/SKILL.md +0 -195
  162. package/ai-config/skills/data-ai/analytics-spring/SKILL.md +0 -340
  163. package/ai-config/skills/data-ai/duckdb-analytics/SKILL.md +0 -440
  164. package/ai-config/skills/data-ai/langchain/SKILL.md +0 -238
  165. package/ai-config/skills/data-ai/mlflow/SKILL.md +0 -302
  166. package/ai-config/skills/data-ai/onnx-inference/SKILL.md +0 -290
  167. package/ai-config/skills/data-ai/powerbi/SKILL.md +0 -352
  168. package/ai-config/skills/data-ai/pytorch/SKILL.md +0 -274
  169. package/ai-config/skills/data-ai/scikit-learn/SKILL.md +0 -321
  170. package/ai-config/skills/data-ai/vector-db/SKILL.md +0 -301
  171. package/ai-config/skills/database/graph-databases/SKILL.md +0 -218
  172. package/ai-config/skills/database/graph-spring/SKILL.md +0 -361
  173. package/ai-config/skills/database/pgx-postgres/SKILL.md +0 -512
  174. package/ai-config/skills/database/redis-cache/SKILL.md +0 -343
  175. package/ai-config/skills/database/sqlite-embedded/SKILL.md +0 -388
  176. package/ai-config/skills/database/timescaledb/SKILL.md +0 -320
  177. package/ai-config/skills/docs/api-documentation/SKILL.md +0 -293
  178. package/ai-config/skills/docs/docs-spring/SKILL.md +0 -377
  179. package/ai-config/skills/docs/mustache-templates/SKILL.md +0 -190
  180. package/ai-config/skills/docs/technical-docs/SKILL.md +0 -447
  181. package/ai-config/skills/frontend/astro-ssr/SKILL.md +0 -441
  182. package/ai-config/skills/frontend/frontend-design/SKILL.md +0 -54
  183. package/ai-config/skills/frontend/frontend-web/SKILL.md +0 -368
  184. package/ai-config/skills/frontend/mantine-ui/SKILL.md +0 -396
  185. package/ai-config/skills/frontend/tanstack-query/SKILL.md +0 -439
  186. package/ai-config/skills/frontend/zod-validation/SKILL.md +0 -417
  187. package/ai-config/skills/frontend/zustand-state/SKILL.md +0 -350
  188. package/ai-config/skills/infrastructure/chaos-engineering/SKILL.md +0 -244
  189. package/ai-config/skills/infrastructure/chaos-spring/SKILL.md +0 -378
  190. package/ai-config/skills/infrastructure/devops-infra/SKILL.md +0 -435
  191. package/ai-config/skills/infrastructure/docker-containers/SKILL.md +0 -420
  192. package/ai-config/skills/infrastructure/kubernetes/SKILL.md +0 -456
  193. package/ai-config/skills/infrastructure/opentelemetry/SKILL.md +0 -546
  194. package/ai-config/skills/infrastructure/traefik-proxy/SKILL.md +0 -474
  195. package/ai-config/skills/infrastructure/woodpecker-ci/SKILL.md +0 -315
  196. package/ai-config/skills/mobile/ionic-capacitor/SKILL.md +0 -504
  197. package/ai-config/skills/mobile/mobile-ionic/SKILL.md +0 -448
  198. package/ai-config/skills/prompt-improver/SKILL.md +0 -125
  199. package/ai-config/skills/quality/ghagga-review/SKILL.md +0 -216
  200. package/ai-config/skills/references/hooks-patterns/SKILL.md +0 -238
  201. package/ai-config/skills/references/mcp-servers/SKILL.md +0 -275
  202. package/ai-config/skills/references/plugins-reference/SKILL.md +0 -110
  203. package/ai-config/skills/references/skills-reference/SKILL.md +0 -420
  204. package/ai-config/skills/references/subagent-templates/SKILL.md +0 -193
  205. package/ai-config/skills/systems-iot/modbus-protocol/SKILL.md +0 -410
  206. package/ai-config/skills/systems-iot/mqtt-rumqttc/SKILL.md +0 -408
  207. package/ai-config/skills/systems-iot/rust-systems/SKILL.md +0 -386
  208. package/ai-config/skills/systems-iot/tokio-async/SKILL.md +0 -324
  209. package/ai-config/skills/testing/playwright-e2e/SKILL.md +0 -289
  210. package/ai-config/skills/testing/testcontainers/SKILL.md +0 -299
  211. package/ai-config/skills/testing/vitest-testing/SKILL.md +0 -381
  212. package/ai-config/skills/workflow/ci-local-guide/SKILL.md +0 -118
  213. package/ai-config/skills/workflow/claude-automation-recommender/SKILL.md +0 -299
  214. package/ai-config/skills/workflow/claude-md-improver/SKILL.md +0 -158
  215. package/ai-config/skills/workflow/finishing-a-development-branch/SKILL.md +0 -117
  216. package/ai-config/skills/workflow/git-github/SKILL.md +0 -334
  217. package/ai-config/skills/workflow/git-github/references/examples.md +0 -160
  218. package/ai-config/skills/workflow/git-workflow/SKILL.md +0 -214
  219. package/ai-config/skills/workflow/ide-plugins/SKILL.md +0 -277
  220. package/ai-config/skills/workflow/ide-plugins-intellij/SKILL.md +0 -401
  221. package/ai-config/skills/workflow/obsidian-brain-workflow/SKILL.md +0 -199
  222. package/ai-config/skills/workflow/using-git-worktrees/SKILL.md +0 -100
  223. package/ai-config/skills/workflow/verification-before-completion/SKILL.md +0 -73
  224. package/ai-config/skills/workflow/wave-workflow/SKILL.md +0 -178
  225. package/schemas/agent.schema.json +0 -34
  226. package/schemas/ai-config.schema.json +0 -28
  227. package/schemas/plugin.schema.json +0 -62
  228. package/schemas/skill.schema.json +0 -44
@@ -1,1657 +0,0 @@
1
- ---
2
- name: api-designer
3
- description: API design expert specializing in REST, GraphQL, OpenAPI specifications, and API-first development
4
- trigger: >
5
- api design, rest api, graphql, openapi, swagger, api specification, api-first,
6
- api versioning, api authentication, rate limiting, api documentation, endpoint design,
7
- resource modeling, http methods, api gateway, microservices api
8
- category: business
9
- color: purple
10
- tools: Write, Read, MultiEdit, Grep, Glob
11
- model: sonnet
12
- metadata:
13
- version: "2.0"
14
- updated: "2026-02"
15
- ---
16
-
17
- You are an API design specialist with expertise in RESTful services, GraphQL, OpenAPI/Swagger specifications, and API-first development methodologies.
18
-
19
- ## Core Expertise
20
- - RESTful API design and best practices
21
- - GraphQL schema design and optimization
22
- - OpenAPI/Swagger specification
23
- - API versioning and evolution
24
- - Authentication and authorization patterns
25
- - Rate limiting and throttling
26
- - API documentation and testing
27
- - Microservices architecture
28
-
29
- ## Technical Stack
30
- - **Specification**: OpenAPI 3.1, Swagger 2.0, AsyncAPI, GraphQL SDL
31
- - **Design Tools**: Stoplight Studio, Postman, Insomnia, SwaggerHub
32
- - **Documentation**: Redoc, Swagger UI, GraphQL Playground, Slate
33
- - **Testing**: Postman, Newman, Dredd, Pact, REST Assured
34
- - **Gateways**: Kong, Apigee, AWS API Gateway, Azure API Management
35
- - **Protocols**: REST, GraphQL, gRPC, WebSocket, Server-Sent Events
36
- - **Standards**: JSON:API, HAL, JSON-LD, OData
37
-
38
- ## API Design Framework
39
- ```typescript
40
- // api-designer.ts
41
- import * as yaml from 'js-yaml';
42
- import { OpenAPIV3 } from 'openapi-types';
43
- import { GraphQLSchema, buildSchema } from 'graphql';
44
- import { JSONSchema7 } from 'json-schema';
45
-
46
- interface APIDesign {
47
- id: string;
48
- name: string;
49
- version: string;
50
- type: APIType;
51
- specification: APISpecification;
52
- endpoints: Endpoint[];
53
- dataModels: DataModel[];
54
- authentication: AuthenticationScheme;
55
- authorization: AuthorizationModel;
56
- rateLimiting: RateLimitPolicy;
57
- versioning: VersioningStrategy;
58
- documentation: APIDocumentation;
59
- testing: TestStrategy;
60
- monitoring: MonitoringConfig;
61
- }
62
-
63
- interface Endpoint {
64
- id: string;
65
- path: string;
66
- method: HTTPMethod;
67
- operation: OperationObject;
68
- parameters: Parameter[];
69
- requestBody?: RequestBody;
70
- responses: ResponseObject[];
71
- security?: SecurityRequirement[];
72
- deprecated?: boolean;
73
- version?: string;
74
- }
75
-
76
- class APIDesigner {
77
- private specifications: Map<string, APISpecification> = new Map();
78
- private patterns: Map<string, DesignPattern> = new Map();
79
- private validator: SpecificationValidator;
80
- private generator: CodeGenerator;
81
-
82
- constructor() {
83
- this.validator = new SpecificationValidator();
84
- this.generator = new CodeGenerator();
85
- this.loadDesignPatterns();
86
- }
87
-
88
- async designRESTAPI(requirements: APIRequirements): Promise<OpenAPISpecification> {
89
- // Analyze requirements
90
- const analysis = await this.analyzeRequirements(requirements);
91
-
92
- // Design resource model
93
- const resources = this.designResources(analysis);
94
-
95
- // Design endpoints
96
- const endpoints = this.designEndpoints(resources, requirements);
97
-
98
- // Design data models
99
- const schemas = this.designSchemas(resources, requirements);
100
-
101
- // Design authentication
102
- const security = this.designSecurity(requirements);
103
-
104
- // Generate OpenAPI specification
105
- const spec = this.generateOpenAPISpec({
106
- info: this.generateAPIInfo(requirements),
107
- servers: this.generateServers(requirements),
108
- paths: this.generatePaths(endpoints),
109
- components: {
110
- schemas: schemas,
111
- securitySchemes: security,
112
- parameters: this.generateCommonParameters(),
113
- responses: this.generateCommonResponses(),
114
- requestBodies: this.generateCommonRequestBodies(),
115
- headers: this.generateCommonHeaders(),
116
- examples: this.generateExamples(endpoints),
117
- links: this.generateLinks(endpoints),
118
- callbacks: this.generateCallbacks(endpoints),
119
- },
120
- security: this.generateSecurityRequirements(security),
121
- tags: this.generateTags(resources),
122
- externalDocs: requirements.documentation,
123
- });
124
-
125
- // Validate specification
126
- await this.validator.validateOpenAPI(spec);
127
-
128
- // Apply best practices
129
- const optimized = this.applyBestPractices(spec);
130
-
131
- return optimized;
132
- }
133
-
134
- private designResources(analysis: RequirementAnalysis): Resource[] {
135
- const resources: Resource[] = [];
136
-
137
- for (const entity of analysis.entities) {
138
- const resource: Resource = {
139
- id: this.generateId('RES'),
140
- name: entity.name,
141
- plural: this.pluralize(entity.name),
142
- description: entity.description,
143
- attributes: this.mapAttributes(entity.properties),
144
- relationships: this.mapRelationships(entity.relationships),
145
- operations: this.determineOperations(entity),
146
- uri: this.generateURI(entity),
147
- subresources: [],
148
- };
149
-
150
- // Identify subresources
151
- resource.subresources = this.identifySubresources(entity, analysis.entities);
152
-
153
- resources.push(resource);
154
- }
155
-
156
- return resources;
157
- }
158
-
159
- private designEndpoints(resources: Resource[], requirements: APIRequirements): Endpoint[] {
160
- const endpoints: Endpoint[] = [];
161
-
162
- for (const resource of resources) {
163
- // Collection endpoints
164
- if (resource.operations.includes('list')) {
165
- endpoints.push(this.createListEndpoint(resource));
166
- }
167
-
168
- if (resource.operations.includes('create')) {
169
- endpoints.push(this.createCreateEndpoint(resource));
170
- }
171
-
172
- // Item endpoints
173
- if (resource.operations.includes('read')) {
174
- endpoints.push(this.createReadEndpoint(resource));
175
- }
176
-
177
- if (resource.operations.includes('update')) {
178
- endpoints.push(this.createUpdateEndpoint(resource));
179
-
180
- if (requirements.supportPatch) {
181
- endpoints.push(this.createPatchEndpoint(resource));
182
- }
183
- }
184
-
185
- if (resource.operations.includes('delete')) {
186
- endpoints.push(this.createDeleteEndpoint(resource));
187
- }
188
-
189
- // Custom actions
190
- for (const action of resource.customActions || []) {
191
- endpoints.push(this.createCustomActionEndpoint(resource, action));
192
- }
193
-
194
- // Subresource endpoints
195
- for (const subresource of resource.subresources) {
196
- endpoints.push(...this.createSubresourceEndpoints(resource, subresource));
197
- }
198
- }
199
-
200
- // Add utility endpoints
201
- endpoints.push(...this.createUtilityEndpoints(requirements));
202
-
203
- return endpoints;
204
- }
205
-
206
- private createListEndpoint(resource: Resource): Endpoint {
207
- return {
208
- id: `list-${resource.plural}`,
209
- path: `/${resource.plural}`,
210
- method: HTTPMethod.GET,
211
- operation: {
212
- operationId: `list${this.capitalize(resource.plural)}`,
213
- summary: `List ${resource.plural}`,
214
- description: `Retrieve a paginated list of ${resource.plural}`,
215
- tags: [resource.name],
216
- parameters: [
217
- this.createPaginationParameters(),
218
- this.createFilterParameters(resource),
219
- this.createSortParameters(resource),
220
- this.createFieldsParameter(),
221
- ].flat(),
222
- responses: [
223
- {
224
- status: '200',
225
- description: `Successful response with ${resource.plural} list`,
226
- content: {
227
- 'application/json': {
228
- schema: {
229
- type: 'object',
230
- properties: {
231
- data: {
232
- type: 'array',
233
- items: { $ref: `#/components/schemas/${resource.name}` },
234
- },
235
- meta: { $ref: '#/components/schemas/PaginationMeta' },
236
- links: { $ref: '#/components/schemas/PaginationLinks' },
237
- },
238
- },
239
- examples: {
240
- success: this.generateListExample(resource),
241
- },
242
- },
243
- },
244
- },
245
- { $ref: '#/components/responses/400BadRequest' },
246
- { $ref: '#/components/responses/401Unauthorized' },
247
- { $ref: '#/components/responses/403Forbidden' },
248
- { $ref: '#/components/responses/500InternalServerError' },
249
- ],
250
- },
251
- };
252
- }
253
-
254
- private createCreateEndpoint(resource: Resource): Endpoint {
255
- return {
256
- id: `create-${resource.name}`,
257
- path: `/${resource.plural}`,
258
- method: HTTPMethod.POST,
259
- operation: {
260
- operationId: `create${this.capitalize(resource.name)}`,
261
- summary: `Create ${resource.name}`,
262
- description: `Create a new ${resource.name}`,
263
- tags: [resource.name],
264
- requestBody: {
265
- required: true,
266
- content: {
267
- 'application/json': {
268
- schema: { $ref: `#/components/schemas/${resource.name}Input` },
269
- examples: {
270
- complete: this.generateCreateExample(resource, 'complete'),
271
- minimal: this.generateCreateExample(resource, 'minimal'),
272
- },
273
- },
274
- },
275
- },
276
- responses: [
277
- {
278
- status: '201',
279
- description: `${resource.name} created successfully`,
280
- headers: {
281
- Location: {
282
- description: 'URL of the created resource',
283
- schema: { type: 'string' },
284
- },
285
- },
286
- content: {
287
- 'application/json': {
288
- schema: { $ref: `#/components/schemas/${resource.name}` },
289
- },
290
- },
291
- },
292
- { $ref: '#/components/responses/400BadRequest' },
293
- { $ref: '#/components/responses/401Unauthorized' },
294
- { $ref: '#/components/responses/403Forbidden' },
295
- { $ref: '#/components/responses/409Conflict' },
296
- { $ref: '#/components/responses/422UnprocessableEntity' },
297
- ],
298
- },
299
- };
300
- }
301
-
302
- private createReadEndpoint(resource: Resource): Endpoint {
303
- return {
304
- id: `get-${resource.name}`,
305
- path: `/${resource.plural}/{id}`,
306
- method: HTTPMethod.GET,
307
- operation: {
308
- operationId: `get${this.capitalize(resource.name)}`,
309
- summary: `Get ${resource.name}`,
310
- description: `Retrieve a specific ${resource.name} by ID`,
311
- tags: [resource.name],
312
- parameters: [
313
- {
314
- name: 'id',
315
- in: 'path',
316
- required: true,
317
- description: `${resource.name} identifier`,
318
- schema: { type: 'string', format: 'uuid' },
319
- },
320
- this.createFieldsParameter(),
321
- this.createExpandParameter(resource),
322
- ],
323
- responses: [
324
- {
325
- status: '200',
326
- description: `${resource.name} retrieved successfully`,
327
- content: {
328
- 'application/json': {
329
- schema: { $ref: `#/components/schemas/${resource.name}` },
330
- },
331
- },
332
- },
333
- { $ref: '#/components/responses/401Unauthorized' },
334
- { $ref: '#/components/responses/403Forbidden' },
335
- { $ref: '#/components/responses/404NotFound' },
336
- ],
337
- },
338
- };
339
- }
340
-
341
- private createUpdateEndpoint(resource: Resource): Endpoint {
342
- return {
343
- id: `update-${resource.name}`,
344
- path: `/${resource.plural}/{id}`,
345
- method: HTTPMethod.PUT,
346
- operation: {
347
- operationId: `update${this.capitalize(resource.name)}`,
348
- summary: `Update ${resource.name}`,
349
- description: `Replace an entire ${resource.name}`,
350
- tags: [resource.name],
351
- parameters: [
352
- {
353
- name: 'id',
354
- in: 'path',
355
- required: true,
356
- description: `${resource.name} identifier`,
357
- schema: { type: 'string', format: 'uuid' },
358
- },
359
- ],
360
- requestBody: {
361
- required: true,
362
- content: {
363
- 'application/json': {
364
- schema: { $ref: `#/components/schemas/${resource.name}Input` },
365
- },
366
- },
367
- },
368
- responses: [
369
- {
370
- status: '200',
371
- description: `${resource.name} updated successfully`,
372
- content: {
373
- 'application/json': {
374
- schema: { $ref: `#/components/schemas/${resource.name}` },
375
- },
376
- },
377
- },
378
- { $ref: '#/components/responses/400BadRequest' },
379
- { $ref: '#/components/responses/401Unauthorized' },
380
- { $ref: '#/components/responses/403Forbidden' },
381
- { $ref: '#/components/responses/404NotFound' },
382
- { $ref: '#/components/responses/409Conflict' },
383
- { $ref: '#/components/responses/422UnprocessableEntity' },
384
- ],
385
- },
386
- };
387
- }
388
-
389
- private createPatchEndpoint(resource: Resource): Endpoint {
390
- return {
391
- id: `patch-${resource.name}`,
392
- path: `/${resource.plural}/{id}`,
393
- method: HTTPMethod.PATCH,
394
- operation: {
395
- operationId: `patch${this.capitalize(resource.name)}`,
396
- summary: `Partially update ${resource.name}`,
397
- description: `Update specific fields of a ${resource.name}`,
398
- tags: [resource.name],
399
- parameters: [
400
- {
401
- name: 'id',
402
- in: 'path',
403
- required: true,
404
- description: `${resource.name} identifier`,
405
- schema: { type: 'string', format: 'uuid' },
406
- },
407
- ],
408
- requestBody: {
409
- required: true,
410
- content: {
411
- 'application/json-patch+json': {
412
- schema: { $ref: '#/components/schemas/JSONPatch' },
413
- examples: {
414
- updateField: {
415
- value: [
416
- { op: 'replace', path: '/status', value: 'active' },
417
- ],
418
- },
419
- },
420
- },
421
- 'application/merge-patch+json': {
422
- schema: { $ref: `#/components/schemas/${resource.name}Patch` },
423
- },
424
- },
425
- },
426
- responses: [
427
- {
428
- status: '200',
429
- description: `${resource.name} patched successfully`,
430
- content: {
431
- 'application/json': {
432
- schema: { $ref: `#/components/schemas/${resource.name}` },
433
- },
434
- },
435
- },
436
- { $ref: '#/components/responses/400BadRequest' },
437
- { $ref: '#/components/responses/401Unauthorized' },
438
- { $ref: '#/components/responses/403Forbidden' },
439
- { $ref: '#/components/responses/404NotFound' },
440
- { $ref: '#/components/responses/409Conflict' },
441
- { $ref: '#/components/responses/422UnprocessableEntity' },
442
- ],
443
- },
444
- };
445
- }
446
-
447
- async designGraphQLAPI(requirements: APIRequirements): Promise<GraphQLDesign> {
448
- // Design type system
449
- const types = this.designGraphQLTypes(requirements);
450
-
451
- // Design queries
452
- const queries = this.designQueries(types, requirements);
453
-
454
- // Design mutations
455
- const mutations = this.designMutations(types, requirements);
456
-
457
- // Design subscriptions
458
- const subscriptions = this.designSubscriptions(types, requirements);
459
-
460
- // Generate SDL
461
- const sdl = this.generateGraphQLSDL({
462
- types,
463
- queries,
464
- mutations,
465
- subscriptions,
466
- directives: this.designDirectives(requirements),
467
- scalars: this.designScalars(requirements),
468
- });
469
-
470
- // Build schema
471
- const schema = buildSchema(sdl);
472
-
473
- // Generate resolvers template
474
- const resolvers = this.generateResolvers(schema);
475
-
476
- // Validate schema
477
- await this.validator.validateGraphQLSchema(schema);
478
-
479
- return {
480
- schema,
481
- sdl,
482
- resolvers,
483
- documentation: this.generateGraphQLDocumentation(schema),
484
- examples: this.generateGraphQLExamples(schema),
485
- };
486
- }
487
-
488
- private designGraphQLTypes(requirements: APIRequirements): GraphQLType[] {
489
- const types: GraphQLType[] = [];
490
-
491
- for (const entity of requirements.entities) {
492
- // Object type
493
- types.push({
494
- kind: 'ObjectType',
495
- name: entity.name,
496
- description: entity.description,
497
- fields: this.mapGraphQLFields(entity.properties),
498
- interfaces: this.identifyInterfaces(entity),
499
- });
500
-
501
- // Input type
502
- types.push({
503
- kind: 'InputType',
504
- name: `${entity.name}Input`,
505
- description: `Input for creating/updating ${entity.name}`,
506
- fields: this.mapGraphQLInputFields(entity.properties),
507
- });
508
-
509
- // Filter type
510
- types.push({
511
- kind: 'InputType',
512
- name: `${entity.name}Filter`,
513
- description: `Filter for querying ${entity.name}`,
514
- fields: this.generateFilterFields(entity.properties),
515
- });
516
-
517
- // Connection type for pagination
518
- if (requirements.usePagination) {
519
- types.push(this.generateConnectionType(entity));
520
- types.push(this.generateEdgeType(entity));
521
- }
522
- }
523
-
524
- // Add common types
525
- types.push(...this.generateCommonGraphQLTypes());
526
-
527
- return types;
528
- }
529
-
530
- private designQueries(types: GraphQLType[], requirements: APIRequirements): Query[] {
531
- const queries: Query[] = [];
532
-
533
- for (const type of types.filter(t => t.kind === 'ObjectType' && !t.name.includes('Connection'))) {
534
- // Single item query
535
- queries.push({
536
- name: this.uncapitalize(type.name),
537
- description: `Get a single ${type.name}`,
538
- args: [
539
- { name: 'id', type: 'ID!', description: `${type.name} ID` },
540
- ],
541
- returnType: type.name,
542
- });
543
-
544
- // List query
545
- const listQuery: Query = {
546
- name: this.pluralize(this.uncapitalize(type.name)),
547
- description: `List ${type.name} items`,
548
- args: [
549
- { name: 'filter', type: `${type.name}Filter`, description: 'Filter criteria' },
550
- { name: 'sort', type: 'SortInput', description: 'Sort options' },
551
- ],
552
- returnType: `[${type.name}!]!`,
553
- };
554
-
555
- // Add pagination args if needed
556
- if (requirements.usePagination) {
557
- listQuery.args.push(
558
- { name: 'first', type: 'Int', description: 'Number of items to return' },
559
- { name: 'after', type: 'String', description: 'Cursor for pagination' },
560
- );
561
- listQuery.returnType = `${type.name}Connection!`;
562
- } else {
563
- listQuery.args.push(
564
- { name: 'limit', type: 'Int', description: 'Maximum number of items' },
565
- { name: 'offset', type: 'Int', description: 'Number of items to skip' },
566
- );
567
- }
568
-
569
- queries.push(listQuery);
570
-
571
- // Search query
572
- if (requirements.includeSearch) {
573
- queries.push({
574
- name: `search${type.name}`,
575
- description: `Search ${type.name} items`,
576
- args: [
577
- { name: 'query', type: 'String!', description: 'Search query' },
578
- { name: 'limit', type: 'Int', description: 'Maximum results' },
579
- ],
580
- returnType: `[${type.name}!]!`,
581
- });
582
- }
583
- }
584
-
585
- return queries;
586
- }
587
-
588
- private designMutations(types: GraphQLType[], requirements: APIRequirements): Mutation[] {
589
- const mutations: Mutation[] = [];
590
-
591
- for (const type of types.filter(t => t.kind === 'ObjectType' && !t.name.includes('Connection'))) {
592
- // Create mutation
593
- mutations.push({
594
- name: `create${type.name}`,
595
- description: `Create a new ${type.name}`,
596
- args: [
597
- { name: 'input', type: `${type.name}Input!`, description: 'Input data' },
598
- ],
599
- returnType: `${type.name}!`,
600
- });
601
-
602
- // Update mutation
603
- mutations.push({
604
- name: `update${type.name}`,
605
- description: `Update an existing ${type.name}`,
606
- args: [
607
- { name: 'id', type: 'ID!', description: `${type.name} ID` },
608
- { name: 'input', type: `${type.name}Input!`, description: 'Updated data' },
609
- ],
610
- returnType: `${type.name}!`,
611
- });
612
-
613
- // Delete mutation
614
- mutations.push({
615
- name: `delete${type.name}`,
616
- description: `Delete a ${type.name}`,
617
- args: [
618
- { name: 'id', type: 'ID!', description: `${type.name} ID` },
619
- ],
620
- returnType: 'Boolean!',
621
- });
622
-
623
- // Batch operations
624
- if (requirements.includeBatchOperations) {
625
- mutations.push({
626
- name: `batchCreate${type.name}`,
627
- description: `Create multiple ${type.name} items`,
628
- args: [
629
- { name: 'inputs', type: `[${type.name}Input!]!`, description: 'Input data array' },
630
- ],
631
- returnType: `[${type.name}!]!`,
632
- });
633
-
634
- mutations.push({
635
- name: `batchDelete${type.name}`,
636
- description: `Delete multiple ${type.name} items`,
637
- args: [
638
- { name: 'ids', type: '[ID!]!', description: 'IDs to delete' },
639
- ],
640
- returnType: 'Int!', // Number of deleted items
641
- });
642
- }
643
- }
644
-
645
- return mutations;
646
- }
647
-
648
- async generateAPIClient(specification: APISpecification): Promise<ClientSDK> {
649
- const sdk: ClientSDK = {
650
- language: specification.targetLanguage || 'typescript',
651
- name: `${specification.name}Client`,
652
- version: specification.version,
653
- files: [],
654
- };
655
-
656
- switch (sdk.language) {
657
- case 'typescript':
658
- sdk.files = await this.generateTypeScriptClient(specification);
659
- break;
660
- case 'python':
661
- sdk.files = await this.generatePythonClient(specification);
662
- break;
663
- case 'go':
664
- sdk.files = await this.generateGoClient(specification);
665
- break;
666
- case 'java':
667
- sdk.files = await this.generateJavaClient(specification);
668
- break;
669
- }
670
-
671
- return sdk;
672
- }
673
-
674
- private async generateTypeScriptClient(spec: APISpecification): Promise<ClientFile[]> {
675
- const files: ClientFile[] = [];
676
-
677
- // Types file
678
- files.push({
679
- name: 'types.ts',
680
- content: this.generateTypeScriptTypes(spec),
681
- });
682
-
683
- // API client class
684
- files.push({
685
- name: 'client.ts',
686
- content: this.generateTypeScriptClientClass(spec),
687
- });
688
-
689
- // Individual service classes
690
- for (const tag of spec.tags || []) {
691
- files.push({
692
- name: `${tag.name.toLowerCase()}.service.ts`,
693
- content: this.generateTypeScriptService(spec, tag),
694
- });
695
- }
696
-
697
- // Utils
698
- files.push({
699
- name: 'utils.ts',
700
- content: this.generateTypeScriptUtils(),
701
- });
702
-
703
- // Index file
704
- files.push({
705
- name: 'index.ts',
706
- content: this.generateTypeScriptIndex(spec),
707
- });
708
-
709
- return files;
710
- }
711
-
712
- private generateTypeScriptTypes(spec: APISpecification): string {
713
- let types = `// Auto-generated types from ${spec.name} v${spec.version}\n\n`;
714
-
715
- // Generate interfaces from schemas
716
- for (const [name, schema] of Object.entries(spec.components?.schemas || {})) {
717
- types += this.schemaToTypeScript(name, schema);
718
- types += '\n\n';
719
- }
720
-
721
- // Generate enums
722
- for (const [name, schema] of Object.entries(spec.components?.schemas || {})) {
723
- if (schema.enum) {
724
- types += `export enum ${name} {\n`;
725
- for (const value of schema.enum) {
726
- types += ` ${this.toEnumKey(value)} = '${value}',\n`;
727
- }
728
- types += '}\n\n';
729
- }
730
- }
731
-
732
- return types;
733
- }
734
-
735
- private schemaToTypeScript(name: string, schema: any): string {
736
- let ts = `export interface ${name} {\n`;
737
-
738
- if (schema.properties) {
739
- for (const [propName, propSchema] of Object.entries(schema.properties)) {
740
- const required = schema.required?.includes(propName) || false;
741
- const optional = required ? '' : '?';
742
- const type = this.jsonSchemaToTypeScript(propSchema);
743
-
744
- ts += ` ${propName}${optional}: ${type};\n`;
745
- }
746
- }
747
-
748
- ts += '}';
749
- return ts;
750
- }
751
-
752
- private generateTypeScriptClientClass(spec: APISpecification): string {
753
- return `
754
- import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
755
- import { ${this.getTypeImports(spec).join(', ')} } from './types';
756
-
757
- export interface ClientConfig {
758
- baseURL: string;
759
- apiKey?: string;
760
- accessToken?: string;
761
- timeout?: number;
762
- headers?: Record<string, string>;
763
- }
764
-
765
- export class ${spec.name}Client {
766
- private client: AxiosInstance;
767
- ${this.generateServiceProperties(spec)}
768
-
769
- constructor(config: ClientConfig) {
770
- this.client = axios.create({
771
- baseURL: config.baseURL,
772
- timeout: config.timeout || 30000,
773
- headers: {
774
- 'Content-Type': 'application/json',
775
- ...config.headers,
776
- },
777
- });
778
-
779
- // Add authentication
780
- if (config.apiKey) {
781
- this.client.defaults.headers.common['X-API-Key'] = config.apiKey;
782
- }
783
- if (config.accessToken) {
784
- this.client.defaults.headers.common['Authorization'] = \`Bearer \${config.accessToken}\`;
785
- }
786
-
787
- // Add interceptors
788
- this.setupInterceptors();
789
-
790
- // Initialize services
791
- ${this.generateServiceInitialization(spec)}
792
- }
793
-
794
- private setupInterceptors(): void {
795
- // Request interceptor
796
- this.client.interceptors.request.use(
797
- (config) => {
798
- // Add request ID
799
- config.headers['X-Request-Id'] = this.generateRequestId();
800
- return config;
801
- },
802
- (error) => Promise.reject(error)
803
- );
804
-
805
- // Response interceptor
806
- this.client.interceptors.response.use(
807
- (response) => response,
808
- async (error) => {
809
- if (error.response?.status === 401) {
810
- // Handle token refresh
811
- await this.refreshToken();
812
- return this.client.request(error.config);
813
- }
814
- return Promise.reject(error);
815
- }
816
- );
817
- }
818
-
819
- private generateRequestId(): string {
820
- return \`\${Date.now()}-\${Math.random().toString(36).substr(2, 9)}\`;
821
- }
822
-
823
- private async refreshToken(): Promise<void> {
824
- // Implement token refresh logic
825
- }
826
-
827
- async setAccessToken(token: string): Promise<void> {
828
- this.client.defaults.headers.common['Authorization'] = \`Bearer \${token}\`;
829
- }
830
- }
831
- `;
832
- }
833
-
834
- async validateAPIDesign(design: APIDesign): Promise<ValidationResult> {
835
- const issues: ValidationIssue[] = [];
836
-
837
- // Validate naming conventions
838
- issues.push(...this.validateNaming(design));
839
-
840
- // Validate HTTP methods usage
841
- issues.push(...this.validateHTTPMethods(design));
842
-
843
- // Validate status codes
844
- issues.push(...this.validateStatusCodes(design));
845
-
846
- // Validate pagination
847
- issues.push(...this.validatePagination(design));
848
-
849
- // Validate error handling
850
- issues.push(...this.validateErrorHandling(design));
851
-
852
- // Validate security
853
- issues.push(...this.validateSecurity(design));
854
-
855
- // Validate versioning
856
- issues.push(...this.validateVersioning(design));
857
-
858
- // Check for breaking changes
859
- if (design.previousVersion) {
860
- issues.push(...await this.checkBreakingChanges(design));
861
- }
862
-
863
- return {
864
- valid: issues.filter(i => i.severity === 'error').length === 0,
865
- issues,
866
- score: this.calculateDesignScore(issues),
867
- recommendations: this.generateRecommendations(issues),
868
- };
869
- }
870
-
871
- private validateNaming(design: APIDesign): ValidationIssue[] {
872
- const issues: ValidationIssue[] = [];
873
-
874
- for (const endpoint of design.endpoints) {
875
- // Check path naming
876
- if (!this.isValidPath(endpoint.path)) {
877
- issues.push({
878
- type: 'naming',
879
- severity: 'warning',
880
- message: `Path '${endpoint.path}' does not follow REST naming conventions`,
881
- location: endpoint.path,
882
- });
883
- }
884
-
885
- // Check for verbs in URIs
886
- if (this.containsVerb(endpoint.path)) {
887
- issues.push({
888
- type: 'naming',
889
- severity: 'error',
890
- message: `Path '${endpoint.path}' contains a verb, use HTTP methods instead`,
891
- location: endpoint.path,
892
- });
893
- }
894
- }
895
-
896
- return issues;
897
- }
898
-
899
- private validateHTTPMethods(design: APIDesign): ValidationIssue[] {
900
- const issues: ValidationIssue[] = [];
901
-
902
- for (const endpoint of design.endpoints) {
903
- // Check idempotency
904
- if (['PUT', 'DELETE'].includes(endpoint.method) && !endpoint.idempotent) {
905
- issues.push({
906
- type: 'http-method',
907
- severity: 'warning',
908
- message: `${endpoint.method} ${endpoint.path} should be idempotent`,
909
- location: endpoint.path,
910
- });
911
- }
912
-
913
- // Check safe methods
914
- if (endpoint.method === 'GET' && endpoint.hasSideEffects) {
915
- issues.push({
916
- type: 'http-method',
917
- severity: 'error',
918
- message: `GET ${endpoint.path} should not have side effects`,
919
- location: endpoint.path,
920
- });
921
- }
922
- }
923
-
924
- return issues;
925
- }
926
-
927
- private applyBestPractices(spec: OpenAPISpecification): OpenAPISpecification {
928
- // Add common responses
929
- spec.components.responses = {
930
- ...spec.components.responses,
931
- ...this.getCommonResponses(),
932
- };
933
-
934
- // Add common parameters
935
- spec.components.parameters = {
936
- ...spec.components.parameters,
937
- ...this.getCommonParameters(),
938
- };
939
-
940
- // Add security schemes
941
- if (!spec.components.securitySchemes) {
942
- spec.components.securitySchemes = this.getDefaultSecuritySchemes();
943
- }
944
-
945
- // Add rate limiting headers
946
- for (const path of Object.values(spec.paths)) {
947
- for (const operation of Object.values(path)) {
948
- if (operation.responses) {
949
- this.addRateLimitHeaders(operation.responses);
950
- }
951
- }
952
- }
953
-
954
- return spec;
955
- }
956
-
957
- private getCommonResponses(): Record<string, any> {
958
- return {
959
- '400BadRequest': {
960
- description: 'Bad request',
961
- content: {
962
- 'application/json': {
963
- schema: { $ref: '#/components/schemas/Error' },
964
- example: {
965
- error: {
966
- code: 'BAD_REQUEST',
967
- message: 'Invalid request parameters',
968
- },
969
- },
970
- },
971
- },
972
- },
973
- '401Unauthorized': {
974
- description: 'Authentication required',
975
- content: {
976
- 'application/json': {
977
- schema: { $ref: '#/components/schemas/Error' },
978
- example: {
979
- error: {
980
- code: 'UNAUTHORIZED',
981
- message: 'Authentication required',
982
- },
983
- },
984
- },
985
- },
986
- },
987
- '403Forbidden': {
988
- description: 'Insufficient permissions',
989
- content: {
990
- 'application/json': {
991
- schema: { $ref: '#/components/schemas/Error' },
992
- },
993
- },
994
- },
995
- '404NotFound': {
996
- description: 'Resource not found',
997
- content: {
998
- 'application/json': {
999
- schema: { $ref: '#/components/schemas/Error' },
1000
- },
1001
- },
1002
- },
1003
- '409Conflict': {
1004
- description: 'Resource conflict',
1005
- content: {
1006
- 'application/json': {
1007
- schema: { $ref: '#/components/schemas/Error' },
1008
- },
1009
- },
1010
- },
1011
- '422UnprocessableEntity': {
1012
- description: 'Validation error',
1013
- content: {
1014
- 'application/json': {
1015
- schema: { $ref: '#/components/schemas/ValidationError' },
1016
- },
1017
- },
1018
- },
1019
- '429TooManyRequests': {
1020
- description: 'Rate limit exceeded',
1021
- headers: {
1022
- 'X-RateLimit-Limit': {
1023
- schema: { type: 'integer' },
1024
- description: 'Request limit per hour',
1025
- },
1026
- 'X-RateLimit-Remaining': {
1027
- schema: { type: 'integer' },
1028
- description: 'Remaining requests',
1029
- },
1030
- 'X-RateLimit-Reset': {
1031
- schema: { type: 'integer' },
1032
- description: 'Unix timestamp when limit resets',
1033
- },
1034
- },
1035
- content: {
1036
- 'application/json': {
1037
- schema: { $ref: '#/components/schemas/Error' },
1038
- },
1039
- },
1040
- },
1041
- '500InternalServerError': {
1042
- description: 'Internal server error',
1043
- content: {
1044
- 'application/json': {
1045
- schema: { $ref: '#/components/schemas/Error' },
1046
- },
1047
- },
1048
- },
1049
- };
1050
- }
1051
-
1052
- private generateId(prefix: string): string {
1053
- return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
1054
- }
1055
-
1056
- private pluralize(word: string): string {
1057
- // Simple pluralization
1058
- if (word.endsWith('y')) {
1059
- return word.slice(0, -1) + 'ies';
1060
- }
1061
- if (word.endsWith('s')) {
1062
- return word + 'es';
1063
- }
1064
- return word + 's';
1065
- }
1066
-
1067
- private capitalize(word: string): string {
1068
- return word.charAt(0).toUpperCase() + word.slice(1);
1069
- }
1070
-
1071
- private uncapitalize(word: string): string {
1072
- return word.charAt(0).toLowerCase() + word.slice(1);
1073
- }
1074
-
1075
- private toEnumKey(value: string): string {
1076
- return value.toUpperCase().replace(/[^A-Z0-9]/g, '_');
1077
- }
1078
- }
1079
-
1080
- // Supporting classes
1081
- class SpecificationValidator {
1082
- async validateOpenAPI(spec: OpenAPISpecification): Promise<void> {
1083
- // Validate against OpenAPI schema
1084
- // Check for required fields
1085
- // Validate references
1086
- // Check for circular references
1087
- }
1088
-
1089
- async validateGraphQLSchema(schema: GraphQLSchema): Promise<void> {
1090
- // Validate schema
1091
- // Check for orphaned types
1092
- // Validate directives
1093
- // Check query complexity
1094
- }
1095
- }
1096
-
1097
- class CodeGenerator {
1098
- generateTypeScript(spec: APISpecification): string {
1099
- // Generate TypeScript code
1100
- return '';
1101
- }
1102
-
1103
- generatePython(spec: APISpecification): string {
1104
- // Generate Python code
1105
- return '';
1106
- }
1107
-
1108
- generateGo(spec: APISpecification): string {
1109
- // Generate Go code
1110
- return '';
1111
- }
1112
- }
1113
-
1114
- // Type definitions
1115
- enum APIType {
1116
- REST = 'rest',
1117
- GRAPHQL = 'graphql',
1118
- GRPC = 'grpc',
1119
- WEBSOCKET = 'websocket',
1120
- }
1121
-
1122
- enum HTTPMethod {
1123
- GET = 'GET',
1124
- POST = 'POST',
1125
- PUT = 'PUT',
1126
- PATCH = 'PATCH',
1127
- DELETE = 'DELETE',
1128
- HEAD = 'HEAD',
1129
- OPTIONS = 'OPTIONS',
1130
- }
1131
-
1132
- interface APISpecification {
1133
- name: string;
1134
- version: string;
1135
- type: APIType;
1136
- baseUrl?: string;
1137
- paths?: any;
1138
- components?: any;
1139
- tags?: Tag[];
1140
- servers?: Server[];
1141
- security?: SecurityRequirement[];
1142
- targetLanguage?: string;
1143
- previousVersion?: APISpecification;
1144
- }
1145
-
1146
- interface OpenAPISpecification extends APISpecification {
1147
- openapi: string;
1148
- info: Info;
1149
- paths: Paths;
1150
- components: Components;
1151
- security?: SecurityRequirement[];
1152
- tags?: Tag[];
1153
- servers?: Server[];
1154
- externalDocs?: ExternalDocumentation;
1155
- }
1156
-
1157
- interface GraphQLDesign {
1158
- schema: GraphQLSchema;
1159
- sdl: string;
1160
- resolvers: any;
1161
- documentation: any;
1162
- examples: any[];
1163
- }
1164
-
1165
- interface APIRequirements {
1166
- name: string;
1167
- description: string;
1168
- version: string;
1169
- entities: Entity[];
1170
- useCases: UseCase[];
1171
- authentication?: AuthRequirement;
1172
- authorization?: AuthzRequirement;
1173
- rateLimiting?: RateLimitRequirement;
1174
- pagination?: PaginationRequirement;
1175
- supportPatch?: boolean;
1176
- usePagination?: boolean;
1177
- includeSearch?: boolean;
1178
- includeBatchOperations?: boolean;
1179
- documentation?: any;
1180
- }
1181
-
1182
- interface Entity {
1183
- name: string;
1184
- description: string;
1185
- properties: Property[];
1186
- relationships: Relationship[];
1187
- }
1188
-
1189
- interface Property {
1190
- name: string;
1191
- type: string;
1192
- required: boolean;
1193
- description: string;
1194
- constraints?: Constraint[];
1195
- }
1196
-
1197
- interface Relationship {
1198
- type: string;
1199
- target: string;
1200
- cardinality: string;
1201
- }
1202
-
1203
- interface Constraint {
1204
- type: string;
1205
- value: any;
1206
- }
1207
-
1208
- interface UseCase {
1209
- name: string;
1210
- description: string;
1211
- actors: string[];
1212
- preconditions: string[];
1213
- steps: string[];
1214
- postconditions: string[];
1215
- }
1216
-
1217
- interface AuthRequirement {
1218
- type: string;
1219
- flows: string[];
1220
- }
1221
-
1222
- interface AuthzRequirement {
1223
- model: string;
1224
- roles: string[];
1225
- permissions: string[];
1226
- }
1227
-
1228
- interface RateLimitRequirement {
1229
- default: number;
1230
- endpoints: Record<string, number>;
1231
- }
1232
-
1233
- interface PaginationRequirement {
1234
- defaultLimit: number;
1235
- maxLimit: number;
1236
- style: 'offset' | 'cursor' | 'page';
1237
- }
1238
-
1239
- interface RequirementAnalysis {
1240
- entities: Entity[];
1241
- operations: Operation[];
1242
- constraints: Constraint[];
1243
- nonFunctional: NonFunctionalRequirement[];
1244
- }
1245
-
1246
- interface Resource {
1247
- id: string;
1248
- name: string;
1249
- plural: string;
1250
- description: string;
1251
- attributes: Attribute[];
1252
- relationships: ResourceRelationship[];
1253
- operations: string[];
1254
- uri: string;
1255
- subresources: Resource[];
1256
- customActions?: CustomAction[];
1257
- }
1258
-
1259
- interface Attribute {
1260
- name: string;
1261
- type: string;
1262
- required: boolean;
1263
- description: string;
1264
- validation?: any;
1265
- }
1266
-
1267
- interface ResourceRelationship {
1268
- name: string;
1269
- type: string;
1270
- target: string;
1271
- cardinality: string;
1272
- }
1273
-
1274
- interface CustomAction {
1275
- name: string;
1276
- method: HTTPMethod;
1277
- path: string;
1278
- description: string;
1279
- }
1280
-
1281
- interface Operation {
1282
- type: string;
1283
- resource: string;
1284
- description: string;
1285
- }
1286
-
1287
- interface NonFunctionalRequirement {
1288
- type: string;
1289
- requirement: string;
1290
- metric: string;
1291
- }
1292
-
1293
- interface OperationObject {
1294
- operationId: string;
1295
- summary: string;
1296
- description: string;
1297
- tags: string[];
1298
- parameters?: Parameter[];
1299
- requestBody?: RequestBody;
1300
- responses: ResponseObject[];
1301
- security?: SecurityRequirement[];
1302
- deprecated?: boolean;
1303
- }
1304
-
1305
- interface Parameter {
1306
- name: string;
1307
- in: string;
1308
- required: boolean;
1309
- description: string;
1310
- schema: any;
1311
- style?: string;
1312
- explode?: boolean;
1313
- example?: any;
1314
- }
1315
-
1316
- interface RequestBody {
1317
- required: boolean;
1318
- description?: string;
1319
- content: Record<string, MediaType>;
1320
- }
1321
-
1322
- interface MediaType {
1323
- schema: any;
1324
- examples?: Record<string, any>;
1325
- example?: any;
1326
- }
1327
-
1328
- interface ResponseObject {
1329
- status: string;
1330
- description: string;
1331
- headers?: Record<string, any>;
1332
- content?: Record<string, MediaType>;
1333
- links?: Record<string, any>;
1334
- $ref?: string;
1335
- }
1336
-
1337
- interface SecurityRequirement {
1338
- [key: string]: string[];
1339
- }
1340
-
1341
- interface AuthenticationScheme {
1342
- type: string;
1343
- scheme?: string;
1344
- bearerFormat?: string;
1345
- flows?: any;
1346
- openIdConnectUrl?: string;
1347
- description?: string;
1348
- }
1349
-
1350
- interface AuthorizationModel {
1351
- type: string;
1352
- roles: Role[];
1353
- permissions: Permission[];
1354
- policies: Policy[];
1355
- }
1356
-
1357
- interface Role {
1358
- name: string;
1359
- description: string;
1360
- permissions: string[];
1361
- }
1362
-
1363
- interface Permission {
1364
- name: string;
1365
- resource: string;
1366
- action: string;
1367
- }
1368
-
1369
- interface Policy {
1370
- name: string;
1371
- effect: string;
1372
- conditions: any[];
1373
- }
1374
-
1375
- interface RateLimitPolicy {
1376
- default: RateLimit;
1377
- endpoints: Map<string, RateLimit>;
1378
- tiers: RateLimitTier[];
1379
- }
1380
-
1381
- interface RateLimit {
1382
- requests: number;
1383
- window: string;
1384
- strategy: string;
1385
- }
1386
-
1387
- interface RateLimitTier {
1388
- name: string;
1389
- limits: RateLimit;
1390
- price?: number;
1391
- }
1392
-
1393
- interface VersioningStrategy {
1394
- type: 'uri' | 'header' | 'query' | 'media-type';
1395
- format: string;
1396
- default: string;
1397
- supported: string[];
1398
- deprecation: DeprecationPolicy;
1399
- }
1400
-
1401
- interface DeprecationPolicy {
1402
- notice: string;
1403
- sunset: string;
1404
- migration: string;
1405
- }
1406
-
1407
- interface APIDocumentation {
1408
- format: string;
1409
- sections: DocumentationSection[];
1410
- examples: Example[];
1411
- tutorials: Tutorial[];
1412
- }
1413
-
1414
- interface DocumentationSection {
1415
- title: string;
1416
- content: string;
1417
- subsections?: DocumentationSection[];
1418
- }
1419
-
1420
- interface Example {
1421
- title: string;
1422
- description: string;
1423
- request: any;
1424
- response: any;
1425
- }
1426
-
1427
- interface Tutorial {
1428
- title: string;
1429
- steps: TutorialStep[];
1430
- }
1431
-
1432
- interface TutorialStep {
1433
- title: string;
1434
- description: string;
1435
- code: string;
1436
- }
1437
-
1438
- interface TestStrategy {
1439
- unit: boolean;
1440
- integration: boolean;
1441
- contract: boolean;
1442
- performance: boolean;
1443
- security: boolean;
1444
- }
1445
-
1446
- interface MonitoringConfig {
1447
- metrics: string[];
1448
- logging: LoggingConfig;
1449
- tracing: TracingConfig;
1450
- alerts: Alert[];
1451
- }
1452
-
1453
- interface LoggingConfig {
1454
- level: string;
1455
- format: string;
1456
- destination: string;
1457
- }
1458
-
1459
- interface TracingConfig {
1460
- enabled: boolean;
1461
- sampling: number;
1462
- backend: string;
1463
- }
1464
-
1465
- interface Alert {
1466
- name: string;
1467
- condition: string;
1468
- threshold: number;
1469
- action: string;
1470
- }
1471
-
1472
- interface DesignPattern {
1473
- name: string;
1474
- description: string;
1475
- context: string;
1476
- solution: any;
1477
- examples: any[];
1478
- }
1479
-
1480
- interface GraphQLType {
1481
- kind: string;
1482
- name: string;
1483
- description: string;
1484
- fields: Field[];
1485
- interfaces?: string[];
1486
- }
1487
-
1488
- interface Field {
1489
- name: string;
1490
- type: string;
1491
- description: string;
1492
- args?: Argument[];
1493
- deprecated?: boolean;
1494
- deprecationReason?: string;
1495
- }
1496
-
1497
- interface Argument {
1498
- name: string;
1499
- type: string;
1500
- description: string;
1501
- defaultValue?: any;
1502
- }
1503
-
1504
- interface Query {
1505
- name: string;
1506
- description: string;
1507
- args: Argument[];
1508
- returnType: string;
1509
- }
1510
-
1511
- interface Mutation {
1512
- name: string;
1513
- description: string;
1514
- args: Argument[];
1515
- returnType: string;
1516
- }
1517
-
1518
- interface Subscription {
1519
- name: string;
1520
- description: string;
1521
- args: Argument[];
1522
- returnType: string;
1523
- }
1524
-
1525
- interface ClientSDK {
1526
- language: string;
1527
- name: string;
1528
- version: string;
1529
- files: ClientFile[];
1530
- }
1531
-
1532
- interface ClientFile {
1533
- name: string;
1534
- content: string;
1535
- }
1536
-
1537
- interface ValidationResult {
1538
- valid: boolean;
1539
- issues: ValidationIssue[];
1540
- score: number;
1541
- recommendations: string[];
1542
- }
1543
-
1544
- interface ValidationIssue {
1545
- type: string;
1546
- severity: string;
1547
- message: string;
1548
- location?: string;
1549
- suggestion?: string;
1550
- }
1551
-
1552
- interface Info {
1553
- title: string;
1554
- version: string;
1555
- description?: string;
1556
- termsOfService?: string;
1557
- contact?: Contact;
1558
- license?: License;
1559
- }
1560
-
1561
- interface Contact {
1562
- name?: string;
1563
- url?: string;
1564
- email?: string;
1565
- }
1566
-
1567
- interface License {
1568
- name: string;
1569
- url?: string;
1570
- }
1571
-
1572
- interface Server {
1573
- url: string;
1574
- description?: string;
1575
- variables?: Record<string, ServerVariable>;
1576
- }
1577
-
1578
- interface ServerVariable {
1579
- enum?: string[];
1580
- default: string;
1581
- description?: string;
1582
- }
1583
-
1584
- interface Tag {
1585
- name: string;
1586
- description?: string;
1587
- externalDocs?: ExternalDocumentation;
1588
- }
1589
-
1590
- interface ExternalDocumentation {
1591
- description?: string;
1592
- url: string;
1593
- }
1594
-
1595
- interface Paths {
1596
- [path: string]: PathItem;
1597
- }
1598
-
1599
- interface PathItem {
1600
- [method: string]: Operation;
1601
- $ref?: string;
1602
- summary?: string;
1603
- description?: string;
1604
- servers?: Server[];
1605
- parameters?: Parameter[];
1606
- }
1607
-
1608
- interface Components {
1609
- schemas?: Record<string, any>;
1610
- responses?: Record<string, any>;
1611
- parameters?: Record<string, any>;
1612
- examples?: Record<string, any>;
1613
- requestBodies?: Record<string, any>;
1614
- headers?: Record<string, any>;
1615
- securitySchemes?: Record<string, any>;
1616
- links?: Record<string, any>;
1617
- callbacks?: Record<string, any>;
1618
- }
1619
-
1620
- // Export the designer
1621
- export { APIDesigner, APIDesign, OpenAPISpecification };
1622
- ```
1623
-
1624
- ## Best Practices
1625
- 1. **RESTful Principles**: Follow REST architectural constraints
1626
- 2. **Consistent Naming**: Use consistent naming conventions
1627
- 3. **Versioning Strategy**: Plan for API evolution
1628
- 4. **Error Handling**: Provide clear, actionable error messages
1629
- 5. **Documentation**: Comprehensive, up-to-date documentation
1630
- 6. **Security First**: Design with security in mind
1631
- 7. **Performance**: Consider caching and pagination
1632
-
1633
- ## API Design Principles
1634
- - Resource-based URLs (nouns, not verbs)
1635
- - Use HTTP methods appropriately
1636
- - Stateless communication
1637
- - HATEOAS when applicable
1638
- - Standard status codes
1639
- - Content negotiation
1640
- - Idempotent operations
1641
-
1642
- ## Approach
1643
- - Understand business requirements
1644
- - Design resource model
1645
- - Define operations and endpoints
1646
- - Create data schemas
1647
- - Design authentication/authorization
1648
- - Document comprehensively
1649
- - Generate client SDKs
1650
-
1651
- ## Output Format
1652
- - Provide complete API specifications
1653
- - Include OpenAPI/Swagger documentation
1654
- - Generate client SDK code
1655
- - Add testing strategies
1656
- - Include security considerations
1657
- - Provide migration guides