rapitapir 0.1.1 → 2.0.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -7
- data/.rubocop_todo.yml +83 -0
- data/README.md +1319 -235
- data/RUBY_WEEKLY_LAUNCH_POST.md +219 -0
- data/docs/RAILS_INTEGRATION_IMPLEMENTATION.md +209 -0
- data/docs/SINATRA_EXTENSION.md +399 -348
- data/docs/STRICT_VALIDATION.md +229 -0
- data/docs/VALIDATION_IMPROVEMENTS.md +218 -0
- data/docs/ai-integration-plan.md +112 -0
- data/docs/auto-derivation.md +505 -92
- data/docs/endpoint-definition.md +536 -129
- data/docs/n8n-integration.md +212 -0
- data/docs/observability.md +810 -500
- data/docs/using-mcp.md +93 -0
- data/examples/ai/knowledge_base_rag.rb +83 -0
- data/examples/ai/user_management_mcp.rb +92 -0
- data/examples/ai/user_validation_llm.rb +187 -0
- data/examples/rails/RAILS_8_GUIDE.md +165 -0
- data/examples/rails/RAILS_LOADING_FIX.rb +35 -0
- data/examples/rails/README.md +497 -0
- data/examples/rails/comprehensive_test.rb +91 -0
- data/examples/rails/config/routes.rb +48 -0
- data/examples/rails/debug_controller.rb +63 -0
- data/examples/rails/detailed_test.rb +46 -0
- data/examples/rails/enhanced_users_controller.rb +278 -0
- data/examples/rails/final_server_test.rb +50 -0
- data/examples/rails/hello_world_app.rb +116 -0
- data/examples/rails/hello_world_controller.rb +186 -0
- data/examples/rails/hello_world_routes.rb +28 -0
- data/examples/rails/rails8_minimal_demo.rb +132 -0
- data/examples/rails/rails8_simple_demo.rb +140 -0
- data/examples/rails/rails8_working_demo.rb +255 -0
- data/examples/rails/real_world_blog_api.rb +510 -0
- data/examples/rails/server_test.rb +46 -0
- data/examples/rails/test_direct_processing.rb +41 -0
- data/examples/rails/test_hello_world.rb +80 -0
- data/examples/rails/test_rails_integration.rb +54 -0
- data/examples/rails/traditional_app/Gemfile +37 -0
- data/examples/rails/traditional_app/README.md +265 -0
- data/examples/rails/traditional_app/app/controllers/api/v1/posts_controller.rb +254 -0
- data/examples/rails/traditional_app/app/controllers/api/v1/users_controller.rb +220 -0
- data/examples/rails/traditional_app/app/controllers/application_controller.rb +86 -0
- data/examples/rails/traditional_app/app/controllers/application_controller_simplified.rb +87 -0
- data/examples/rails/traditional_app/app/controllers/documentation_controller.rb +149 -0
- data/examples/rails/traditional_app/app/controllers/health_controller.rb +42 -0
- data/examples/rails/traditional_app/config/routes.rb +25 -0
- data/examples/rails/traditional_app/config/routes_best_practice.rb +25 -0
- data/examples/rails/traditional_app/config/routes_simplified.rb +36 -0
- data/examples/rails/traditional_app_runnable.rb +406 -0
- data/examples/rails/users_controller.rb +4 -1
- data/examples/serverless/Gemfile +43 -0
- data/examples/serverless/QUICKSTART.md +331 -0
- data/examples/serverless/README.md +520 -0
- data/examples/serverless/aws_lambda_example.rb +307 -0
- data/examples/serverless/aws_sam_template.yaml +215 -0
- data/examples/serverless/azure_functions_example.rb +407 -0
- data/examples/serverless/deploy.rb +204 -0
- data/examples/serverless/gcp_cloud_functions_example.rb +367 -0
- data/examples/serverless/gcp_function.yaml +23 -0
- data/examples/serverless/host.json +24 -0
- data/examples/serverless/package.json +32 -0
- data/examples/serverless/spec/aws_lambda_spec.rb +196 -0
- data/examples/serverless/spec/spec_helper.rb +89 -0
- data/examples/serverless/vercel.json +31 -0
- data/examples/serverless/vercel_example.rb +404 -0
- data/examples/strict_validation_examples.rb +104 -0
- data/examples/validation_error_examples.rb +173 -0
- data/lib/rapitapir/ai/llm_instruction.rb +456 -0
- data/lib/rapitapir/ai/mcp.rb +134 -0
- data/lib/rapitapir/ai/rag.rb +287 -0
- data/lib/rapitapir/ai/rag_middleware.rb +147 -0
- data/lib/rapitapir/auth/oauth2.rb +43 -57
- data/lib/rapitapir/cli/command.rb +362 -2
- data/lib/rapitapir/cli/mcp_export.rb +18 -0
- data/lib/rapitapir/cli/validator.rb +2 -6
- data/lib/rapitapir/core/endpoint.rb +59 -6
- data/lib/rapitapir/core/enhanced_endpoint.rb +2 -6
- data/lib/rapitapir/dsl/fluent_endpoint_builder.rb +53 -0
- data/lib/rapitapir/endpoint_registry.rb +47 -0
- data/lib/rapitapir/observability/health_check.rb +4 -4
- data/lib/rapitapir/observability/logging.rb +10 -10
- data/lib/rapitapir/schema.rb +2 -2
- data/lib/rapitapir/server/rack_adapter.rb +1 -3
- data/lib/rapitapir/server/rails/configuration.rb +77 -0
- data/lib/rapitapir/server/rails/controller_base.rb +185 -0
- data/lib/rapitapir/server/rails/documentation_helpers.rb +76 -0
- data/lib/rapitapir/server/rails/resource_builder.rb +181 -0
- data/lib/rapitapir/server/rails/routes.rb +114 -0
- data/lib/rapitapir/server/rails_adapter.rb +10 -3
- data/lib/rapitapir/server/rails_adapter_class.rb +1 -3
- data/lib/rapitapir/server/rails_controller.rb +1 -3
- data/lib/rapitapir/server/rails_integration.rb +67 -0
- data/lib/rapitapir/server/rails_response_handler.rb +16 -3
- data/lib/rapitapir/server/sinatra_adapter.rb +29 -5
- data/lib/rapitapir/server/sinatra_integration.rb +4 -4
- data/lib/rapitapir/sinatra/extension.rb +2 -2
- data/lib/rapitapir/sinatra/oauth2_helpers.rb +34 -40
- data/lib/rapitapir/types/array.rb +4 -0
- data/lib/rapitapir/types/auto_derivation.rb +4 -18
- data/lib/rapitapir/types/datetime.rb +1 -3
- data/lib/rapitapir/types/float.rb +2 -6
- data/lib/rapitapir/types/hash.rb +40 -2
- data/lib/rapitapir/types/integer.rb +4 -12
- data/lib/rapitapir/types/object.rb +6 -2
- data/lib/rapitapir/types.rb +6 -2
- data/lib/rapitapir/version.rb +1 -1
- data/lib/rapitapir.rb +5 -3
- data/rapitapir.gemspec +7 -5
- metadata +116 -16
@@ -0,0 +1,212 @@
|
|
1
|
+
# RapiTapir + n8n Integration Guide
|
2
|
+
|
3
|
+
This guide shows how to integrate RapiTapir APIs with n8n workflow automation.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
1. A RapiTapir API with endpoints marked for MCP export
|
8
|
+
2. n8n instance (local or cloud)
|
9
|
+
3. Generated OpenAPI specification
|
10
|
+
|
11
|
+
## Integration Methods
|
12
|
+
|
13
|
+
### Method 1: Using OpenAPI Import (Recommended)
|
14
|
+
|
15
|
+
1. **Generate OpenAPI spec:**
|
16
|
+
```bash
|
17
|
+
rapitapir generate openapi --endpoints api.rb --output openapi.json
|
18
|
+
```
|
19
|
+
|
20
|
+
2. **Import in n8n:**
|
21
|
+
- Open n8n workflow editor
|
22
|
+
- Add "HTTP Request" node
|
23
|
+
- In node settings, click "Import from URL" or "Import from File"
|
24
|
+
- Select your `openapi.json` file
|
25
|
+
- n8n will auto-generate the available endpoints
|
26
|
+
|
27
|
+
### Method 2: Manual HTTP Request Configuration
|
28
|
+
|
29
|
+
For each RapiTapir endpoint:
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
// n8n HTTP Request Node Configuration
|
33
|
+
{
|
34
|
+
"method": "GET",
|
35
|
+
"url": "https://your-api.com/users/{{ $json.user_id }}",
|
36
|
+
"headers": {
|
37
|
+
"Content-Type": "application/json",
|
38
|
+
"Authorization": "Bearer {{ $json.auth_token }}"
|
39
|
+
},
|
40
|
+
"body": {
|
41
|
+
// Request body for POST/PUT endpoints
|
42
|
+
}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
### Method 3: Using MCP Context (Advanced)
|
47
|
+
|
48
|
+
Export MCP context for AI-powered workflow creation:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
rapitapir export mcp --endpoints api.rb --output mcp-context.json
|
52
|
+
```
|
53
|
+
|
54
|
+
Use the MCP context to:
|
55
|
+
- Auto-generate n8n workflow templates
|
56
|
+
- Provide API documentation to AI assistants
|
57
|
+
- Create dynamic workflow suggestions
|
58
|
+
|
59
|
+
## Example Workflows
|
60
|
+
|
61
|
+
### User Management Workflow
|
62
|
+
|
63
|
+
```json
|
64
|
+
{
|
65
|
+
"name": "User Management with RapiTapir",
|
66
|
+
"nodes": [
|
67
|
+
{
|
68
|
+
"name": "Webhook Trigger",
|
69
|
+
"type": "n8n-nodes-base.webhook",
|
70
|
+
"parameters": {
|
71
|
+
"path": "user-signup"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"name": "Create User",
|
76
|
+
"type": "n8n-nodes-base.httpRequest",
|
77
|
+
"parameters": {
|
78
|
+
"method": "POST",
|
79
|
+
"url": "https://your-api.com/users",
|
80
|
+
"headers": {
|
81
|
+
"Content-Type": "application/json"
|
82
|
+
},
|
83
|
+
"body": {
|
84
|
+
"name": "={{ $json.name }}",
|
85
|
+
"email": "={{ $json.email }}"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"name": "Send Welcome Email",
|
91
|
+
"type": "n8n-nodes-base.emailSend",
|
92
|
+
"parameters": {
|
93
|
+
"toEmail": "={{ $node['Create User'].json.email }}",
|
94
|
+
"subject": "Welcome!",
|
95
|
+
"text": "Welcome {{ $node['Create User'].json.name }}!"
|
96
|
+
}
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"connections": {
|
100
|
+
"Webhook Trigger": {
|
101
|
+
"main": [["Create User"]]
|
102
|
+
},
|
103
|
+
"Create User": {
|
104
|
+
"main": [["Send Welcome Email"]]
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
```
|
109
|
+
|
110
|
+
### Data Sync Workflow
|
111
|
+
|
112
|
+
```json
|
113
|
+
{
|
114
|
+
"name": "Daily User Sync",
|
115
|
+
"nodes": [
|
116
|
+
{
|
117
|
+
"name": "Schedule Trigger",
|
118
|
+
"type": "n8n-nodes-base.cron",
|
119
|
+
"parameters": {
|
120
|
+
"rule": {
|
121
|
+
"interval": [{"field": "cronExpression", "value": "0 9 * * *"}]
|
122
|
+
}
|
123
|
+
}
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"name": "Get Users",
|
127
|
+
"type": "n8n-nodes-base.httpRequest",
|
128
|
+
"parameters": {
|
129
|
+
"method": "GET",
|
130
|
+
"url": "https://your-api.com/users?page=1&limit=100"
|
131
|
+
}
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"name": "Process Each User",
|
135
|
+
"type": "n8n-nodes-base.splitInBatches",
|
136
|
+
"parameters": {
|
137
|
+
"batchSize": 10
|
138
|
+
}
|
139
|
+
}
|
140
|
+
]
|
141
|
+
}
|
142
|
+
```
|
143
|
+
|
144
|
+
## Authentication Setup
|
145
|
+
|
146
|
+
### OAuth2 with RapiTapir
|
147
|
+
|
148
|
+
1. **Configure OAuth2 in n8n:**
|
149
|
+
```json
|
150
|
+
{
|
151
|
+
"authentication": "oAuth2Api",
|
152
|
+
"oAuth2Api": {
|
153
|
+
"authUrl": "https://your-auth-provider.com/oauth/authorize",
|
154
|
+
"accessTokenUrl": "https://your-auth-provider.com/oauth/token",
|
155
|
+
"clientId": "{{ $credentials.clientId }}",
|
156
|
+
"clientSecret": "{{ $credentials.clientSecret }}",
|
157
|
+
"scope": "read:users write:users"
|
158
|
+
}
|
159
|
+
}
|
160
|
+
```
|
161
|
+
|
162
|
+
### JWT Authentication
|
163
|
+
|
164
|
+
```json
|
165
|
+
{
|
166
|
+
"authentication": "headerAuth",
|
167
|
+
"headerAuth": {
|
168
|
+
"name": "Authorization",
|
169
|
+
"value": "Bearer {{ $credentials.jwt_token }}"
|
170
|
+
}
|
171
|
+
}
|
172
|
+
```
|
173
|
+
|
174
|
+
## Best Practices
|
175
|
+
|
176
|
+
1. **Error Handling:**
|
177
|
+
- Use n8n's "Error Trigger" node for failed API calls
|
178
|
+
- Implement retry logic for transient failures
|
179
|
+
|
180
|
+
2. **Rate Limiting:**
|
181
|
+
- Add "Wait" nodes between API calls
|
182
|
+
- Use n8n's built-in rate limiting features
|
183
|
+
|
184
|
+
3. **Data Validation:**
|
185
|
+
- Validate input data before sending to RapiTapir endpoints
|
186
|
+
- Use n8n's "Set" node to transform data formats
|
187
|
+
|
188
|
+
4. **Monitoring:**
|
189
|
+
- Enable n8n's execution logging
|
190
|
+
- Set up alerts for failed workflows
|
191
|
+
|
192
|
+
## Troubleshooting
|
193
|
+
|
194
|
+
### Common Issues
|
195
|
+
|
196
|
+
1. **CORS Errors:**
|
197
|
+
- Ensure RapiTapir API allows n8n's origin
|
198
|
+
- Use server-side n8n instance for cross-origin requests
|
199
|
+
|
200
|
+
2. **Authentication Failures:**
|
201
|
+
- Verify credentials are properly configured
|
202
|
+
- Check token expiration and refresh logic
|
203
|
+
|
204
|
+
3. **Schema Mismatches:**
|
205
|
+
- Keep OpenAPI spec updated with API changes
|
206
|
+
- Validate request/response formats
|
207
|
+
|
208
|
+
## Resources
|
209
|
+
|
210
|
+
- [n8n HTTP Request Node Documentation](https://docs.n8n.io/nodes/n8n-nodes-base.httpRequest/)
|
211
|
+
- [n8n OAuth2 Authentication](https://docs.n8n.io/credentials/oauth2/)
|
212
|
+
- [RapiTapir OpenAPI Documentation](../openapi-documentation.md)
|