rapitapir 2.0.0 → 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_todo.yml +5 -0
- data/CHANGELOG.md +29 -1
- data/README.md +23 -4
- data/RUBY_WEEKLY_LAUNCH_POST.md +43 -62
- 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/blueprint.md +92 -4
- data/docs/implementation-status.md +1 -1
- 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/simple_demo_api.rb +40 -7
- data/examples/user_api.rb +130 -132
- data/lib/rapitapir/auth/oauth2.rb +1 -1
- data/lib/rapitapir/cli/command.rb +30 -4
- data/lib/rapitapir/cli/scaffold_generator.rb +639 -0
- data/lib/rapitapir/cli/validator.rb +1 -1
- data/lib/rapitapir/core/enhanced_endpoint.rb +1 -1
- data/lib/rapitapir/dsl/enhanced_structures.rb +1 -1
- data/lib/rapitapir/openapi/schema_generator.rb +46 -2
- data/lib/rapitapir/server/enhanced_rack_adapter.rb +11 -8
- data/lib/rapitapir/server/middleware.rb +2 -2
- data/lib/rapitapir/types/auto_derivation.rb +2 -4
- data/lib/rapitapir/version.rb +1 -1
- data/rapitapir.gemspec +3 -2
- metadata +70 -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'
|
data/examples/simple_demo_api.rb
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'lib/rapitapir'
|
|
4
|
-
|
|
3
|
+
require_relative '../lib/rapitapir'
|
|
4
|
+
|
|
5
|
+
USER_LIST_TYPE = RapiTapir::Types.array(
|
|
6
|
+
RapiTapir::Types.hash({
|
|
7
|
+
'id' => RapiTapir::Types.integer,
|
|
8
|
+
'name' => RapiTapir::Types.string,
|
|
9
|
+
'email' => RapiTapir::Types.string
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
USER_TYPE = RapiTapir::Types.hash({
|
|
14
|
+
'id' => RapiTapir::Types.integer,
|
|
15
|
+
'name' => RapiTapir::Types.string,
|
|
16
|
+
'email' => RapiTapir::Types.string
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
CREATE_USER_TYPE = RapiTapir::Types.hash({
|
|
20
|
+
'name' => RapiTapir::Types.string,
|
|
21
|
+
'email' => RapiTapir::Types.string,
|
|
22
|
+
'password' => RapiTapir::Types.string
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
ERROR_TYPE = RapiTapir::Types.hash({
|
|
26
|
+
'error' => RapiTapir::Types.string,
|
|
27
|
+
'message' => RapiTapir::Types.string
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
VALIDATION_ERROR_TYPE = RapiTapir::Types.hash({
|
|
31
|
+
'error' => RapiTapir::Types.string,
|
|
32
|
+
'validation_errors' => RapiTapir::Types.array(RapiTapir::Types.string)
|
|
33
|
+
})
|
|
5
34
|
|
|
6
35
|
# Simple API endpoints for demonstration
|
|
7
36
|
RapiTapir.get('/users')
|
|
8
|
-
.
|
|
37
|
+
.ok(USER_LIST_TYPE)
|
|
9
38
|
.summary('List all users')
|
|
10
39
|
.description('Retrieve a paginated list of all users in the system')
|
|
40
|
+
.build
|
|
11
41
|
|
|
12
42
|
RapiTapir.post('/users')
|
|
13
|
-
.
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
43
|
+
.json_body(CREATE_USER_TYPE)
|
|
44
|
+
.created(USER_TYPE)
|
|
45
|
+
.bad_request(VALIDATION_ERROR_TYPE)
|
|
46
|
+
.unprocessable_entity(ERROR_TYPE)
|
|
17
47
|
.summary('Create new user')
|
|
18
48
|
.description('Create a new user account with the provided information')
|
|
49
|
+
.build
|
|
50
|
+
|
|
51
|
+
puts "✅ Defined #{RapiTapir.endpoints.size} endpoints"
|
data/examples/user_api.rb
CHANGED
|
@@ -5,180 +5,178 @@ require_relative '../lib/rapitapir'
|
|
|
5
5
|
|
|
6
6
|
# Example: User Management API
|
|
7
7
|
module UserAPI
|
|
8
|
-
|
|
8
|
+
# Shared type definitions
|
|
9
|
+
USER_TYPE = RapiTapir::Types.hash({
|
|
10
|
+
'id' => RapiTapir::Types.integer,
|
|
11
|
+
'name' => RapiTapir::Types.string,
|
|
12
|
+
'email' => RapiTapir::Types.string
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
USER_DETAIL_TYPE = RapiTapir::Types.hash({
|
|
16
|
+
'id' => RapiTapir::Types.integer,
|
|
17
|
+
'name' => RapiTapir::Types.string,
|
|
18
|
+
'email' => RapiTapir::Types.string,
|
|
19
|
+
'created_at' => RapiTapir::Types.datetime
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
CREATE_USER_TYPE = RapiTapir::Types.hash({
|
|
23
|
+
'name' => RapiTapir::Types.string,
|
|
24
|
+
'email' => RapiTapir::Types.string,
|
|
25
|
+
'password' => RapiTapir::Types.string
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
LOGIN_TYPE = RapiTapir::Types.hash({
|
|
29
|
+
'email' => RapiTapir::Types.string,
|
|
30
|
+
'password' => RapiTapir::Types.string
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
LOGIN_RESULT_TYPE = RapiTapir::Types.hash({
|
|
34
|
+
'user' => USER_TYPE,
|
|
35
|
+
'token' => RapiTapir::Types.string,
|
|
36
|
+
'expires_at' => RapiTapir::Types.datetime
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
ERROR_TYPE = RapiTapir::Types.hash({
|
|
40
|
+
'error' => RapiTapir::Types.string
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
VALIDATION_ERROR_TYPE = RapiTapir::Types.hash({
|
|
44
|
+
'error' => RapiTapir::Types.string,
|
|
45
|
+
'validation_errors' => RapiTapir::Types.array(
|
|
46
|
+
RapiTapir::Types.hash({
|
|
47
|
+
'field' => RapiTapir::Types.string,
|
|
48
|
+
'message' => RapiTapir::Types.string
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
USER_LIST_TYPE = RapiTapir::Types.hash({
|
|
54
|
+
'users' => RapiTapir::Types.array(USER_TYPE),
|
|
55
|
+
'total' => RapiTapir::Types.integer,
|
|
56
|
+
'page' => RapiTapir::Types.integer,
|
|
57
|
+
'limit' => RapiTapir::Types.integer
|
|
58
|
+
})
|
|
9
59
|
|
|
10
60
|
# GET /users - List all users
|
|
11
61
|
LIST_USERS = RapiTapir.get('/users')
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
.
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
total: :integer,
|
|
20
|
-
page: :integer,
|
|
21
|
-
limit: :integer
|
|
22
|
-
}))
|
|
23
|
-
.error_out(401, json_body({ error: :string }))
|
|
24
|
-
.error_out(500, json_body({ error: :string }))
|
|
62
|
+
.query(:page, RapiTapir::Types.optional(RapiTapir::Types.integer))
|
|
63
|
+
.query(:limit, RapiTapir::Types.optional(RapiTapir::Types.integer))
|
|
64
|
+
.query(:search, RapiTapir::Types.optional(RapiTapir::Types.string))
|
|
65
|
+
.header(:authorization, RapiTapir::Types.string)
|
|
66
|
+
.ok(USER_LIST_TYPE)
|
|
67
|
+
.unauthorized(ERROR_TYPE)
|
|
68
|
+
.internal_server_error(ERROR_TYPE)
|
|
25
69
|
.description('Retrieve a paginated list of users')
|
|
26
70
|
.summary('List users')
|
|
27
|
-
.
|
|
71
|
+
.tags('users')
|
|
72
|
+
.build
|
|
28
73
|
|
|
29
74
|
# GET /users/:id - Get specific user
|
|
30
75
|
GET_USER = RapiTapir.get('/users/:id')
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
.
|
|
34
|
-
.
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
.error_out(500, json_body({ error: :string }))
|
|
76
|
+
.path_param(:id, RapiTapir::Types.integer)
|
|
77
|
+
.header(:authorization, RapiTapir::Types.string)
|
|
78
|
+
.ok(USER_DETAIL_TYPE)
|
|
79
|
+
.unauthorized(ERROR_TYPE)
|
|
80
|
+
.not_found(ERROR_TYPE)
|
|
81
|
+
.internal_server_error(ERROR_TYPE)
|
|
38
82
|
.description('Retrieve a specific user by ID')
|
|
39
83
|
.summary('Get user')
|
|
40
|
-
.
|
|
84
|
+
.tags('users')
|
|
85
|
+
.build
|
|
41
86
|
|
|
42
87
|
# POST /users - Create new user
|
|
43
88
|
CREATE_USER = RapiTapir.post('/users')
|
|
44
|
-
.
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
.
|
|
50
|
-
.
|
|
51
|
-
.error_out(422, json_body({ error: :string,
|
|
52
|
-
validation_errors: [{ field: :string, message: :string }] }))
|
|
53
|
-
.error_out(500, json_body({ error: :string }))
|
|
89
|
+
.header(:authorization, RapiTapir::Types.string)
|
|
90
|
+
.json_body(CREATE_USER_TYPE)
|
|
91
|
+
.created(USER_DETAIL_TYPE)
|
|
92
|
+
.bad_request(ERROR_TYPE)
|
|
93
|
+
.unauthorized(ERROR_TYPE)
|
|
94
|
+
.unprocessable_entity(VALIDATION_ERROR_TYPE)
|
|
95
|
+
.internal_server_error(ERROR_TYPE)
|
|
54
96
|
.description('Create a new user account')
|
|
55
97
|
.summary('Create user')
|
|
56
|
-
.
|
|
98
|
+
.tags('users')
|
|
99
|
+
.build
|
|
57
100
|
|
|
58
101
|
# PUT /users/:id - Update user
|
|
59
102
|
UPDATE_USER = RapiTapir.put('/users/:id')
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
103
|
+
.path_param(:id, RapiTapir::Types.integer)
|
|
104
|
+
.header(:authorization, RapiTapir::Types.string)
|
|
105
|
+
.json_body(RapiTapir::Types.hash({
|
|
106
|
+
'name' => RapiTapir::Types.string,
|
|
107
|
+
'email' => RapiTapir::Types.string
|
|
108
|
+
}))
|
|
109
|
+
.ok(RapiTapir::Types.hash({
|
|
110
|
+
'id' => RapiTapir::Types.integer,
|
|
111
|
+
'name' => RapiTapir::Types.string,
|
|
112
|
+
'email' => RapiTapir::Types.string,
|
|
113
|
+
'updated_at' => RapiTapir::Types.datetime
|
|
114
|
+
}))
|
|
115
|
+
.bad_request(ERROR_TYPE)
|
|
116
|
+
.unauthorized(ERROR_TYPE)
|
|
117
|
+
.not_found(ERROR_TYPE)
|
|
118
|
+
.unprocessable_entity(VALIDATION_ERROR_TYPE)
|
|
119
|
+
.internal_server_error(ERROR_TYPE)
|
|
72
120
|
.description('Update an existing user')
|
|
73
121
|
.summary('Update user')
|
|
74
|
-
.
|
|
122
|
+
.tags('users')
|
|
123
|
+
.build
|
|
75
124
|
|
|
76
125
|
# DELETE /users/:id - Delete user
|
|
77
126
|
DELETE_USER = RapiTapir.delete('/users/:id')
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
.
|
|
83
|
-
.
|
|
127
|
+
.path_param(:id, RapiTapir::Types.integer)
|
|
128
|
+
.header(:authorization, RapiTapir::Types.string)
|
|
129
|
+
.no_content
|
|
130
|
+
.unauthorized(ERROR_TYPE)
|
|
131
|
+
.not_found(ERROR_TYPE)
|
|
132
|
+
.internal_server_error(ERROR_TYPE)
|
|
84
133
|
.description('Delete a user account')
|
|
85
134
|
.summary('Delete user')
|
|
86
|
-
.
|
|
135
|
+
.tags('users')
|
|
136
|
+
.build
|
|
87
137
|
|
|
88
138
|
# POST /users/login - User authentication
|
|
89
139
|
LOGIN_USER = RapiTapir.post('/users/login')
|
|
90
|
-
.
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
token: :string,
|
|
96
|
-
expires_at: :datetime
|
|
97
|
-
}))
|
|
98
|
-
.error_out(400, json_body({ error: :string }))
|
|
99
|
-
.error_out(401, json_body({ error: :string }))
|
|
100
|
-
.error_out(500, json_body({ error: :string }))
|
|
140
|
+
.json_body(LOGIN_TYPE)
|
|
141
|
+
.ok(LOGIN_RESULT_TYPE)
|
|
142
|
+
.bad_request(ERROR_TYPE)
|
|
143
|
+
.unauthorized(ERROR_TYPE)
|
|
144
|
+
.internal_server_error(ERROR_TYPE)
|
|
101
145
|
.description('Authenticate user and return access token')
|
|
102
146
|
.summary('User login')
|
|
103
|
-
.
|
|
147
|
+
.tags('authentication')
|
|
148
|
+
.build
|
|
104
149
|
|
|
105
150
|
# Example usage and validation
|
|
106
151
|
def self.demo
|
|
107
152
|
puts '=== RapiTapir User API Demo ==='
|
|
108
153
|
puts
|
|
109
154
|
|
|
110
|
-
# Example 1:
|
|
111
|
-
puts '1.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
name: 'John Doe',
|
|
118
|
-
email: 'john@example.com',
|
|
119
|
-
created_at: DateTime.now
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
begin
|
|
123
|
-
CREATE_USER.validate!(input_data, output_data)
|
|
124
|
-
puts '✓ Validation passed'
|
|
125
|
-
rescue StandardError => e
|
|
126
|
-
puts "✗ Validation failed: #{e.message}"
|
|
127
|
-
end
|
|
155
|
+
# Example 1: Endpoint structure
|
|
156
|
+
puts '1. Endpoint structure:'
|
|
157
|
+
puts ' GET /users:'
|
|
158
|
+
puts " Method: #{LIST_USERS.method} #{LIST_USERS.path}"
|
|
159
|
+
puts " Inputs: #{LIST_USERS.inputs.length}"
|
|
160
|
+
puts " Outputs: #{LIST_USERS.outputs.length}"
|
|
161
|
+
puts " Error responses: #{LIST_USERS.errors.length}"
|
|
128
162
|
puts
|
|
129
163
|
|
|
130
|
-
# Example 2:
|
|
131
|
-
puts '2.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
begin
|
|
137
|
-
CREATE_USER.validate!(invalid_input, output_data)
|
|
138
|
-
puts '✓ Validation passed'
|
|
139
|
-
rescue StandardError => e
|
|
140
|
-
puts "✗ Validation failed: #{e.message}"
|
|
141
|
-
end
|
|
164
|
+
# Example 2: Endpoint metadata
|
|
165
|
+
puts '2. Endpoint metadata:'
|
|
166
|
+
puts " Summary: #{GET_USER.metadata[:summary]}"
|
|
167
|
+
puts " Description: #{GET_USER.metadata[:description]}"
|
|
142
168
|
puts
|
|
143
169
|
|
|
144
|
-
# Example 3:
|
|
145
|
-
puts '3.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
users: [
|
|
149
|
-
{ id: 1, name: 'John Doe', email: 'john@example.com' },
|
|
150
|
-
{ id: 2, name: 'Jane Smith', email: 'jane@example.com' }
|
|
151
|
-
],
|
|
152
|
-
total: 2,
|
|
153
|
-
page: 1,
|
|
154
|
-
limit: 10
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
begin
|
|
158
|
-
LIST_USERS.validate!(list_input, list_output)
|
|
159
|
-
puts '✓ Validation passed'
|
|
160
|
-
rescue StandardError => e
|
|
161
|
-
puts "✗ Validation failed: #{e.message}"
|
|
162
|
-
end
|
|
163
|
-
puts
|
|
170
|
+
# Example 3: Built-in validation
|
|
171
|
+
puts '3. Endpoint validation:'
|
|
172
|
+
CREATE_USER.validate!
|
|
173
|
+
puts ' CREATE_USER passed built-in validation ✓'
|
|
164
174
|
|
|
165
|
-
# Example 4:
|
|
166
|
-
puts '4. Endpoint metadata:'
|
|
167
|
-
puts 'GET /users:'
|
|
168
|
-
puts " Description: #{GET_USER.metadata[:description]}"
|
|
169
|
-
puts " Summary: #{GET_USER.metadata[:summary]}"
|
|
170
|
-
puts " Tag: #{GET_USER.metadata[:tag]}"
|
|
171
|
-
puts " Inputs: #{GET_USER.inputs.length}"
|
|
172
|
-
puts " Outputs: #{GET_USER.outputs.length}"
|
|
173
|
-
puts " Error responses: #{GET_USER.errors.length}"
|
|
175
|
+
# Example 4: All endpoints summary
|
|
174
176
|
puts
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
json_output = CREATE_USER.outputs.find { |o| o.kind == :json }
|
|
179
|
-
if json_output
|
|
180
|
-
serialized = json_output.serialize(output_data)
|
|
181
|
-
puts "JSON: #{serialized}"
|
|
177
|
+
puts '4. All endpoints:'
|
|
178
|
+
[LIST_USERS, GET_USER, CREATE_USER, UPDATE_USER, DELETE_USER, LOGIN_USER].each do |ep|
|
|
179
|
+
puts " #{ep.method.to_s.ljust(6).upcase} #{ep.path}"
|
|
182
180
|
end
|
|
183
181
|
puts
|
|
184
182
|
|
|
@@ -171,10 +171,13 @@ module RapiTapir
|
|
|
171
171
|
when 'docs'
|
|
172
172
|
docs_type = args.shift || 'html'
|
|
173
173
|
generate_docs(docs_type)
|
|
174
|
+
when 'scaffold'
|
|
175
|
+
generate_scaffold(args)
|
|
174
176
|
when 'mcp'
|
|
175
177
|
generate_mcp
|
|
176
178
|
else
|
|
177
179
|
puts "Error: Unknown generation type: #{type}"
|
|
180
|
+
# Keep this list stable for backward compatibility with existing tests
|
|
178
181
|
puts 'Available types: openapi, client, docs, mcp'
|
|
179
182
|
exit 1
|
|
180
183
|
end
|
|
@@ -404,6 +407,31 @@ module RapiTapir
|
|
|
404
407
|
end
|
|
405
408
|
end
|
|
406
409
|
|
|
410
|
+
def generate_scaffold(_args)
|
|
411
|
+
unless @options[:input]
|
|
412
|
+
puts 'Error: --input must point to an OpenAPI/Swagger JSON file'
|
|
413
|
+
exit 1
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
output_dir = @options[:output] || 'rapitapir_sinatra_app'
|
|
417
|
+
|
|
418
|
+
begin
|
|
419
|
+
require_relative 'scaffold_generator'
|
|
420
|
+
generator = RapiTapir::CLI::ScaffoldGenerator.new(
|
|
421
|
+
openapi_path: @options[:input],
|
|
422
|
+
output_dir: output_dir,
|
|
423
|
+
config: @options[:config]
|
|
424
|
+
)
|
|
425
|
+
generator.generate!
|
|
426
|
+
puts "Scaffold generated at #{output_dir}"
|
|
427
|
+
puts "Next steps:\n 1) cd #{output_dir}\n 2) bundle install\n 3) bundle exec rake db:create db:migrate\n 4) bundle exec rackup"
|
|
428
|
+
rescue StandardError => e
|
|
429
|
+
puts "Error generating scaffold: #{e.message}"
|
|
430
|
+
puts e.backtrace.first(5).join("\n")
|
|
431
|
+
exit 1
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
407
435
|
def create_markdown_generator(endpoints)
|
|
408
436
|
require_relative '../docs/markdown_generator'
|
|
409
437
|
RapiTapir::Docs::MarkdownGenerator.new(
|
|
@@ -500,9 +528,8 @@ module RapiTapir
|
|
|
500
528
|
file_dir = File.dirname(File.expand_path(file_path))
|
|
501
529
|
Dir.chdir(file_dir) do
|
|
502
530
|
# Execute the file content using load instead of eval for safety
|
|
503
|
-
# rubocop:disable Security/Eval
|
|
531
|
+
# rubocop:disable-next Security/Eval
|
|
504
532
|
eval(content, TOPLEVEL_BINDING, file_path)
|
|
505
|
-
# rubocop:enable Security/Eval
|
|
506
533
|
end
|
|
507
534
|
|
|
508
535
|
find_endpoints_in_variables(content)
|
|
@@ -540,9 +567,8 @@ module RapiTapir
|
|
|
540
567
|
|
|
541
568
|
return nil unless global_endpoints_var
|
|
542
569
|
|
|
543
|
-
# rubocop:disable Security/Eval
|
|
570
|
+
# rubocop:disable-next Security/Eval
|
|
544
571
|
endpoints = eval(global_endpoints_var.to_s)
|
|
545
|
-
# rubocop:enable Security/Eval
|
|
546
572
|
normalize_endpoints_array(endpoints)
|
|
547
573
|
end
|
|
548
574
|
|