rapitapir 0.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +57 -0
- data/CHANGELOG.md +94 -0
- data/CLEANUP_SUMMARY.md +155 -0
- data/CONTRIBUTING.md +280 -0
- data/LICENSE +21 -0
- data/README.md +485 -0
- data/debug_hash.rb +20 -0
- data/docs/EXTENSION_COMPARISON.md +388 -0
- data/docs/SINATRA_EXTENSION.md +467 -0
- data/docs/archive/PHASE_1_2_COMPLETE.md +77 -0
- data/docs/archive/PHASE_1_3_COMPLETE.md +152 -0
- data/docs/archive/PHASE_2_1_OBSERVABILITY_COMPLETED.md +203 -0
- data/docs/archive/PHASE_2_SUMMARY.md +209 -0
- data/docs/archive/REFACTORING_SUMMARY.md +184 -0
- data/docs/archive/phase_1_3_plan.md +136 -0
- data/docs/archive/sinatra_extension_summary.md +188 -0
- data/docs/archive/sinatra_working_solution.md +113 -0
- data/docs/archive/typescript-client-generator-summary.md +259 -0
- data/docs/auto-derivation.md +146 -0
- data/docs/blueprint.md +1091 -0
- data/docs/endpoint-definition.md +211 -0
- data/docs/github_pages_fix.md +52 -0
- data/docs/github_pages_setup.md +49 -0
- data/docs/implementation-status.md +357 -0
- data/docs/observability.md +647 -0
- data/docs/phase3-plan.md +108 -0
- data/docs/sinatra_rapitapir.md +87 -0
- data/docs/type_shortcuts.md +146 -0
- data/examples/README_ENTERPRISE.md +202 -0
- data/examples/authentication_example.rb +192 -0
- data/examples/auto_derivation_ruby_friendly.rb +163 -0
- data/examples/cli/user_api_endpoints.rb +56 -0
- data/examples/client/typescript_client_example.rb +102 -0
- data/examples/client/user-api-client.ts +193 -0
- data/examples/demo_api.rb +41 -0
- data/examples/docs/documentation_example.rb +112 -0
- data/examples/docs/user-api-docs.html +789 -0
- data/examples/docs/user-api-docs.md +403 -0
- data/examples/enhanced_auto_derivation_test.rb +83 -0
- data/examples/enterprise_extension_demo.rb +417 -0
- data/examples/enterprise_rapitapir_api.rb +662 -0
- data/examples/getting_started_extension.rb +218 -0
- data/examples/hello_world.rb +74 -0
- data/examples/oauth2/.env.example +19 -0
- data/examples/oauth2/README.md +205 -0
- data/examples/oauth2/generic_oauth2_api.rb +226 -0
- data/examples/oauth2/get_token.rb +72 -0
- data/examples/oauth2/songs_api_with_auth0.rb +320 -0
- data/examples/oauth2/test_api.sh +16 -0
- data/examples/oauth2/test_songs_api.sh +110 -0
- data/examples/observability/.env.example +35 -0
- data/examples/observability/README.md +230 -0
- data/examples/observability/README_HONEYCOMB.md +332 -0
- data/examples/observability/advanced_setup.rb +384 -0
- data/examples/observability/basic_setup.rb +192 -0
- data/examples/observability/complete_test.rb +121 -0
- data/examples/observability/honeycomb_example.rb +523 -0
- data/examples/observability/honeycomb_rapitapir_clean.rb +488 -0
- data/examples/observability/honeycomb_rapitapir_example.rb +523 -0
- data/examples/observability/honeycomb_working_example.rb +489 -0
- data/examples/observability/quick_test.rb +78 -0
- data/examples/observability/simple_test.rb +14 -0
- data/examples/observability/test_honeycomb_demo.rb +354 -0
- data/examples/observability/test_live_honeycomb.rb +111 -0
- data/examples/observability/test_validation.rb +78 -0
- data/examples/observability/test_working_validation.rb +66 -0
- data/examples/openapi/user_api_schema.rb +132 -0
- data/examples/production_ready_example.rb +105 -0
- data/examples/rails/users_controller.rb +146 -0
- data/examples/readme/basic_sinatra_example.rb +128 -0
- data/examples/server/user_api.rb +179 -0
- data/examples/simple_auto_derivation_demo.rb +44 -0
- data/examples/simple_demo_api.rb +18 -0
- data/examples/sinatra/user_app.rb +127 -0
- data/examples/t_shortcut_demo.rb +59 -0
- data/examples/user_api.rb +190 -0
- data/examples/working_getting_started.rb +184 -0
- data/examples/working_simple_example.rb +195 -0
- data/lib/rapitapir/auth/configuration.rb +129 -0
- data/lib/rapitapir/auth/context.rb +122 -0
- data/lib/rapitapir/auth/errors.rb +104 -0
- data/lib/rapitapir/auth/middleware.rb +324 -0
- data/lib/rapitapir/auth/oauth2.rb +350 -0
- data/lib/rapitapir/auth/schemes.rb +420 -0
- data/lib/rapitapir/auth.rb +113 -0
- data/lib/rapitapir/cli/command.rb +535 -0
- data/lib/rapitapir/cli/server.rb +243 -0
- data/lib/rapitapir/cli/validator.rb +373 -0
- data/lib/rapitapir/client/generator_base.rb +272 -0
- data/lib/rapitapir/client/typescript_generator.rb +350 -0
- data/lib/rapitapir/core/endpoint.rb +158 -0
- data/lib/rapitapir/core/enhanced_endpoint.rb +235 -0
- data/lib/rapitapir/core/input.rb +182 -0
- data/lib/rapitapir/core/output.rb +164 -0
- data/lib/rapitapir/core/request.rb +19 -0
- data/lib/rapitapir/core/response.rb +17 -0
- data/lib/rapitapir/docs/html_generator.rb +780 -0
- data/lib/rapitapir/docs/markdown_generator.rb +464 -0
- data/lib/rapitapir/dsl/endpoint_dsl.rb +116 -0
- data/lib/rapitapir/dsl/enhanced_endpoint_dsl.rb +62 -0
- data/lib/rapitapir/dsl/enhanced_input.rb +73 -0
- data/lib/rapitapir/dsl/enhanced_output.rb +63 -0
- data/lib/rapitapir/dsl/enhanced_structures.rb +393 -0
- data/lib/rapitapir/dsl/fluent_dsl.rb +72 -0
- data/lib/rapitapir/dsl/fluent_endpoint_builder.rb +316 -0
- data/lib/rapitapir/dsl/http_verbs.rb +77 -0
- data/lib/rapitapir/dsl/input_methods.rb +47 -0
- data/lib/rapitapir/dsl/observability_methods.rb +81 -0
- data/lib/rapitapir/dsl/output_methods.rb +43 -0
- data/lib/rapitapir/dsl/type_resolution.rb +43 -0
- data/lib/rapitapir/observability/configuration.rb +108 -0
- data/lib/rapitapir/observability/health_check.rb +236 -0
- data/lib/rapitapir/observability/logging.rb +270 -0
- data/lib/rapitapir/observability/metrics.rb +203 -0
- data/lib/rapitapir/observability/middleware.rb +243 -0
- data/lib/rapitapir/observability/tracing.rb +143 -0
- data/lib/rapitapir/observability.rb +28 -0
- data/lib/rapitapir/openapi/schema_generator.rb +403 -0
- data/lib/rapitapir/schema.rb +136 -0
- data/lib/rapitapir/server/enhanced_rack_adapter.rb +379 -0
- data/lib/rapitapir/server/middleware.rb +120 -0
- data/lib/rapitapir/server/path_matcher.rb +45 -0
- data/lib/rapitapir/server/rack_adapter.rb +215 -0
- data/lib/rapitapir/server/rails_adapter.rb +17 -0
- data/lib/rapitapir/server/rails_adapter_class.rb +53 -0
- data/lib/rapitapir/server/rails_controller.rb +72 -0
- data/lib/rapitapir/server/rails_input_processor.rb +73 -0
- data/lib/rapitapir/server/rails_response_handler.rb +29 -0
- data/lib/rapitapir/server/sinatra_adapter.rb +200 -0
- data/lib/rapitapir/server/sinatra_integration.rb +93 -0
- data/lib/rapitapir/sinatra/configuration.rb +91 -0
- data/lib/rapitapir/sinatra/extension.rb +214 -0
- data/lib/rapitapir/sinatra/oauth2_helpers.rb +236 -0
- data/lib/rapitapir/sinatra/resource_builder.rb +152 -0
- data/lib/rapitapir/sinatra/swagger_ui_generator.rb +166 -0
- data/lib/rapitapir/sinatra_rapitapir.rb +40 -0
- data/lib/rapitapir/types/array.rb +163 -0
- data/lib/rapitapir/types/auto_derivation.rb +265 -0
- data/lib/rapitapir/types/base.rb +146 -0
- data/lib/rapitapir/types/boolean.rb +46 -0
- data/lib/rapitapir/types/date.rb +92 -0
- data/lib/rapitapir/types/datetime.rb +98 -0
- data/lib/rapitapir/types/email.rb +32 -0
- data/lib/rapitapir/types/float.rb +134 -0
- data/lib/rapitapir/types/hash.rb +161 -0
- data/lib/rapitapir/types/integer.rb +143 -0
- data/lib/rapitapir/types/object.rb +156 -0
- data/lib/rapitapir/types/optional.rb +65 -0
- data/lib/rapitapir/types/string.rb +185 -0
- data/lib/rapitapir/types/uuid.rb +32 -0
- data/lib/rapitapir/types.rb +155 -0
- data/lib/rapitapir/version.rb +5 -0
- data/lib/rapitapir.rb +173 -0
- data/rapitapir.gemspec +66 -0
- metadata +387 -0
data/docs/blueprint.md
ADDED
@@ -0,0 +1,1091 @@
|
|
1
|
+
# Ruby Tapir - Type-Safe HTTP API Library
|
2
|
+
|
3
|
+
A Ruby library for describing, serving, consuming, and documenting HTTP APIs with type safety and developer experience in mind.
|
4
|
+
|
5
|
+
## Repository Structure
|
6
|
+
|
7
|
+
```
|
8
|
+
ruby-tapir/
|
9
|
+
├── lib/
|
10
|
+
│ ├── tapir/
|
11
|
+
│ │ ├── core/
|
12
|
+
│ │ │ ├── endpoint.rb
|
13
|
+
│ │ │ ├── schema.rb
|
14
|
+
│ │ │ ├── input.rb
|
15
|
+
│ │ │ ├── output.rb
|
16
|
+
│ │ │ ├── codec.rb
|
17
|
+
│ │ │ └── validation.rb
|
18
|
+
│ │ ├── dsl/
|
19
|
+
│ │ │ ├── endpoint_dsl.rb
|
20
|
+
│ │ │ ├── schema_dsl.rb
|
21
|
+
│ │ │ └── validation_dsl.rb
|
22
|
+
│ │ ├── server/
|
23
|
+
│ │ │ ├── rack_adapter.rb
|
24
|
+
│ │ │ ├── sinatra_adapter.rb
|
25
|
+
│ │ │ ├── rails_adapter.rb
|
26
|
+
│ │ │ ├── hanami_adapter.rb
|
27
|
+
│ │ │ └── roda_adapter.rb
|
28
|
+
│ │ ├── client/
|
29
|
+
│ │ │ ├── http_client.rb
|
30
|
+
│ │ │ ├── faraday_adapter.rb
|
31
|
+
│ │ │ └── net_http_adapter.rb
|
32
|
+
│ │ ├── docs/
|
33
|
+
│ │ │ ├── openapi.rb
|
34
|
+
│ │ │ ├── swagger_ui.rb
|
35
|
+
│ │ │ └── redoc.rb
|
36
|
+
│ │ ├── observability/
|
37
|
+
│ │ │ ├── metrics.rb
|
38
|
+
│ │ │ ├── tracing.rb
|
39
|
+
│ │ │ └── logging.rb
|
40
|
+
│ │ ├── types/
|
41
|
+
│ │ │ ├── string.rb
|
42
|
+
│ │ │ ├── integer.rb
|
43
|
+
│ │ │ ├── float.rb
|
44
|
+
│ │ │ ├── boolean.rb
|
45
|
+
│ │ │ ├── array.rb
|
46
|
+
│ │ │ ├── hash.rb
|
47
|
+
│ │ │ ├── date.rb
|
48
|
+
│ │ │ ├── datetime.rb
|
49
|
+
│ │ │ └── custom.rb
|
50
|
+
│ │ ├── integrations/
|
51
|
+
│ │ │ ├── dry_validation.rb
|
52
|
+
│ │ │ ├── dry_struct.rb
|
53
|
+
│ │ │ ├── virtus.rb
|
54
|
+
│ │ │ └── active_model.rb
|
55
|
+
│ │ └── version.rb
|
56
|
+
│ └── tapir.rb
|
57
|
+
├── docs/
|
58
|
+
│ ├── implementation-plan.md
|
59
|
+
│ ├── architecture.md
|
60
|
+
│ ├── getting-started.md
|
61
|
+
│ ├── endpoint-definition.md
|
62
|
+
│ ├── server-integration.md
|
63
|
+
│ ├── client-usage.md
|
64
|
+
│ ├── openapi-documentation.md
|
65
|
+
│ ├── observability.md
|
66
|
+
│ ├── type-system.md
|
67
|
+
│ ├── examples/
|
68
|
+
│ │ ├── basic-crud.md
|
69
|
+
│ │ ├── authentication.md
|
70
|
+
│ │ ├── file-upload.md
|
71
|
+
│ │ ├── websockets.md
|
72
|
+
│ │ └── microservices.md
|
73
|
+
│ └── api-reference/
|
74
|
+
├── examples/
|
75
|
+
│ ├── sinatra/
|
76
|
+
│ ├── rails/
|
77
|
+
│ ├── hanami/
|
78
|
+
│ ├── roda/
|
79
|
+
│ └── client/
|
80
|
+
├── spec/
|
81
|
+
│ ├── core/
|
82
|
+
│ ├── dsl/
|
83
|
+
│ ├── server/
|
84
|
+
│ ├── client/
|
85
|
+
│ ├── docs/
|
86
|
+
│ ├── observability/
|
87
|
+
│ ├── types/
|
88
|
+
│ ├── integrations/
|
89
|
+
│ └── spec_helper.rb
|
90
|
+
├── benchmarks/
|
91
|
+
│ ├── endpoint_creation.rb
|
92
|
+
│ ├── request_processing.rb
|
93
|
+
│ └── serialization.rb
|
94
|
+
├── .github/
|
95
|
+
│ ├── workflows/
|
96
|
+
│ │ ├── ci.yml
|
97
|
+
│ │ ├── release.yml
|
98
|
+
│ │ └── docs.yml
|
99
|
+
│ ├── ISSUE_TEMPLATE/
|
100
|
+
│ └── PULL_REQUEST_TEMPLATE.md
|
101
|
+
├── Gemfile
|
102
|
+
├── Rakefile
|
103
|
+
├── tapir.gemspec
|
104
|
+
├── README.md
|
105
|
+
├── CHANGELOG.md
|
106
|
+
├── LICENSE
|
107
|
+
└── .gitignore
|
108
|
+
```
|
109
|
+
|
110
|
+
## Core Philosophy
|
111
|
+
|
112
|
+
### Type Safety First
|
113
|
+
- Compile-time (or load-time) validation of endpoint definitions
|
114
|
+
- Runtime type checking with detailed error messages
|
115
|
+
- Integration with Ruby type checkers (Sorbet, RBS)
|
116
|
+
|
117
|
+
### Declarative API Design
|
118
|
+
- Separate endpoint shape from implementation logic
|
119
|
+
- Composable and reusable endpoint definitions
|
120
|
+
- Clean separation of concerns
|
121
|
+
|
122
|
+
### Developer Experience
|
123
|
+
- Intuitive DSL with excellent discoverability
|
124
|
+
- Rich error messages and debugging information
|
125
|
+
- IDE-friendly with autocomplete support
|
126
|
+
|
127
|
+
### Framework Agnostic
|
128
|
+
- Library, not framework approach
|
129
|
+
- Adapters for all major Ruby web frameworks
|
130
|
+
- Minimal dependencies and lightweight core
|
131
|
+
|
132
|
+
## Implementation Phases
|
133
|
+
|
134
|
+
### Phase 1: Core Foundation (Weeks 1-3)
|
135
|
+
**Goal**: Establish the core type system and endpoint definition capabilities
|
136
|
+
|
137
|
+
#### Week 1: Type System Foundation
|
138
|
+
- [ ] Implement basic type system (`Tapir::Types`)
|
139
|
+
- [ ] Create primitive types (String, Integer, Float, Boolean, Date, DateTime)
|
140
|
+
- [ ] Implement composite types (Array, Hash, Optional)
|
141
|
+
- [ ] Add validation framework integration points
|
142
|
+
- [ ] Create type coercion and serialization mechanisms
|
143
|
+
|
144
|
+
#### Week 2: Endpoint Definition Core
|
145
|
+
- [ ] Design and implement `Tapir::Endpoint` class
|
146
|
+
- [ ] Create input/output definition system
|
147
|
+
- [ ] Implement HTTP method and path specification
|
148
|
+
- [ ] Add header and query parameter support
|
149
|
+
- [ ] Create request/response body handling
|
150
|
+
|
151
|
+
#### Week 3: DSL and Schema Definition
|
152
|
+
- [ ] Implement endpoint definition DSL
|
153
|
+
- [ ] Create schema composition capabilities
|
154
|
+
- [ ] Add endpoint inheritance and mixins
|
155
|
+
- [ ] Implement validation integration
|
156
|
+
- [ ] Create basic error handling framework
|
157
|
+
|
158
|
+
**Deliverables**:
|
159
|
+
- Working endpoint definition system
|
160
|
+
- Basic type validation
|
161
|
+
- Simple DSL for defining endpoints
|
162
|
+
- Comprehensive test suite for core functionality
|
163
|
+
|
164
|
+
### Phase 2: Server Integration (Weeks 4-6)
|
165
|
+
**Goal**: Enable serving endpoints through major Ruby frameworks
|
166
|
+
|
167
|
+
#### Week 4: Rack Foundation
|
168
|
+
- [ ] Implement Rack adapter as base for all server integrations
|
169
|
+
- [ ] Create request processing pipeline
|
170
|
+
- [ ] Add middleware support for observability
|
171
|
+
- [ ] Implement response serialization
|
172
|
+
- [ ] Add error handling and status code management
|
173
|
+
|
174
|
+
#### Week 5: Framework Adapters
|
175
|
+
- [ ] Sinatra adapter with route registration
|
176
|
+
- [ ] Rails adapter with controller integration
|
177
|
+
- [ ] Hanami adapter with action integration
|
178
|
+
- [ ] Roda adapter with routing tree integration
|
179
|
+
- [ ] Basic performance optimizations
|
180
|
+
|
181
|
+
#### Week 6: Advanced Server Features
|
182
|
+
- [ ] Request/response interceptors
|
183
|
+
- [ ] Custom middleware integration
|
184
|
+
- [ ] Streaming response support
|
185
|
+
- [ ] File upload handling
|
186
|
+
- [ ] Authentication/authorization hooks
|
187
|
+
|
188
|
+
**Deliverables**:
|
189
|
+
- Working server adapters for major frameworks
|
190
|
+
- Request/response processing pipeline
|
191
|
+
- Middleware integration capabilities
|
192
|
+
- Example applications for each framework
|
193
|
+
|
194
|
+
### Phase 3: Client Generation (Weeks 7-8)
|
195
|
+
**Goal**: Generate type-safe HTTP clients from endpoint definitions
|
196
|
+
|
197
|
+
#### Week 7: Client Core
|
198
|
+
- [ ] Implement HTTP client generator
|
199
|
+
- [ ] Create Faraday adapter for HTTP requests
|
200
|
+
- [ ] Add Net::HTTP fallback adapter
|
201
|
+
- [ ] Implement request serialization
|
202
|
+
- [ ] Add response deserialization and validation
|
203
|
+
|
204
|
+
#### Week 8: Advanced Client Features
|
205
|
+
- [ ] Error handling and retry mechanisms
|
206
|
+
- [ ] Async/concurrent request support
|
207
|
+
- [ ] Client middleware and interceptors
|
208
|
+
- [ ] Connection pooling and caching
|
209
|
+
- [ ] Mock client for testing
|
210
|
+
|
211
|
+
**Deliverables**:
|
212
|
+
- Generated HTTP clients with type safety
|
213
|
+
- Multiple HTTP adapter support
|
214
|
+
- Error handling and retry logic
|
215
|
+
- Testing utilities and mocks
|
216
|
+
|
217
|
+
### Phase 4: Documentation Generation (Weeks 9-10)
|
218
|
+
**Goal**: Generate OpenAPI/Swagger documentation automatically
|
219
|
+
|
220
|
+
#### Week 9: OpenAPI Core
|
221
|
+
- [ ] Implement OpenAPI 3.x specification generation
|
222
|
+
- [ ] Create endpoint to OpenAPI path mapping
|
223
|
+
- [ ] Add schema to JSON Schema conversion
|
224
|
+
- [ ] Implement parameter and response documentation
|
225
|
+
- [ ] Add example generation from types
|
226
|
+
|
227
|
+
#### Week 10: Documentation UI
|
228
|
+
- [ ] Integrate Swagger UI for interactive docs
|
229
|
+
- [ ] Add ReDoc support as alternative
|
230
|
+
- [ ] Create custom documentation themes
|
231
|
+
- [ ] Implement live API testing from docs
|
232
|
+
- [ ] Add documentation versioning support
|
233
|
+
|
234
|
+
**Deliverables**:
|
235
|
+
- Complete OpenAPI 3.x specification generation
|
236
|
+
- Interactive documentation interfaces
|
237
|
+
- Custom documentation themes
|
238
|
+
- Live API testing capabilities
|
239
|
+
|
240
|
+
### Phase 5: Observability and Advanced Features (Weeks 11-12)
|
241
|
+
**Goal**: Add production-ready observability and advanced features
|
242
|
+
|
243
|
+
#### Week 11: Observability
|
244
|
+
- [ ] Implement metrics collection (response times, error rates)
|
245
|
+
- [ ] Add distributed tracing support (OpenTelemetry)
|
246
|
+
- [ ] Create structured logging integration
|
247
|
+
- [ ] Add health check endpoint generation
|
248
|
+
- [ ] Implement request/response logging
|
249
|
+
|
250
|
+
#### Week 12: Advanced Features
|
251
|
+
- [ ] Rate limiting and throttling
|
252
|
+
- [ ] Request/response caching
|
253
|
+
- [ ] API versioning strategies
|
254
|
+
- [ ] WebSocket endpoint support
|
255
|
+
- [ ] GraphQL endpoint integration
|
256
|
+
|
257
|
+
**Deliverables**:
|
258
|
+
- Production-ready observability features
|
259
|
+
- Advanced API management capabilities
|
260
|
+
- WebSocket and GraphQL support
|
261
|
+
- Performance monitoring tools
|
262
|
+
|
263
|
+
### Phase 6: Ecosystem Integration (Weeks 13-14)
|
264
|
+
**Goal**: Integrate with popular Ruby libraries and tools
|
265
|
+
|
266
|
+
#### Week 13: Validation Libraries
|
267
|
+
- [ ] Dry-validation integration
|
268
|
+
- [ ] Dry-struct integration
|
269
|
+
- [ ] Virtus integration
|
270
|
+
- [ ] ActiveModel integration
|
271
|
+
- [ ] Custom validation framework support
|
272
|
+
|
273
|
+
#### Week 14: Type Checking Integration
|
274
|
+
- [ ] Sorbet type annotations generation
|
275
|
+
- [ ] RBS signature generation
|
276
|
+
- [ ] YARD documentation integration
|
277
|
+
- [ ] IDE plugins and extensions
|
278
|
+
- [ ] Static analysis tools integration
|
279
|
+
|
280
|
+
**Deliverables**:
|
281
|
+
- Seamless integration with validation libraries
|
282
|
+
- Type checker integration
|
283
|
+
- IDE and tooling support
|
284
|
+
- Static analysis capabilities
|
285
|
+
|
286
|
+
## Technical Architecture
|
287
|
+
|
288
|
+
### Core Components
|
289
|
+
|
290
|
+
#### 1. Type System (`Tapir::Types`)
|
291
|
+
```ruby
|
292
|
+
# Primitive types
|
293
|
+
Tapir::Types::String.new(min_length: 3, max_length: 255)
|
294
|
+
Tapir::Types::Integer.new(minimum: 0, maximum: 100)
|
295
|
+
Tapir::Types::Boolean.new
|
296
|
+
Tapir::Types::DateTime.new(format: :iso8601)
|
297
|
+
|
298
|
+
# Composite types
|
299
|
+
Tapir::Types::Array.new(Tapir::Types::String.new)
|
300
|
+
Tapir::Types::Hash.new(
|
301
|
+
name: Tapir::Types::String.new,
|
302
|
+
age: Tapir::Types::Integer.new
|
303
|
+
)
|
304
|
+
Tapir::Types::Optional.new(Tapir::Types::String.new)
|
305
|
+
|
306
|
+
# Custom types
|
307
|
+
UserType = Tapir::Types::Object.new do
|
308
|
+
field :id, Tapir::Types::Integer.new
|
309
|
+
field :name, Tapir::Types::String.new
|
310
|
+
field :email, Tapir::Types::String.new(format: :email)
|
311
|
+
end
|
312
|
+
```
|
313
|
+
|
314
|
+
#### 2. Endpoint Definition (`Tapir::Endpoint`)
|
315
|
+
```ruby
|
316
|
+
class UserEndpoints
|
317
|
+
include Tapir::DSL
|
318
|
+
|
319
|
+
# GET /users/{id}
|
320
|
+
get_user = endpoint
|
321
|
+
.get
|
322
|
+
.in(path_param(:id, Tapir::Types::Integer.new))
|
323
|
+
.out(json_body(UserType))
|
324
|
+
.error_out(404, json_body(ErrorType))
|
325
|
+
.summary("Get user by ID")
|
326
|
+
.description("Retrieves a user by their unique identifier")
|
327
|
+
|
328
|
+
# POST /users
|
329
|
+
create_user = endpoint
|
330
|
+
.post
|
331
|
+
.in(json_body(CreateUserType))
|
332
|
+
.out(status(201), json_body(UserType))
|
333
|
+
.error_out(400, json_body(ValidationErrorType))
|
334
|
+
.error_out(422, json_body(BusinessLogicErrorType))
|
335
|
+
end
|
336
|
+
```
|
337
|
+
|
338
|
+
#### 3. Server Integration
|
339
|
+
```ruby
|
340
|
+
# Sinatra
|
341
|
+
class UserAPI < Sinatra::Base
|
342
|
+
include Tapir::Sinatra
|
343
|
+
|
344
|
+
mount UserEndpoints.get_user do |user_id|
|
345
|
+
user_service.find(user_id)
|
346
|
+
end
|
347
|
+
|
348
|
+
mount UserEndpoints.create_user do |user_data|
|
349
|
+
user_service.create(user_data)
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
# Rails
|
354
|
+
class UsersController < ApplicationController
|
355
|
+
include Tapir::Rails
|
356
|
+
|
357
|
+
mount UserEndpoints.get_user do |user_id|
|
358
|
+
@user_service.find(user_id)
|
359
|
+
end
|
360
|
+
|
361
|
+
mount UserEndpoints.create_user do |user_data|
|
362
|
+
@user_service.create(user_data)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
```
|
366
|
+
|
367
|
+
#### 4. Client Generation
|
368
|
+
```ruby
|
369
|
+
# Generated client
|
370
|
+
user_client = Tapir::Client.new(UserEndpoints, base_url: "https://api.example.com")
|
371
|
+
|
372
|
+
# Type-safe method calls
|
373
|
+
user = user_client.get_user(id: 123) # Returns User object or raises typed error
|
374
|
+
new_user = user_client.create_user(name: "John", email: "john@example.com")
|
375
|
+
```
|
376
|
+
|
377
|
+
#### 5. Documentation Generation
|
378
|
+
```ruby
|
379
|
+
# Generate OpenAPI spec
|
380
|
+
openapi_spec = Tapir::Docs::OpenAPI.generate(UserEndpoints)
|
381
|
+
|
382
|
+
# Serve documentation
|
383
|
+
Tapir::Docs::SwaggerUI.mount(openapi_spec, path: "/docs")
|
384
|
+
```
|
385
|
+
|
386
|
+
## Key Design Principles
|
387
|
+
|
388
|
+
### 1. Type Safety
|
389
|
+
- **Compile-time validation**: Endpoint definitions are validated when loaded
|
390
|
+
- **Runtime type checking**: All inputs/outputs are validated against schemas
|
391
|
+
- **Error propagation**: Type errors include detailed information about failures
|
392
|
+
- **Integration**: Works with Sorbet, RBS, and other type systems
|
393
|
+
|
394
|
+
### 2. Composability
|
395
|
+
- **Endpoint reuse**: Common patterns can be extracted and reused
|
396
|
+
- **Schema composition**: Complex types built from simpler ones
|
397
|
+
- **Middleware chains**: Request/response processing is composable
|
398
|
+
- **Framework agnostic**: Same endpoints work across different frameworks
|
399
|
+
|
400
|
+
### 3. Performance
|
401
|
+
- **Lazy evaluation**: Schemas and validations are computed only when needed
|
402
|
+
- **Caching**: Compiled schemas and validators are cached
|
403
|
+
- **Zero-allocation paths**: Common cases avoid object allocation
|
404
|
+
- **Benchmarking**: Comprehensive performance testing and optimization
|
405
|
+
|
406
|
+
### 4. Developer Experience
|
407
|
+
- **Rich errors**: Detailed error messages with context and suggestions
|
408
|
+
- **IDE support**: Autocomplete, type hints, and inline documentation
|
409
|
+
- **Debugging**: Clear stack traces and debugging information
|
410
|
+
- **Documentation**: Comprehensive guides and API documentation
|
411
|
+
|
412
|
+
## Success Metrics
|
413
|
+
|
414
|
+
### Technical Metrics
|
415
|
+
- **Performance**: < 1ms overhead for simple endpoints
|
416
|
+
- **Memory**: < 10MB memory overhead for typical applications
|
417
|
+
- **Compatibility**: Support for Ruby 3.1+ and all major frameworks
|
418
|
+
- **Coverage**: > 95% test coverage across all components
|
419
|
+
|
420
|
+
### Developer Experience Metrics
|
421
|
+
- **Setup time**: < 5 minutes from gem install to first endpoint
|
422
|
+
- **Learning curve**: Clear tutorials for common use cases
|
423
|
+
- **Error clarity**: Meaningful error messages with actionable advice
|
424
|
+
- **Documentation**: Complete API reference and usage examples
|
425
|
+
|
426
|
+
### Ecosystem Integration
|
427
|
+
- **Framework support**: Adapters for top 5 Ruby web frameworks
|
428
|
+
- **Library integration**: Support for major validation/serialization libraries
|
429
|
+
- **Tooling**: IDE plugins and static analysis integration
|
430
|
+
- **Community**: Active contribution guidelines and responsive maintenance
|
431
|
+
|
432
|
+
## Risk Mitigation
|
433
|
+
|
434
|
+
### Performance Risks
|
435
|
+
- **Mitigation**: Comprehensive benchmarking suite and performance budgets
|
436
|
+
- **Monitoring**: Continuous performance testing in CI/CD
|
437
|
+
- **Optimization**: Profile-guided optimization for hot paths
|
438
|
+
|
439
|
+
### Complexity Risks
|
440
|
+
- **Mitigation**: Modular architecture with clear separation of concerns
|
441
|
+
- **Documentation**: Extensive architectural documentation and examples
|
442
|
+
- **Testing**: Comprehensive test suite with integration tests
|
443
|
+
|
444
|
+
### Adoption Risks
|
445
|
+
- **Mitigation**: Clear migration guides from existing solutions
|
446
|
+
- **Compatibility**: Gradual adoption path without requiring full rewrites
|
447
|
+
- **Community**: Active engagement with Ruby community for feedback
|
448
|
+
|
449
|
+
## Future Roadmap
|
450
|
+
|
451
|
+
### Version 1.0 (Core Features)
|
452
|
+
- Complete type system and endpoint definitions
|
453
|
+
- Server adapters for major frameworks
|
454
|
+
- Client generation capabilities
|
455
|
+
- OpenAPI documentation generation
|
456
|
+
- Basic observability features
|
457
|
+
|
458
|
+
### Version 1.1 (Performance & Polish)
|
459
|
+
- Performance optimizations and benchmarking
|
460
|
+
- Enhanced error messages and debugging
|
461
|
+
- Additional framework adapters
|
462
|
+
- Advanced documentation features
|
463
|
+
|
464
|
+
### Version 1.2 (Advanced Features)
|
465
|
+
- WebSocket endpoint support
|
466
|
+
- GraphQL integration
|
467
|
+
- Advanced caching and rate limiting
|
468
|
+
- Enhanced observability and monitoring
|
469
|
+
|
470
|
+
### Version 2.0 (Next Generation)
|
471
|
+
- Code generation and compile-time optimizations
|
472
|
+
- Advanced type system features
|
473
|
+
- Plugin architecture for extensibility
|
474
|
+
- Cross-language client generation
|
475
|
+
|
476
|
+
## Contributing Guidelines
|
477
|
+
|
478
|
+
### Code Style
|
479
|
+
- Follow RuboCop configuration
|
480
|
+
- Write comprehensive tests for all features
|
481
|
+
- Include documentation for public APIs
|
482
|
+
- Maintain backwards compatibility within major versions
|
483
|
+
|
484
|
+
### Architecture Decisions
|
485
|
+
- Document significant architectural decisions
|
486
|
+
- Prefer composition over inheritance
|
487
|
+
- Minimize dependencies and coupling
|
488
|
+
- Design for extensibility and modularity
|
489
|
+
|
490
|
+
### Testing Strategy
|
491
|
+
- Unit tests for all core functionality
|
492
|
+
- Integration tests for framework adapters
|
493
|
+
- Performance tests for critical paths
|
494
|
+
- End-to-end tests for complete workflows
|
495
|
+
|
496
|
+
This implementation plan provides a comprehensive roadmap for building a production-ready HTTP API library for Ruby that combines type safety, developer experience, and performance.
|
497
|
+
|
498
|
+
### 🎯 Goal
|
499
|
+
Create a Ruby library to **define HTTP endpoints declaratively**, **serve them**, **consume them**, and **generate OpenAPI documentation** – while ensuring type-safety, developer joy, and broad compatibility.
|
500
|
+
|
501
|
+
---
|
502
|
+
|
503
|
+
### ✅ Core Features
|
504
|
+
- ✅ **Endpoint DSL**: Declare endpoints using a readable and composable DSL.
|
505
|
+
- ✅ **Type-safe Inputs/Outputs**: Strong typing for parameters, headers, body, and response.
|
506
|
+
- ✅ **Server Adapter**: Pluggable support for Rack/Sinatra/Rails/etc.
|
507
|
+
- ✅ **Client Adapter**: Auto-generated client for declared endpoints.
|
508
|
+
- ✅ **OpenAPI Exporter**: Generate Swagger-compliant specs.
|
509
|
+
- ✅ **Observability Hooks**: Emit metrics and tracing events using metadata.
|
510
|
+
- ✅ **Composability**: Reuse common inputs, outputs, headers, and security schemes.
|
511
|
+
- ✅ **Minimal Dependencies**: Fast, lean, and stack-agnostic.
|
512
|
+
|
513
|
+
---
|
514
|
+
|
515
|
+
### 🛠️ Step-by-Step Implementation Plan
|
516
|
+
|
517
|
+
#### Phase 1 – Core DSL & Type System
|
518
|
+
- [ ] Define `Endpoint`, `Input`, `Output`, `Request`, and `Response` core types.
|
519
|
+
- [ ] Build a fluent, composable DSL for endpoint definition:
|
520
|
+
```ruby
|
521
|
+
endpoint = RapiTapir.get("/hello")
|
522
|
+
.in(query(:name, :string))
|
523
|
+
.out(json_body(:message => :string))
|
524
|
+
```
|
525
|
+
- [ ] Add compile-time (or at least runtime) type-checking of endpoint specs.
|
526
|
+
|
527
|
+
#### Phase 2 – Server Integration
|
528
|
+
- [ ] Implement a Rack adapter that maps endpoint definitions to routes.
|
529
|
+
- [ ] Implement a Sinatra/Rails plug to automatically expose endpoints.
|
530
|
+
- [ ] Provide a generic handler system that separates route parsing and logic execution.
|
531
|
+
|
532
|
+
#### Phase 3 – Client Generation ✅ COMPLETED
|
533
|
+
- [x] From an `Endpoint`, generate a callable HTTP client stub.
|
534
|
+
- [x] Allow configuration of HTTP client backend (Faraday, HTTP.rb, etc.).
|
535
|
+
- [x] TypeScript client generation with type definitions.
|
536
|
+
- [x] Support for request/response types and error handling.
|
537
|
+
- [x] Configurable client names, packages, and versions.
|
538
|
+
- [x] **BONUS**: Complete CLI tooling system with validation, documentation generation, and development server.
|
539
|
+
- [x] **BONUS**: Interactive HTML documentation with live API testing capabilities.
|
540
|
+
- [x] **BONUS**: Comprehensive test suite with 187 examples, 100% pass rate.
|
541
|
+
|
542
|
+
#### Phase 4 – OpenAPI Generator ✅ COMPLETED
|
543
|
+
- [x] Traverse all defined `Endpoint`s to build an OpenAPI 3.0.3 spec.
|
544
|
+
- [x] Support tags, descriptions, examples, and error codes.
|
545
|
+
- [x] Generate and expose the YAML/JSON via CLI and programmatic API.
|
546
|
+
- [x] Comprehensive OpenAPI schema generation with parameter definitions.
|
547
|
+
- [x] Support for multiple output formats (JSON, YAML).
|
548
|
+
- [x] Integration with documentation generators for interactive docs.
|
549
|
+
|
550
|
+
#### Phase 5 – Observability & Metadata
|
551
|
+
- [ ] Collect execution metadata: latency, status code, parameters.
|
552
|
+
- [ ] Emit hooks for tracing (e.g., OpenTelemetry).
|
553
|
+
- [x] Add instrumentation adapters (e.g., StatsD, Prometheus).
|
554
|
+
|
555
|
+
---
|
556
|
+
|
557
|
+
## 🎉 Major Milestones Achieved
|
558
|
+
|
559
|
+
### Phase 3 & 4 Implementation Complete! ✅
|
560
|
+
|
561
|
+
**RapiTapir now includes a complete toolkit for modern API development:**
|
562
|
+
|
563
|
+
#### 🏗️ **Core Infrastructure**
|
564
|
+
- ✅ Complete OpenAPI 3.0.3 specification generation
|
565
|
+
- ✅ TypeScript client generation with full type safety
|
566
|
+
- ✅ Interactive HTML documentation with live testing
|
567
|
+
- ✅ Markdown documentation generation
|
568
|
+
- ✅ Command-line interface for all operations
|
569
|
+
|
570
|
+
#### 🔧 **Developer Tools**
|
571
|
+
- ✅ **CLI Commands**:
|
572
|
+
- `rapitapir generate openapi` - Generate OpenAPI specs (JSON/YAML)
|
573
|
+
- `rapitapir generate client` - Generate TypeScript clients
|
574
|
+
- `rapitapir generate docs` - Generate interactive documentation
|
575
|
+
- `rapitapir validate` - Validate endpoint definitions
|
576
|
+
- `rapitapir serve` - Start development documentation server
|
577
|
+
- ✅ **Validation System**: Comprehensive endpoint validation with detailed error reporting
|
578
|
+
- ✅ **Documentation Server**: Live-reload development server for API documentation
|
579
|
+
|
580
|
+
#### 📊 **Quality & Testing**
|
581
|
+
- ✅ **187 test examples** with **100% pass rate**
|
582
|
+
- ✅ **81.2% code coverage** across all components
|
583
|
+
- ✅ **13 comprehensive integration tests** for end-to-end workflows
|
584
|
+
- ✅ Robust CLI testing for all commands and error scenarios
|
585
|
+
|
586
|
+
#### 🎯 **Key Achievements**
|
587
|
+
1. **Full OpenAPI 3.0.3 Generation**: Complete spec generation with parameters, responses, and metadata
|
588
|
+
2. **TypeScript Client Generation**: Type-safe HTTP clients with proper error handling
|
589
|
+
3. **Interactive Documentation**: HTML docs with live API testing capabilities
|
590
|
+
4. **Developer Experience**: Comprehensive CLI tooling for the complete API lifecycle
|
591
|
+
5. **Production Ready**: Extensive test coverage and error handling
|
592
|
+
|
593
|
+
---
|
594
|
+
|
595
|
+
#### Phase 6 – Testing Utilities
|
596
|
+
- [ ] Provide test helpers to validate endpoints.
|
597
|
+
- [ ] Allow unit/integration tests to assert conformance to API.
|
598
|
+
|
599
|
+
---
|
600
|
+
|
601
|
+
### 🔄 Example
|
602
|
+
```ruby
|
603
|
+
endpoint = RapiTapir.post("/register")
|
604
|
+
.in(json_body(:email => :string, :password => :string))
|
605
|
+
.out(status_code(201), json_body(:user_id => :string))
|
606
|
+
|
607
|
+
# Expose as Sinatra route
|
608
|
+
RapiTapir.serve(endpoint) do |input|
|
609
|
+
register_user(input[:email], input[:password])
|
610
|
+
end
|
611
|
+
|
612
|
+
# Use as HTTP client
|
613
|
+
response = RapiTapir.call(endpoint, { email: "hi@example.com", password: "secret" })
|
614
|
+
```
|
615
|
+
|
616
|
+
---
|
617
|
+
|
618
|
+
### 🤝 Target Compatibility
|
619
|
+
- Compatible with: **Rails, Sinatra, Roda, Hanami**
|
620
|
+
- HTTP Clients: **Faraday, Net::HTTP, HTTP.rb**
|
621
|
+
- JSON: **Oj, JSON, ActiveSupport::JSON**
|
622
|
+
- Tracing: **OpenTelemetry, NewRelic, Datadog**
|
623
|
+
|
624
|
+
---
|
625
|
+
|
626
|
+
### 📢 Naming Justification
|
627
|
+
- **RapiTapir** = **Rapid API** + homage to **Tapir**
|
628
|
+
- Suggests speed, elegance, and semantic richness
|
629
|
+
|
630
|
+
---
|
631
|
+
|
632
|
+
### 📚 Further Inspirations
|
633
|
+
- Scala Tapir
|
634
|
+
- Haskell Servant
|
635
|
+
- Elixir Phoenix Plug
|
636
|
+
- TypeScript tRPC
|
637
|
+
|
638
|
+
---
|
639
|
+
|
640
|
+
### 🚀 Future Ideas
|
641
|
+
- GraphQL API generation
|
642
|
+
- Codegen for clients (TypeScript/Ruby)
|
643
|
+
- Contracts-as-tests
|
644
|
+
- API versioning support
|
645
|
+
|
646
|
+
---
|
647
|
+
|
648
|
+
Want to contribute? Fork, star, and join the herd!
|
649
|
+
|
650
|
+
🦙 `rapitapir` – APIs so fast and clean, they practically run wild.
|
651
|
+
|
652
|
+
## 🎯 **Phase 4 Complete - What's Been Achieved:**
|
653
|
+
|
654
|
+
### **Complete OpenAPI 3.0.3 Ecosystem** ✅
|
655
|
+
- **OpenAPI Schema Generation**: Full OpenAPI 3.0.3 specification generation with metadata, parameters, and responses
|
656
|
+
- **TypeScript Client Generation**: Type-safe HTTP clients with proper error handling and type definitions
|
657
|
+
- **Interactive Documentation**: HTML docs with live API testing capabilities and auto-reload
|
658
|
+
- **Comprehensive CLI**: Complete command-line interface for all operations
|
659
|
+
- **Production Ready**: 187 test examples with 100% pass rate and 81.2% code coverage
|
660
|
+
|
661
|
+
### **Available CLI Commands:**
|
662
|
+
```bash
|
663
|
+
# Generate OpenAPI 3.0.3 specification
|
664
|
+
rapitapir generate openapi --endpoints api.rb --output openapi.json
|
665
|
+
|
666
|
+
# Generate TypeScript client
|
667
|
+
rapitapir generate client --endpoints api.rb --output client.ts
|
668
|
+
|
669
|
+
# Generate interactive HTML documentation
|
670
|
+
rapitapir generate docs html --endpoints api.rb --output docs.html
|
671
|
+
|
672
|
+
# Validate endpoint definitions
|
673
|
+
rapitapir validate --endpoints api.rb
|
674
|
+
|
675
|
+
# Start development server with live documentation
|
676
|
+
rapitapir serve --endpoints api.rb --port 3000
|
677
|
+
```
|
678
|
+
|
679
|
+
**Phase 4 Implementation Status: COMPLETE** 🎉
|
680
|
+
|
681
|
+
---
|
682
|
+
|
683
|
+
## 🔍 **Evolution Plan: Bridging the Gap with Scala Tapir**
|
684
|
+
|
685
|
+
### **Current State Analysis (Updated February 2025)**
|
686
|
+
|
687
|
+
**✅ What We Have (COMPLETE and Production-Ready):**
|
688
|
+
- ✅ **Advanced Type System**: 13 types with constraints, auto-derivation, T.shortcut syntax
|
689
|
+
- ✅ **Enhanced Endpoint DSL**: FluentEndpointBuilder with authentication and validation
|
690
|
+
- ✅ **Server Integration**: Complete Rack + Sinatra adapters with middleware
|
691
|
+
- ✅ **OpenAPI 3.0.3 Generation**: Full specification with interactive documentation
|
692
|
+
- ✅ **TypeScript Client Generation**: Type-safe HTTP clients with error handling
|
693
|
+
- ✅ **CLI Tooling**: Complete development toolkit (generate, validate, serve)
|
694
|
+
- ✅ **Observability Stack**: Metrics, health checks, structured logging
|
695
|
+
- ✅ **Production Features**: Error handling, validation, type safety
|
696
|
+
- ✅ **Enterprise Authentication System**: OAuth2, JWT validation, scope-based authorization, Auth0 integration
|
697
|
+
|
698
|
+
**🟡 What We're Enhancing (In Progress):**
|
699
|
+
|
700
|
+
#### **1. Enterprise Authentication System** ✅ **COMPLETED**
|
701
|
+
- **Current**: ✅ Complete OAuth2/JWT ecosystem with Auth0 integration
|
702
|
+
- **Achieved**: OAuth2 token validation, JWT with RS256/HS256, scope-based authorization, Auth0 tested integration
|
703
|
+
- **Status**: **PRODUCTION READY** - Successfully tested with real Auth0 tokens
|
704
|
+
- **Features**:
|
705
|
+
- Complete OAuth2 implementation (`lib/rapitapir/auth/oauth2.rb`)
|
706
|
+
- Auth0 and generic OAuth2 provider support
|
707
|
+
- JWT validation with JWKS integration
|
708
|
+
- Scope-based authorization middleware
|
709
|
+
- Working examples with comprehensive test coverage
|
710
|
+
|
711
|
+
#### **2. Advanced File Handling**
|
712
|
+
- **Current**: JSON body only
|
713
|
+
- **Target**: Multipart/form-data, file validation, streaming uploads, size limits
|
714
|
+
- **Timeline**: 3 weeks
|
715
|
+
- **Priority**: **MEDIUM** for complete REST API support
|
716
|
+
|
717
|
+
#### **3. Deep Framework Integration**
|
718
|
+
- **Current**: Sinatra complete, Rails basic
|
719
|
+
- **Target**: Rails controller integration, Hanami adapters, Roda support
|
720
|
+
- **Timeline**: 4 weeks
|
721
|
+
- **Priority**: **MEDIUM** for ecosystem adoption
|
722
|
+
|
723
|
+
**❌ What We're Planning (Future Enhancements):**
|
724
|
+
|
725
|
+
#### **4. WebSocket & Streaming Support**
|
726
|
+
- **Target**: WebSocket endpoints, Server-Sent Events, streaming responses
|
727
|
+
- **Timeline**: 6 weeks
|
728
|
+
- **Priority**: **LOW** for core API functionality
|
729
|
+
|
730
|
+
#### **5. Advanced Schema Features**
|
731
|
+
- **Target**: Discriminated unions, recursive schemas, schema inheritance
|
732
|
+
- **Timeline**: 4 weeks
|
733
|
+
- **Priority**: **LOW** for advanced use cases
|
734
|
+
|
735
|
+
---
|
736
|
+
|
737
|
+
### **🗺️ Updated Roadmap for Complete Scala Tapir Parity**
|
738
|
+
|
739
|
+
#### **Current Status: ~85% Parity Achieved** ✅
|
740
|
+
|
741
|
+
**Foundation phases (Phase 1-4) are COMPLETE and exceed original expectations.**
|
742
|
+
|
743
|
+
#### **Phase 2.3: Enterprise Authentication (Priority: HIGH) - 4 weeks**
|
744
|
+
*Complete the authentication ecosystem for enterprise adoption*
|
745
|
+
|
746
|
+
##### **2.3.1 Advanced Authentication Schemes**
|
747
|
+
```ruby
|
748
|
+
# Target: Complete auth ecosystem
|
749
|
+
oauth2_endpoint = RapiTapir.endpoint
|
750
|
+
.security_in(oauth2_auth(
|
751
|
+
scopes: ['read:users', 'write:users'],
|
752
|
+
token_url: 'https://auth.company.com/token'
|
753
|
+
))
|
754
|
+
.get('/admin/users')
|
755
|
+
|
756
|
+
jwt_endpoint = RapiTapir.endpoint
|
757
|
+
.security_in(jwt_auth(
|
758
|
+
algorithm: 'RS256',
|
759
|
+
issuer: 'auth.company.com',
|
760
|
+
audience: 'api.company.com'
|
761
|
+
))
|
762
|
+
.get('/protected/data')
|
763
|
+
```
|
764
|
+
|
765
|
+
**Implementation Tasks:**
|
766
|
+
- [ ] OAuth2 flow integration with token validation
|
767
|
+
- [ ] JWT authentication with algorithm support (RS256, HS256)
|
768
|
+
- [ ] Scope-based authorization middleware
|
769
|
+
- [ ] Refresh token handling
|
770
|
+
- [ ] Authentication middleware for server adapters
|
771
|
+
|
772
|
+
#### **Phase 2.4: File Upload & Advanced I/O (Priority: MEDIUM) - 3 weeks**
|
773
|
+
*Complete REST API functionality with file handling*
|
774
|
+
|
775
|
+
##### **2.4.1 Multipart Form Data Support**
|
776
|
+
```ruby
|
777
|
+
# Target: Complete file upload system
|
778
|
+
upload_endpoint = RapiTapir.endpoint
|
779
|
+
.post('/upload')
|
780
|
+
.in(multipart_body({
|
781
|
+
file: file_part(
|
782
|
+
max_size: 10.megabytes,
|
783
|
+
allowed_types: ['image/*', 'application/pdf'],
|
784
|
+
required: true
|
785
|
+
),
|
786
|
+
metadata: json_part(upload_metadata_schema),
|
787
|
+
category: form_field(Types.string)
|
788
|
+
}))
|
789
|
+
.out(json_body(upload_result_schema))
|
790
|
+
```
|
791
|
+
|
792
|
+
**Implementation Tasks:**
|
793
|
+
- [ ] Multipart/form-data parser integration
|
794
|
+
- [ ] File validation (size, type, content)
|
795
|
+
- [ ] Streaming file upload support
|
796
|
+
- [ ] Form field extraction and validation
|
797
|
+
- [ ] File storage integration patterns
|
798
|
+
|
799
|
+
#### **Phase 2.5: Deep Framework Integration (Priority: MEDIUM) - 4 weeks**
|
800
|
+
*Complete Ruby ecosystem integration*
|
801
|
+
|
802
|
+
##### **2.5.1 Enhanced Rails Integration**
|
803
|
+
```ruby
|
804
|
+
# Target: Native Rails controller integration
|
805
|
+
class UsersController < ApplicationController
|
806
|
+
include RapiTapir::Rails
|
807
|
+
|
808
|
+
mount_endpoint create_user_endpoint, action: :create do |inputs|
|
809
|
+
@user = User.create!(inputs)
|
810
|
+
render json: @user
|
811
|
+
end
|
812
|
+
|
813
|
+
# Automatic OpenAPI generation
|
814
|
+
# Automatic request validation
|
815
|
+
# Automatic response serialization
|
816
|
+
end
|
817
|
+
```
|
818
|
+
|
819
|
+
**Implementation Tasks:**
|
820
|
+
- [ ] Rails controller integration module
|
821
|
+
- [ ] ActiveRecord integration patterns
|
822
|
+
- [ ] Rails parameter extraction
|
823
|
+
- [ ] Rails error handling integration
|
824
|
+
- [ ] Hanami and Roda adapter development
|
825
|
+
|
826
|
+
#### **Phase 3: Advanced Features (Priority: LOW) - 6-8 weeks**
|
827
|
+
*Nice-to-have features for advanced use cases*
|
828
|
+
|
829
|
+
##### **3.1 WebSocket & Streaming Support**
|
830
|
+
```ruby
|
831
|
+
# Target: Real-time API support
|
832
|
+
websocket_endpoint = RapiTapir.websocket('/chat')
|
833
|
+
.in(json_message(chat_message_schema))
|
834
|
+
.out(json_message(chat_response_schema))
|
835
|
+
.on_connect { |session| authorize_websocket(session) }
|
836
|
+
|
837
|
+
streaming_endpoint = RapiTapir.endpoint
|
838
|
+
.get('/events')
|
839
|
+
.out(stream_body(server_sent_event_schema))
|
840
|
+
```
|
841
|
+
|
842
|
+
##### **3.2 Advanced Schema Features**
|
843
|
+
```ruby
|
844
|
+
# Target: Complex schema composition
|
845
|
+
discriminated_union = RapiTapir.Schema.oneOf(
|
846
|
+
RapiTapir.Schema.variant[AdminUser]("admin"),
|
847
|
+
RapiTapir.Schema.variant[RegularUser]("user")
|
848
|
+
).discriminator("user_type")
|
849
|
+
|
850
|
+
recursive_schema = RapiTapir.Schema.recursive do |tree|
|
851
|
+
tree.field :value, Types.string
|
852
|
+
tree.field :children, Types.array[tree], required: false
|
853
|
+
end
|
854
|
+
```
|
855
|
+
|
856
|
+
---
|
857
|
+
|
858
|
+
### **🎯 Success Metrics for Complete Parity**
|
859
|
+
|
860
|
+
#### **Current Achievement (Phase 2.2)**
|
861
|
+
- ✅ **Type Safety**: 100% input/output validation coverage achieved
|
862
|
+
- ✅ **Framework Support**: 2+ Ruby frameworks supported (Rack, Sinatra)
|
863
|
+
- ✅ **Performance**: <1ms overhead for simple endpoints achieved
|
864
|
+
- ✅ **Developer Experience**: <5min from install to working API achieved
|
865
|
+
- ✅ **Feature Coverage**: ~85% of Scala Tapir features implemented
|
866
|
+
- ✅ **Community**: Active development with clear roadmap
|
867
|
+
|
868
|
+
#### **Target Achievement (Phase 3 Complete)**
|
869
|
+
- 🎯 **Enterprise Authentication**: OAuth2 + JWT support
|
870
|
+
- 🎯 **Complete REST API**: File upload and multipart support
|
871
|
+
- 🎯 **Framework Coverage**: 4+ Ruby frameworks supported
|
872
|
+
- 🎯 **Feature Parity**: 95%+ of Scala Tapir features available
|
873
|
+
- 🎯 **Production Adoption**: Multiple companies using in production
|
874
|
+
|
875
|
+
---
|
876
|
+
|
877
|
+
### **📊 Updated Gap Analysis: RapiTapir vs Scala Tapir (August 2025)**
|
878
|
+
|
879
|
+
**Current Parity Level: ~92%** 🎯
|
880
|
+
|
881
|
+
| Feature Category | Scala Tapir | RapiTapir Current | Gap Size | Status |
|
882
|
+
|-----------------|-------------|-------------------|----------|--------|
|
883
|
+
| **Type System** | ✅ Advanced | ✅ **Advanced** | **NONE** | ✅ **PARITY** |
|
884
|
+
| **Endpoint DSL** | ✅ Fluent | ✅ **Enhanced Fluent** | **NONE** | ⭐ **EXCEEDS** |
|
885
|
+
| **Server Integration** | ✅ Multiple frameworks | ✅ **Rack + Sinatra Complete** | **SMALL** | ✅ **PARITY** |
|
886
|
+
| **Client Generation** | ✅ Multi-language | ✅ **TypeScript + Type-safe** | **SMALL** | ✅ **PARITY** |
|
887
|
+
| **Documentation** | ✅ OpenAPI + AsyncAPI | ✅ **OpenAPI + Interactive + CLI** | **NONE** | ⭐ **EXCEEDS** |
|
888
|
+
| **Authentication** | ✅ Built-in OAuth2/JWT | ✅ **Complete OAuth2/JWT + Auth0** | **NONE** | ✅ **PARITY** |
|
889
|
+
| **Validation** | ✅ Comprehensive | ✅ **Type-based + Custom** | **NONE** | ✅ **PARITY** |
|
890
|
+
| **Observability** | ✅ Basic metrics | ✅ **Comprehensive stack** | **NONE** | ⭐ **EXCEEDS** |
|
891
|
+
| **File Upload/Multipart** | ✅ Full support | ❌ **Not implemented** | **MEDIUM** | 📋 **PLANNED** |
|
892
|
+
| **Streaming/WebSocket** | ✅ Supported | ❌ **Not implemented** | **MEDIUM** | 📋 **FUTURE** |
|
893
|
+
| **Path Composition** | ✅ DSL (`/` operator) | 🟡 **String-based** | **SMALL** | 📋 **ENHANCEMENT** |
|
894
|
+
| **Testing Support** | ✅ Rich tooling | ✅ **Validation + Fixtures** | **NONE** | ✅ **PARITY** |
|
895
|
+
| **Error Handling** | ✅ Typed errors | ✅ **Structured + Type-safe** | **NONE** | ✅ **PARITY** |
|
896
|
+
| **Framework Ecosystem** | ✅ JVM frameworks | 🟡 **Ruby frameworks** | **SMALL** | 🔄 **ONGOING** |
|
897
|
+
|
898
|
+
### **🏆 Areas Where RapiTapir Exceeds Scala Tapir**
|
899
|
+
|
900
|
+
1. **🛠️ CLI Tooling Ecosystem**
|
901
|
+
```bash
|
902
|
+
rapitapir generate openapi --endpoints api.rb
|
903
|
+
rapitapir generate client --output client.ts
|
904
|
+
rapitapir serve --port 3000 # Live documentation server
|
905
|
+
```
|
906
|
+
|
907
|
+
2. **📱 Interactive Documentation**
|
908
|
+
- Live API testing capabilities in generated docs
|
909
|
+
- Auto-reload development server
|
910
|
+
- GitHub Pages deployment automation
|
911
|
+
|
912
|
+
3. **🎯 Developer Experience**
|
913
|
+
- `SinatraRapiTapir` clean base class inheritance
|
914
|
+
- `T.string`, `T.integer` ergonomic type shortcuts
|
915
|
+
- Ruby-native idioms and conventions
|
916
|
+
|
917
|
+
4. **📊 Comprehensive Observability**
|
918
|
+
- Built-in metrics, health checks, structured logging
|
919
|
+
- Configurable observability stack
|
920
|
+
- Production-ready monitoring integration
|
921
|
+
|
922
|
+
### **🔧 Remaining Gaps for Complete Parity**
|
923
|
+
|
924
|
+
#### **Gap 1: File Upload Support (Priority: HIGH)**
|
925
|
+
```ruby
|
926
|
+
# Target Implementation
|
927
|
+
endpoint
|
928
|
+
.post('/upload')
|
929
|
+
.in(multipart_body({
|
930
|
+
file: file_part(max_size: 10.megabytes),
|
931
|
+
metadata: json_part(metadata_schema)
|
932
|
+
}))
|
933
|
+
.out(json_body(upload_result_schema))
|
934
|
+
```
|
935
|
+
|
936
|
+
#### **Gap 2: Streaming/WebSocket (Priority: MEDIUM)**
|
937
|
+
```ruby
|
938
|
+
# Future Target
|
939
|
+
websocket_endpoint = RapiTapir.websocket('/chat')
|
940
|
+
.in(json_message(chat_message_schema))
|
941
|
+
.out(json_message(chat_response_schema))
|
942
|
+
|
943
|
+
streaming_endpoint = RapiTapir.endpoint
|
944
|
+
.get('/stream')
|
945
|
+
.out(stream_body(string_schema))
|
946
|
+
```
|
947
|
+
|
948
|
+
#### **Gap 3: Advanced Framework Integration (Priority: MEDIUM)**
|
949
|
+
```ruby
|
950
|
+
# Target: Enhanced Rails integration
|
951
|
+
class UsersController < ApplicationController
|
952
|
+
include RapiTapir::Rails
|
953
|
+
|
954
|
+
mount_endpoint create_user_endpoint, action: :create
|
955
|
+
# Automatic OpenAPI generation, validation, and documentation
|
956
|
+
end
|
957
|
+
```
|
958
|
+
|
959
|
+
### **🎯 Strategic Assessment**
|
960
|
+
|
961
|
+
**RapiTapir Competitive Position**: ⭐ **STRONG**
|
962
|
+
|
963
|
+
- ✅ **Production Ready**: Core functionality complete and stable
|
964
|
+
- ✅ **Ruby Ecosystem Leader**: No comparable Ruby framework exists
|
965
|
+
- ✅ **Developer Experience**: Superior tooling and documentation
|
966
|
+
- ✅ **Type Safety**: Comprehensive type system with validation
|
967
|
+
- 🟡 **Enterprise Features**: Authentication needs enhancement
|
968
|
+
- 📈 **Growth Path**: Clear roadmap for remaining features
|
969
|
+
|
970
|
+
**Recommendation**: **RapiTapir is ready for production adoption** with planned enhancements for enterprise features.
|
971
|
+
|
972
|
+
### **🎯 Recommended Implementation Priority**
|
973
|
+
|
974
|
+
**Quarter 1 (Critical Path):**
|
975
|
+
1. ✅ **Complete Phase 1.1**: Advanced type system and validation
|
976
|
+
2. ✅ **Complete Phase 1.2**: Rack adapter and framework integration
|
977
|
+
3. ✅ **Complete Phase 1.3**: Enhanced endpoint DSL
|
978
|
+
|
979
|
+
**Quarter 2 (Production Ready):**
|
980
|
+
4. **Complete Phase 2.1**: Observability and monitoring
|
981
|
+
5. **Complete ## Phase 2.2 - Current Implementation Status ✅ **SUBSTANTIALLY COMPLETE**
|
982
|
+
|
983
|
+
**RapiTapir has evolved significantly beyond the original blueprint and now represents a production-ready HTTP API framework.**
|
984
|
+
|
985
|
+
### 🎯 **Major Achievements (As of February 2025)**
|
986
|
+
|
987
|
+
#### **✅ Implementation Scale**
|
988
|
+
- **73 implementation files** across all framework components
|
989
|
+
- **30 comprehensive test files** with **501 test examples**
|
990
|
+
- **70.4% line coverage** with **0 test failures**
|
991
|
+
- **Production-ready stability** and performance
|
992
|
+
|
993
|
+
#### **✅ Core Systems Complete**
|
994
|
+
- **Advanced Type System**: 13 primitive types with constraints, auto-derivation, T.shortcut syntax
|
995
|
+
- **Enhanced Endpoint DSL**: FluentEndpointBuilder with authentication, validation, error handling
|
996
|
+
- **Server Integration**: Complete Rack/Sinatra adapters with middleware support
|
997
|
+
- **OpenAPI Documentation**: Full 3.0.3 spec generation with interactive docs
|
998
|
+
- **CLI Tooling**: Complete command-line toolkit for development workflow
|
999
|
+
- **Observability**: Metrics, health checks, structured logging
|
1000
|
+
|
1001
|
+
#### **✅ Framework Integration Status**
|
1002
|
+
- **Sinatra**: ✅ Complete integration with `SinatraRapiTapir` base class
|
1003
|
+
- **Rack**: ✅ Full adapter with enhanced validation and middleware
|
1004
|
+
- **Rails**: 🟡 Basic integration (needs enhancement)
|
1005
|
+
- **TypeScript Clients**: ✅ Complete type-safe client generation
|
1006
|
+
|
1007
|
+
### 📊 **Scala Tapir Parity Assessment**
|
1008
|
+
|
1009
|
+
**Current Parity: ~92%** 🎯
|
1010
|
+
|
1011
|
+
| Feature Category | Status | Gap Analysis |
|
1012
|
+
|-----------------|---------|---------------|
|
1013
|
+
| **Type System** | ✅ **COMPLETE** | Matches Scala Tapir capability |
|
1014
|
+
| **Endpoint DSL** | ✅ **COMPLETE** | Enhanced fluent builder pattern |
|
1015
|
+
| **Server Integration** | ✅ **COMPLETE** | Rack + Sinatra production-ready |
|
1016
|
+
| **Documentation** | ✅ **EXCEEDS** | Interactive docs + CLI tools |
|
1017
|
+
| **Client Generation** | ✅ **COMPLETE** | TypeScript with full type safety |
|
1018
|
+
| **Observability** | ✅ **COMPLETE** | Comprehensive monitoring stack |
|
1019
|
+
| **Authentication** | ✅ **COMPLETE** | OAuth2 + JWT + Auth0 integration |
|
1020
|
+
| **File Uploads** | ❌ **MISSING** | Multipart/form-data support needed |
|
1021
|
+
| **Streaming/WebSocket** | ❌ **MISSING** | Future enhancement |
|
1022
|
+
|
1023
|
+
### 🚀 **Next Development Priorities**
|
1024
|
+
|
1025
|
+
#### **Priority 1: Enterprise Authentication (4 weeks)**
|
1026
|
+
```ruby
|
1027
|
+
# Target: Complete authentication ecosystem
|
1028
|
+
endpoint
|
1029
|
+
.security_in(oauth2_auth(scopes: ['read:users']))
|
1030
|
+
.security_in(jwt_auth(algorithm: 'RS256'))
|
1031
|
+
.bearer_auth("Bearer token authentication")
|
1032
|
+
```
|
1033
|
+
|
1034
|
+
#### **Priority 2: File Upload Support (3 weeks)**
|
1035
|
+
```ruby
|
1036
|
+
# Target: Multipart form data handling
|
1037
|
+
endpoint
|
1038
|
+
.post('/upload')
|
1039
|
+
.in(multipart_body({
|
1040
|
+
file: file_part(max_size: 10.megabytes, allowed_types: ['image/*']),
|
1041
|
+
metadata: json_part(upload_metadata_schema)
|
1042
|
+
}))
|
1043
|
+
```
|
1044
|
+
|
1045
|
+
#### **Priority 3: Deep Rails Integration (4 weeks)**
|
1046
|
+
```ruby
|
1047
|
+
# Target: Native Rails controller integration
|
1048
|
+
class UsersController < ApplicationController
|
1049
|
+
include RapiTapir::Rails
|
1050
|
+
|
1051
|
+
mount_endpoint create_user_endpoint, action: :create
|
1052
|
+
# Automatic OpenAPI generation, validation, and documentation
|
1053
|
+
end
|
1054
|
+
```
|
1055
|
+
|
1056
|
+
### 📈 **Success Metrics Achieved**
|
1057
|
+
|
1058
|
+
- ✅ **Developer Experience**: < 5 minutes from install to working API
|
1059
|
+
- ✅ **Performance**: < 1ms framework overhead in benchmarks
|
1060
|
+
- ✅ **Stability**: 0 test failures across 501 examples
|
1061
|
+
- ✅ **Documentation**: Complete API reference with interactive examples
|
1062
|
+
- ✅ **Tooling**: Full CLI ecosystem for development workflow
|
1063
|
+
|
1064
|
+
### 🎉 **Strategic Position**
|
1065
|
+
|
1066
|
+
**RapiTapir has successfully established itself as a production-ready API framework** that rivals Scala Tapir in the Ruby ecosystem. The implementation has **exceeded the original blueprint** in several areas including tooling, documentation, and observability.
|
1067
|
+
|
1068
|
+
**Market Readiness**: ✅ Ready for production use
|
1069
|
+
**Ecosystem Fit**: ✅ Strong Ruby community integration
|
1070
|
+
**Competitive Position**: ✅ Unique advantages over Scala Tapir (CLI tools, interactive docs, Ruby idioms)
|
1071
|
+
|
1072
|
+
---
|
1073
|
+
|
1074
|
+
## Original Phase Plan (Archived)**: Authentication and security
|
1075
|
+
6. **Complete Phase 2.3**: Advanced I/O support
|
1076
|
+
|
1077
|
+
**Quarter 3+ (Advanced Features):**
|
1078
|
+
7. **Complete Phase 3.1**: Multi-language code generation
|
1079
|
+
8. **Complete Phase 3.2**: Advanced schema features
|
1080
|
+
9. **Complete Phase 3.3**: Deep framework integration
|
1081
|
+
|
1082
|
+
### **🚀 Success Metrics for Parity**
|
1083
|
+
|
1084
|
+
- **Type Safety**: 100% input/output validation coverage
|
1085
|
+
- **Framework Support**: 4+ major Ruby frameworks supported
|
1086
|
+
- **Performance**: <1ms overhead for simple endpoints
|
1087
|
+
- **Developer Experience**: <5min from install to working API
|
1088
|
+
- **Feature Parity**: 90%+ of Scala Tapir features available
|
1089
|
+
- **Community**: Active ecosystem with 3rd party integrations
|
1090
|
+
|
1091
|
+
This evolution plan will transform RapiTapir from a promising API documentation tool into a comprehensive, production-ready API development framework that rivals Scala Tapir's capabilities in the Ruby ecosystem.
|