rapitapir 0.1.2 → 2.1.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 +88 -0
- data/CHANGELOG.md +29 -1
- data/README.md +1339 -236
- data/RUBY_WEEKLY_LAUNCH_POST.md +200 -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/adr/0001-base-class-strategy.md +33 -0
- data/docs/adr/0002-type-shortcut-and-type-system.md +30 -0
- data/docs/adr/0003-openapi-source-of-truth.md +32 -0
- data/docs/adr/0004-client-generation-typescript-first.md +34 -0
- data/docs/adr/0005-auth-architecture.md +32 -0
- data/docs/adr/0006-observability-defaults.md +30 -0
- data/docs/adr/0007-ai-scope-and-boundaries.md +30 -0
- data/docs/adr/README.md +46 -0
- data/docs/adr/template.md +24 -0
- data/docs/ai-integration-plan.md +112 -0
- data/docs/auto-derivation.md +505 -92
- data/docs/blueprint.md +92 -4
- data/docs/endpoint-definition.md +536 -129
- data/docs/implementation-status.md +1 -1
- 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/auto_derivation_ruby_friendly.rb +44 -113
- data/examples/cli/user_api_endpoints.rb +63 -36
- data/examples/demo_api.rb +57 -18
- data/examples/enterprise_extension_demo.rb +13 -13
- data/examples/enterprise_rapitapir_api.rb +81 -93
- data/examples/nocodb/nocodb_scaffold/Gemfile +22 -0
- data/examples/nocodb/nocodb_scaffold/README.md +10 -0
- data/examples/nocodb/nocodb_scaffold/Rakefile +7 -0
- data/examples/nocodb/nocodb_scaffold/app/api/app.rb +1139 -0
- data/examples/nocodb/nocodb_scaffold/app/models/email_template.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/faq.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/feature.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/idea.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/itinerary_day.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/route.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/subscriber.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/tour.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models/webhook.rb +6 -0
- data/examples/nocodb/nocodb_scaffold/app/models_loader.rb +3 -0
- data/examples/nocodb/nocodb_scaffold/config/database.yml +11 -0
- data/examples/nocodb/nocodb_scaffold/config.ru +9 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152012_create_features.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152013_create_tours.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152014_create_routes.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152015_create_itinerary_days.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152016_create_subscribers.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152017_create_email_templates.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152018_create_faqs.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152019_create_webhooks.rb +10 -0
- data/examples/nocodb/nocodb_scaffold/db/migrate/20250808152020_create_ideas.rb +10 -0
- data/examples/nocodb/swagger.json +4378 -0
- data/examples/production_ready_example.rb +78 -58
- 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/simple_demo_api.rb +40 -7
- data/examples/strict_validation_examples.rb +104 -0
- data/examples/user_api.rb +130 -132
- 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 +44 -58
- data/lib/rapitapir/cli/command.rb +392 -6
- data/lib/rapitapir/cli/mcp_export.rb +18 -0
- data/lib/rapitapir/cli/scaffold_generator.rb +639 -0
- data/lib/rapitapir/cli/validator.rb +3 -7
- data/lib/rapitapir/core/endpoint.rb +59 -6
- data/lib/rapitapir/core/enhanced_endpoint.rb +3 -7
- data/lib/rapitapir/dsl/enhanced_structures.rb +1 -1
- 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/openapi/schema_generator.rb +46 -2
- data/lib/rapitapir/schema.rb +2 -2
- data/lib/rapitapir/server/enhanced_rack_adapter.rb +11 -8
- data/lib/rapitapir/server/middleware.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 -20
- 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 +3 -2
- metadata +142 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'lib/rapitapir'
|
|
3
|
+
require_relative '../lib/rapitapir'
|
|
4
4
|
|
|
5
5
|
puts '🌟 RapiTapir Production-Ready API Example'
|
|
6
6
|
puts '=' * 45
|
|
@@ -25,71 +25,91 @@ Error = RapiTapir::Schema.define do
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# Define a complete REST API using the fluent DSL
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
#
|
|
29
|
+
# GET /api/v1/users - List users with pagination
|
|
30
|
+
RapiTapir.get('/api/v1/users')
|
|
31
|
+
.bearer_auth('API Token Required')
|
|
32
|
+
.tags('users', 'rest-api')
|
|
33
|
+
.summary('List users')
|
|
34
|
+
.description('Retrieve paginated list of users')
|
|
35
|
+
.query(:page, RapiTapir::Types.integer, min: 1, default: 1, description: 'Page number')
|
|
36
|
+
.query(:per_page, RapiTapir::Types.integer, min: 1, max: 100, default: 20, description: 'Items per page')
|
|
37
|
+
.query(:search, RapiTapir::Types.optional(RapiTapir::Types.string), description: 'Search users by name')
|
|
38
|
+
.ok(RapiTapir::Types.array(User), description: 'List of users')
|
|
39
|
+
.bad_request(Error, description: 'Invalid query parameters')
|
|
40
|
+
.unauthorized(Error, description: 'Invalid or missing token')
|
|
41
|
+
.forbidden(Error, description: 'Insufficient permissions')
|
|
42
|
+
.internal_server_error(Error, description: 'Internal server error')
|
|
43
|
+
.build
|
|
31
44
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
# GET /api/v1/users/:id - Get specific user
|
|
46
|
+
RapiTapir.get('/api/v1/users/:id')
|
|
47
|
+
.bearer_auth('API Token Required')
|
|
48
|
+
.tags('users', 'rest-api')
|
|
49
|
+
.summary('Get user by ID')
|
|
50
|
+
.description('Retrieve a specific user by their unique identifier')
|
|
51
|
+
.path_param(:id, RapiTapir::Types.uuid, description: 'User unique identifier')
|
|
52
|
+
.ok(User, description: 'User details')
|
|
53
|
+
.not_found(Error, description: 'User not found')
|
|
54
|
+
.unauthorized(Error, description: 'Invalid or missing token')
|
|
55
|
+
.forbidden(Error, description: 'Insufficient permissions')
|
|
56
|
+
.internal_server_error(Error, description: 'Internal server error')
|
|
57
|
+
.build
|
|
37
58
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
# POST /api/v1/users - Create new user
|
|
60
|
+
RapiTapir.post('/api/v1/users')
|
|
61
|
+
.bearer_auth('API Token Required')
|
|
62
|
+
.tags('users', 'rest-api')
|
|
63
|
+
.summary('Create user')
|
|
64
|
+
.description('Create a new user account')
|
|
65
|
+
.json_body(CreateUser, description: 'User data')
|
|
66
|
+
.requires_scope('users:write')
|
|
67
|
+
.created(User, description: 'User created successfully')
|
|
68
|
+
.bad_request(Error, description: 'Invalid user data')
|
|
69
|
+
.unprocessable_entity(Error, description: 'Validation failed')
|
|
70
|
+
.unauthorized(Error, description: 'Invalid or missing token')
|
|
71
|
+
.forbidden(Error, description: 'Insufficient permissions')
|
|
72
|
+
.internal_server_error(Error, description: 'Internal server error')
|
|
73
|
+
.build
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
# PUT /api/v1/users/:id - Update user
|
|
76
|
+
RapiTapir.put('/api/v1/users/:id')
|
|
77
|
+
.bearer_auth('API Token Required')
|
|
78
|
+
.tags('users', 'rest-api')
|
|
79
|
+
.summary('Update user')
|
|
80
|
+
.description('Update an existing user\'s information')
|
|
81
|
+
.path_param(:id, RapiTapir::Types.uuid, description: 'User unique identifier')
|
|
82
|
+
.json_body(CreateUser, description: 'Updated user data')
|
|
83
|
+
.requires_scope('users:write')
|
|
84
|
+
.ok(User, description: 'User updated successfully')
|
|
85
|
+
.not_found(Error, description: 'User not found')
|
|
86
|
+
.unprocessable_entity(Error, description: 'Validation failed')
|
|
87
|
+
.unauthorized(Error, description: 'Invalid or missing token')
|
|
88
|
+
.forbidden(Error, description: 'Insufficient permissions')
|
|
89
|
+
.internal_server_error(Error, description: 'Internal server error')
|
|
90
|
+
.build
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.path_param(:id, :uuid, description: 'User unique identifier')
|
|
71
|
-
.json_body(CreateUser, description: 'Updated user data')
|
|
72
|
-
.requires_scope('users:write')
|
|
73
|
-
.ok(User, description: 'User updated successfully')
|
|
74
|
-
.not_found(Error, description: 'User not found')
|
|
75
|
-
.unprocessable_entity(Error, description: 'Validation failed')
|
|
76
|
-
|
|
77
|
-
# DELETE /api/v1/users/{id} - Delete user
|
|
78
|
-
delete('/{id}')
|
|
79
|
-
.summary('Delete user')
|
|
80
|
-
.description('Permanently delete a user account')
|
|
81
|
-
.path_param(:id, :uuid, description: 'User unique identifier')
|
|
82
|
-
.requires_scope('users:delete')
|
|
83
|
-
.no_content(description: 'User deleted successfully')
|
|
84
|
-
.not_found(Error, description: 'User not found')
|
|
85
|
-
end
|
|
92
|
+
# DELETE /api/v1/users/:id - Delete user
|
|
93
|
+
RapiTapir.delete('/api/v1/users/:id')
|
|
94
|
+
.bearer_auth('API Token Required')
|
|
95
|
+
.tags('users', 'rest-api')
|
|
96
|
+
.summary('Delete user')
|
|
97
|
+
.description('Permanently delete a user account')
|
|
98
|
+
.path_param(:id, RapiTapir::Types.uuid, description: 'User unique identifier')
|
|
99
|
+
.requires_scope('users:delete')
|
|
100
|
+
.no_content(description: 'User deleted successfully')
|
|
101
|
+
.not_found(Error, description: 'User not found')
|
|
102
|
+
.unauthorized(Error, description: 'Invalid or missing token')
|
|
103
|
+
.forbidden(Error, description: 'Insufficient permissions')
|
|
104
|
+
.internal_server_error(Error, description: 'Internal server error')
|
|
105
|
+
.build
|
|
86
106
|
|
|
87
107
|
puts '✅ Defined complete REST API with 5 endpoints'
|
|
88
108
|
puts ' - GET /api/v1/users (list with pagination)'
|
|
89
|
-
puts ' - GET /api/v1/users
|
|
109
|
+
puts ' - GET /api/v1/users/:id (get by ID)'
|
|
90
110
|
puts ' - POST /api/v1/users (create)'
|
|
91
|
-
puts ' - PUT /api/v1/users
|
|
92
|
-
puts ' - DELETE /api/v1/users
|
|
111
|
+
puts ' - PUT /api/v1/users/:id (update)'
|
|
112
|
+
puts ' - DELETE /api/v1/users/:id (delete)'
|
|
93
113
|
|
|
94
114
|
puts "\n✅ Features implemented:"
|
|
95
115
|
puts ' - Bearer token authentication'
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Rails 8 + RapiTapir Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## 🚀 How to Fix the `uninitialized constant RapiTapir::Server::Rails::ControllerBase` Error
|
|
4
|
+
|
|
5
|
+
The error you're encountering is due to the **loading order**. RapiTapir's Rails integration requires Rails to be loaded first.
|
|
6
|
+
|
|
7
|
+
### ✅ **Solution: Correct Loading Order**
|
|
8
|
+
|
|
9
|
+
In your Rails application, ensure this loading order:
|
|
10
|
+
|
|
11
|
+
#### 1. In your `Gemfile`:
|
|
12
|
+
```ruby
|
|
13
|
+
source 'https://rubygems.org'
|
|
14
|
+
ruby '3.2.0'
|
|
15
|
+
|
|
16
|
+
gem 'rails', '~> 8.0.0' # Rails 8
|
|
17
|
+
gem 'rapitapir', '~> 1.0' # RapiTapir after Rails
|
|
18
|
+
|
|
19
|
+
# Other gems...
|
|
20
|
+
gem 'sqlite3'
|
|
21
|
+
gem 'puma'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### 2. In your application (or initializer):
|
|
25
|
+
```ruby
|
|
26
|
+
# This is already handled by Rails bundler, but if you need manual loading:
|
|
27
|
+
|
|
28
|
+
# 1. Rails loads first (via bundle/require in application.rb)
|
|
29
|
+
require 'rails/all'
|
|
30
|
+
|
|
31
|
+
# 2. RapiTapir loads after Rails
|
|
32
|
+
require 'rapitapir' # Usually handled by bundler
|
|
33
|
+
|
|
34
|
+
# 3. Now you can use RapiTapir classes
|
|
35
|
+
class ApplicationController < RapiTapir::Server::Rails::ControllerBase
|
|
36
|
+
# This works!
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 🧪 **Test with Our Runnable Example**
|
|
41
|
+
|
|
42
|
+
The easiest way to verify everything works:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cd examples/rails
|
|
46
|
+
ruby traditional_app_runnable.rb
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This should start successfully and show:
|
|
50
|
+
```
|
|
51
|
+
🚀 Starting Traditional Rails App with RapiTapir on http://localhost:3000
|
|
52
|
+
📚 API Documentation: http://localhost:3000/docs
|
|
53
|
+
📋 OpenAPI Spec: http://localhost:3000/openapi.json
|
|
54
|
+
🏥 Health Check: http://localhost:3000/health
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 🔧 **For New Rails 8 Applications**
|
|
58
|
+
|
|
59
|
+
#### 1. Create Rails App
|
|
60
|
+
```bash
|
|
61
|
+
rails new my_api --api
|
|
62
|
+
cd my_api
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### 2. Add RapiTapir to Gemfile
|
|
66
|
+
```ruby
|
|
67
|
+
# Gemfile
|
|
68
|
+
gem 'rapitapir', '~> 1.0'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### 3. Install
|
|
72
|
+
```bash
|
|
73
|
+
bundle install
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### 4. Update ApplicationController
|
|
77
|
+
```ruby
|
|
78
|
+
# app/controllers/application_controller.rb
|
|
79
|
+
class ApplicationController < RapiTapir::Server::Rails::ControllerBase
|
|
80
|
+
rapitapir do
|
|
81
|
+
development_defaults! if Rails.env.development?
|
|
82
|
+
|
|
83
|
+
# Global error responses
|
|
84
|
+
error_out(json_body(error: T.string), 404)
|
|
85
|
+
error_out(json_body(error: T.string, errors: T.array(T.string).optional), 422)
|
|
86
|
+
|
|
87
|
+
# Health endpoint
|
|
88
|
+
GET('/health')
|
|
89
|
+
.out(json_body(status: T.string, timestamp: T.string))
|
|
90
|
+
.summary("Health check")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def health_check
|
|
94
|
+
{ status: 'ok', timestamp: Time.current.iso8601 }
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### 5. Create API Controllers
|
|
100
|
+
```ruby
|
|
101
|
+
# app/controllers/api/v1/users_controller.rb
|
|
102
|
+
class Api::V1::UsersController < ApplicationController
|
|
103
|
+
rapitapir do
|
|
104
|
+
user_type = T.hash(id: T.integer, name: T.string, email: T.string)
|
|
105
|
+
|
|
106
|
+
GET('/api/v1/users')
|
|
107
|
+
.out(json_body(users: T.array(user_type)))
|
|
108
|
+
.summary("List users")
|
|
109
|
+
.tag("Users")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def list_users
|
|
113
|
+
{ users: [{ id: 1, name: "Test User", email: "test@example.com" }] }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### 6. Update Routes
|
|
119
|
+
```ruby
|
|
120
|
+
# config/routes.rb
|
|
121
|
+
Rails.application.routes.draw do
|
|
122
|
+
rapitapir_routes_for ApplicationController
|
|
123
|
+
|
|
124
|
+
namespace :api do
|
|
125
|
+
namespace :v1 do
|
|
126
|
+
rapitapir_routes_for 'Api::V1::UsersController'
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### 7. Start Server
|
|
133
|
+
```bash
|
|
134
|
+
rails server
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Visit:
|
|
138
|
+
- 🏥 Health: http://localhost:3000/health
|
|
139
|
+
- 📚 Docs: http://localhost:3000/docs
|
|
140
|
+
- 👥 Users: http://localhost:3000/api/v1/users
|
|
141
|
+
|
|
142
|
+
### ⚠️ **Common Issues & Solutions**
|
|
143
|
+
|
|
144
|
+
#### Issue: `uninitialized constant RapiTapir::Server::Rails::ControllerBase`
|
|
145
|
+
**Solution**: Make sure Rails is loaded before RapiTapir. In most Rails apps, this happens automatically via bundler.
|
|
146
|
+
|
|
147
|
+
#### Issue: `NoMethodError: undefined method 'rapitapir_routes_for'`
|
|
148
|
+
**Solution**: Ensure RapiTapir's Rails integration is loaded. Add to `config/application.rb`:
|
|
149
|
+
```ruby
|
|
150
|
+
require 'rapitapir'
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Issue: Documentation not showing up
|
|
154
|
+
**Solution**: Make sure you have `development_defaults!` in your rapitapir block.
|
|
155
|
+
|
|
156
|
+
### 🎉 **Benefits of Rails 8 + RapiTapir**
|
|
157
|
+
|
|
158
|
+
- ✅ **Modern Rails**: Latest Rails 8 features and performance
|
|
159
|
+
- ✅ **Type Safety**: Automatic input validation and output schemas
|
|
160
|
+
- ✅ **Auto Documentation**: Swagger UI and OpenAPI 3.0 specs
|
|
161
|
+
- ✅ **Clean Syntax**: Sinatra-like DSL in Rails controllers
|
|
162
|
+
- ✅ **Zero Config**: Works out of the box with `development_defaults!`
|
|
163
|
+
- ✅ **Production Ready**: Error handling, health checks, monitoring
|
|
164
|
+
|
|
165
|
+
The combination of Rails 8 and RapiTapir gives you the best of both worlds: Rails' maturity and ecosystem with RapiTapir's elegant API design! 🚀
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Instructions for using RapiTapir with Rails
|
|
4
|
+
#
|
|
5
|
+
# To fix the "uninitialized constant RapiTapir::Server::Rails::ControllerBase" error:
|
|
6
|
+
#
|
|
7
|
+
# 1. In your Rails application, make sure to require 'rapitapir' AFTER Rails is loaded
|
|
8
|
+
# 2. In your Gemfile, add:
|
|
9
|
+
# gem 'rapitapir'
|
|
10
|
+
# 3. In your ApplicationController or in an initializer, add:
|
|
11
|
+
# require 'rapitapir' (only if needed - bundler usually handles this)
|
|
12
|
+
#
|
|
13
|
+
# The error occurs because RapiTapir's Rails integration requires Rails and ActiveSupport
|
|
14
|
+
# to be loaded first.
|
|
15
|
+
|
|
16
|
+
# For the traditional_app_runnable.rb example, the require order should be:
|
|
17
|
+
|
|
18
|
+
require 'bundler/inline'
|
|
19
|
+
|
|
20
|
+
gemfile do
|
|
21
|
+
source 'https://rubygems.org'
|
|
22
|
+
gem 'rails', '~> 8.0'
|
|
23
|
+
gem 'sqlite3'
|
|
24
|
+
gem 'puma'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Load Rails first
|
|
28
|
+
require 'rails/all'
|
|
29
|
+
|
|
30
|
+
# THEN load RapiTapir (this is the key!)
|
|
31
|
+
require_relative '../../../lib/rapitapir'
|
|
32
|
+
|
|
33
|
+
# Now you can use RapiTapir::Server::Rails::ControllerBase
|
|
34
|
+
|
|
35
|
+
puts "✅ This order works correctly!"
|