api-regulator 0.1.28 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +214 -32
- data/lib/api_regulator/configuration.rb +1 -1
- data/lib/api_regulator/open_api_generator.rb +2 -2
- data/lib/api_regulator/version.rb +1 -1
- data/lib/tasks/api_regulator_tasks.rake +102 -114
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bcf52fc47c491d424f53b82688cfa8a3f0b78b62460267f1ad81abcf695827d
|
4
|
+
data.tar.gz: 1bb55ea5e11bff7fce98874adf0ca5d79db2431eabf4cafdaaf2dec7b4bb6fa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c872be90e74a524e316958afc1486464612854794ca86f0fe78aef6ea9a67bc1779870eecd7fc8750987e0a5f3b2ca5a99c7af6047add3f3fb83d0e86c326d8b
|
7
|
+
data.tar.gz: e55567f1b2c788bae49bb536aee0aa10e9f6fa6c490ec04632c42a0b6acb0fb2758c54ef6c7944806aeb3453c197cf2bce749977c324d523dbca1c88eb19bf44
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,7 @@ ApiRegulator leverages **Active Model validations** for parameter validation, ma
|
|
13
13
|
- **🏷️ API Versioning**: Support multiple API versions with selective parameter inclusion
|
14
14
|
- **🔒 Security Schemes**: Define authentication and authorization schemes
|
15
15
|
- **🔄 Shared Schemas**: Reuse common response and parameter schemas across multiple endpoints
|
16
|
-
- **📚 ReadMe Integration**: Built-in tasks for uploading
|
16
|
+
- **📚 ReadMe Integration**: Built-in tasks for generating OpenAPI specs and seamless integration with rdme CLI for uploading to ReadMe.com
|
17
17
|
- **🛡️ Parameter Validation**: Strict validation with helpful error messages for unexpected parameters
|
18
18
|
- **📄 Custom Page Management**: Upload and manage documentation pages alongside API specs
|
19
19
|
|
@@ -27,6 +27,20 @@ gem 'api_regulator'
|
|
27
27
|
|
28
28
|
Run `bundle install` to install the gem.
|
29
29
|
|
30
|
+
### Optional: Install rdme CLI for ReadMe Integration
|
31
|
+
|
32
|
+
For uploading documentation to ReadMe, install the rdme CLI:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
npm install -g rdme
|
36
|
+
```
|
37
|
+
|
38
|
+
Or as a project dependency:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
npm install rdme --save-dev
|
42
|
+
```
|
43
|
+
|
30
44
|
## Setup
|
31
45
|
|
32
46
|
### 1. Create an Initializer
|
@@ -91,7 +105,7 @@ class Api::V1::CustomersController < Api::ApplicationController
|
|
91
105
|
# Path parameters
|
92
106
|
param :organization_id, :string, location: :path, presence: true
|
93
107
|
|
94
|
-
# Query parameters
|
108
|
+
# Query parameters
|
95
109
|
param :expand, :string, location: :query, desc: "Comma-separated list of fields to expand"
|
96
110
|
|
97
111
|
# Body parameters
|
@@ -101,7 +115,7 @@ class Api::V1::CustomersController < Api::ApplicationController
|
|
101
115
|
param :email, :string, presence: true, format: { with: ApiRegulator::Formats::EMAIL }
|
102
116
|
param :ssn, :string, presence: true, length: { is: 9 }
|
103
117
|
param :date_of_birth, :string, format: { with: ApiRegulator::Formats::DATE }
|
104
|
-
|
118
|
+
|
105
119
|
# Nested objects
|
106
120
|
param :address, :object do
|
107
121
|
param :street, :string, presence: true
|
@@ -134,7 +148,7 @@ class Api::V1::CustomersController < Api::ApplicationController
|
|
134
148
|
|
135
149
|
def create
|
136
150
|
validate_params! # Validates against DSL definition
|
137
|
-
|
151
|
+
|
138
152
|
customer = Customer.create!(api_params[:customer])
|
139
153
|
render json: { customer: customer }, status: :created
|
140
154
|
end
|
@@ -146,7 +160,7 @@ end
|
|
146
160
|
#### Conditional Requirements
|
147
161
|
|
148
162
|
```ruby
|
149
|
-
param :ssn, :string, presence: {
|
163
|
+
param :ssn, :string, presence: {
|
150
164
|
required_on: [:create, :update], # Required only for these actions
|
151
165
|
required_except_on: [:show] # Required except for these actions
|
152
166
|
}
|
@@ -234,11 +248,11 @@ Define webhook payloads using the same DSL:
|
|
234
248
|
|
235
249
|
```ruby
|
236
250
|
class WebhookDefinitions < Api::ApplicationController
|
237
|
-
webhook :customer_created,
|
251
|
+
webhook :customer_created,
|
238
252
|
desc: "Fired when a new customer is created",
|
239
253
|
title: "Customer Created",
|
240
254
|
tags: ["customers", "webhooks"] do
|
241
|
-
|
255
|
+
|
242
256
|
param :event, :string, desc: "Event name"
|
243
257
|
param :timestamp, :string, desc: "ISO 8601 timestamp"
|
244
258
|
param :data do
|
@@ -299,7 +313,7 @@ end
|
|
299
313
|
```ruby
|
300
314
|
def create
|
301
315
|
validate_params! # Raises ApiRegulator::InvalidParams or ApiRegulator::UnexpectedParams
|
302
|
-
|
316
|
+
|
303
317
|
# Access validated and type-converted parameters
|
304
318
|
customer_data = api_params[:customer]
|
305
319
|
# Process with confidence that data is valid
|
@@ -314,16 +328,16 @@ class Api::ApplicationController < ActionController::API
|
|
314
328
|
include ApiRegulator::ControllerMixin
|
315
329
|
|
316
330
|
rescue_from ApiRegulator::InvalidParams do |exception|
|
317
|
-
render json: {
|
331
|
+
render json: {
|
318
332
|
errors: exception.errors.messages,
|
319
|
-
message: "Validation failed"
|
333
|
+
message: "Validation failed"
|
320
334
|
}, status: :unprocessable_entity
|
321
335
|
end
|
322
336
|
|
323
337
|
rescue_from ApiRegulator::UnexpectedParams do |exception|
|
324
|
-
render json: {
|
338
|
+
render json: {
|
325
339
|
errors: exception.details,
|
326
|
-
message: "Unexpected parameters provided"
|
340
|
+
message: "Unexpected parameters provided"
|
327
341
|
}, status: :bad_request
|
328
342
|
end
|
329
343
|
end
|
@@ -331,6 +345,18 @@ end
|
|
331
345
|
|
332
346
|
## OpenAPI Documentation Generation
|
333
347
|
|
348
|
+
### Validate OpenAPI Specification
|
349
|
+
|
350
|
+
Before uploading, validate your OpenAPI specification using rdme:
|
351
|
+
|
352
|
+
```bash
|
353
|
+
# Validate the generated OpenAPI spec
|
354
|
+
rdme openapi validate doc/openapi.yaml
|
355
|
+
|
356
|
+
# Validate with specific version
|
357
|
+
rdme openapi validate doc/openapi.yaml --version=v1.0
|
358
|
+
```
|
359
|
+
|
334
360
|
### Generate Documentation
|
335
361
|
|
336
362
|
```bash
|
@@ -346,23 +372,84 @@ rake api_docs:generate_all
|
|
346
372
|
|
347
373
|
### Upload to ReadMe
|
348
374
|
|
349
|
-
|
375
|
+
ApiRegulator integrates with [rdme](https://github.com/readmeio/rdme), ReadMe's official CLI tool, for modern, secure, and reliable documentation management.
|
376
|
+
|
377
|
+
#### Installation
|
378
|
+
|
379
|
+
Install the rdme CLI globally:
|
380
|
+
|
381
|
+
```bash
|
382
|
+
npm install -g rdme
|
383
|
+
```
|
384
|
+
|
385
|
+
Or install it as a project dependency:
|
386
|
+
|
387
|
+
```bash
|
388
|
+
npm install rdme --save-dev
|
389
|
+
```
|
390
|
+
|
391
|
+
#### Authentication
|
392
|
+
|
393
|
+
Authenticate with ReadMe using the CLI:
|
394
|
+
|
395
|
+
```bash
|
396
|
+
rdme login
|
397
|
+
```
|
398
|
+
|
399
|
+
Alternatively, set your API key as an environment variable:
|
350
400
|
|
351
401
|
```bash
|
352
402
|
export RDME_API_KEY="your_readme_api_key"
|
353
403
|
```
|
354
404
|
|
405
|
+
#### Upload Commands
|
406
|
+
|
407
|
+
**Recommended approach using rdme CLI:**
|
408
|
+
|
355
409
|
```bash
|
356
|
-
#
|
357
|
-
rake api_docs:
|
410
|
+
# Generate and upload everything using rdme (RECOMMENDED)
|
411
|
+
rake api_docs:publish_rdme
|
358
412
|
|
359
|
-
#
|
413
|
+
# Or step by step:
|
414
|
+
rake api_docs:generate
|
415
|
+
rake api_docs:upload_rdme
|
416
|
+
rdme docs upload doc/
|
417
|
+
```
|
418
|
+
|
419
|
+
**Legacy approach (may not work with ReadMe API v2):**
|
420
|
+
|
421
|
+
```bash
|
422
|
+
# Generate OpenAPI specification
|
423
|
+
rake api_docs:generate
|
424
|
+
|
425
|
+
# Upload using legacy rake tasks (deprecated)
|
426
|
+
rake api_docs:upload
|
360
427
|
rake api_docs:upload_pages
|
428
|
+
```
|
429
|
+
|
430
|
+
#### Migration from Legacy Tasks
|
431
|
+
|
432
|
+
If you're experiencing 404 errors with the legacy upload tasks, migrate to rdme CLI:
|
433
|
+
|
434
|
+
```bash
|
435
|
+
# Run the migration script
|
436
|
+
./scripts/migrate_to_rdme.sh
|
361
437
|
|
362
|
-
#
|
363
|
-
|
438
|
+
# Or manually:
|
439
|
+
npm install -g rdme
|
440
|
+
rdme login
|
441
|
+
rake api_docs:publish_rdme
|
364
442
|
```
|
365
443
|
|
444
|
+
**rdme CLI Features:**
|
445
|
+
|
446
|
+
- Modern ReadMe API v2 integration
|
447
|
+
- Bearer token authentication (more secure)
|
448
|
+
- Better performance and reliability
|
449
|
+
- Support for ReadMe Refactored features
|
450
|
+
- Branch-based versioning
|
451
|
+
- Built-in validation and error handling
|
452
|
+
|
366
453
|
### Custom Documentation Pages
|
367
454
|
|
368
455
|
Create markdown files in your `docs_path` with YAML frontmatter:
|
@@ -380,14 +467,60 @@ hidden: false
|
|
380
467
|
Your API documentation content here...
|
381
468
|
```
|
382
469
|
|
470
|
+
### GitHub Actions Integration
|
471
|
+
|
472
|
+
Use rdme in your GitHub Actions workflow for automated documentation updates:
|
473
|
+
|
474
|
+
```yaml
|
475
|
+
name: Update API Documentation
|
476
|
+
|
477
|
+
on:
|
478
|
+
push:
|
479
|
+
branches: [main]
|
480
|
+
pull_request:
|
481
|
+
branches: [main]
|
482
|
+
|
483
|
+
jobs:
|
484
|
+
update-docs:
|
485
|
+
runs-on: ubuntu-latest
|
486
|
+
|
487
|
+
steps:
|
488
|
+
- name: Checkout code
|
489
|
+
uses: actions/checkout@v4
|
490
|
+
|
491
|
+
- name: Setup Ruby
|
492
|
+
uses: ruby/setup-ruby@v1
|
493
|
+
with:
|
494
|
+
ruby-version: 3.0
|
495
|
+
|
496
|
+
- name: Install dependencies
|
497
|
+
run: |
|
498
|
+
gem install bundler
|
499
|
+
bundle install
|
500
|
+
|
501
|
+
- name: Generate and upload API documentation
|
502
|
+
run: rake api_docs:publish_rdme
|
503
|
+
env:
|
504
|
+
RDME_API_KEY: ${{ secrets.RDME_API_KEY }}
|
505
|
+
```
|
506
|
+
|
383
507
|
### ReadMe Integration Features
|
384
508
|
|
385
509
|
```bash
|
386
|
-
#
|
387
|
-
|
510
|
+
# Validate OpenAPI specification
|
511
|
+
rdme openapi validate doc/openapi.yaml
|
512
|
+
|
513
|
+
# Upload OpenAPI spec using rake task (recommended)
|
514
|
+
rake api_docs:upload_rdme
|
388
515
|
|
389
516
|
# Upload with specific version
|
390
|
-
VERSION=v2.0 rake api_docs:
|
517
|
+
VERSION=v2.0 rake api_docs:upload_rdme
|
518
|
+
|
519
|
+
# Upload directly with rdme CLI
|
520
|
+
rdme openapi upload doc/openapi.yaml --version=v2.0
|
521
|
+
|
522
|
+
# Fetch available categories
|
523
|
+
rdme categories list
|
391
524
|
```
|
392
525
|
|
393
526
|
## Built-in Format Validators
|
@@ -396,7 +529,7 @@ ApiRegulator includes common format validators:
|
|
396
529
|
|
397
530
|
```ruby
|
398
531
|
ApiRegulator::Formats::DATE # ISO 8601 date format
|
399
|
-
ApiRegulator::Formats::DATETIME # ISO 8601 datetime format
|
532
|
+
ApiRegulator::Formats::DATETIME # ISO 8601 datetime format
|
400
533
|
ApiRegulator::Formats::EMAIL # Email address validation
|
401
534
|
ApiRegulator::Formats::ZIP_CODE # US ZIP code (12345 or 12345-6789)
|
402
535
|
ApiRegulator::Formats::URI # URI format validation
|
@@ -426,11 +559,11 @@ RSpec.describe Api::V1::CustomersController do
|
|
426
559
|
params = {
|
427
560
|
customer: {
|
428
561
|
first_name: "John",
|
429
|
-
last_name: "Doe",
|
562
|
+
last_name: "Doe",
|
430
563
|
email: "john@example.com"
|
431
564
|
}
|
432
565
|
}
|
433
|
-
|
566
|
+
|
434
567
|
post "/api/v1/customers", params: params
|
435
568
|
expect(response).to have_http_status(:created)
|
436
569
|
end
|
@@ -444,22 +577,22 @@ end
|
|
444
577
|
ApiRegulator.configure do |config|
|
445
578
|
# Base URL for all API endpoints (default: "api/v1")
|
446
579
|
config.api_base_url = "/api/v1"
|
447
|
-
|
580
|
+
|
448
581
|
# Application name shown in documentation (default: "API Documentation")
|
449
582
|
config.app_name = "My API"
|
450
|
-
|
583
|
+
|
451
584
|
# Directory for documentation files (default: "doc")
|
452
585
|
config.docs_path = Rails.root.join("doc").to_s
|
453
|
-
|
586
|
+
|
454
587
|
# Version mapping for ReadMe (optional)
|
455
588
|
config.versions = {
|
456
589
|
"v1.0" => "readme_spec_id_1",
|
457
590
|
"v2.0" => "readme_spec_id_2"
|
458
591
|
}
|
459
|
-
|
592
|
+
|
460
593
|
# Default version when none specified (optional)
|
461
594
|
config.default_version = "v1.0"
|
462
|
-
|
595
|
+
|
463
596
|
# Server definitions for OpenAPI spec (optional)
|
464
597
|
config.servers = [
|
465
598
|
{ url: "https://api.example.com", description: "Production" },
|
@@ -476,7 +609,7 @@ end
|
|
476
609
|
# Define version-specific endpoints
|
477
610
|
api self, :create, versions: [:v1, :v2] do
|
478
611
|
param :name, :string, presence: true
|
479
|
-
param :email, :string, presence: true, versions: [:v1, :v2]
|
612
|
+
param :email, :string, presence: true, versions: [:v1, :v2]
|
480
613
|
param :phone, :string, versions: [:v2] # Only in v2
|
481
614
|
end
|
482
615
|
```
|
@@ -487,7 +620,7 @@ end
|
|
487
620
|
api self, :create do
|
488
621
|
# This endpoint requires authentication
|
489
622
|
security [{ bearer_auth: [] }]
|
490
|
-
|
623
|
+
|
491
624
|
param :customer do
|
492
625
|
param :name, :string, presence: true
|
493
626
|
end
|
@@ -500,12 +633,61 @@ end
|
|
500
633
|
def update
|
501
634
|
# Validate with specific context
|
502
635
|
validate_params!
|
503
|
-
|
636
|
+
|
504
637
|
# The validation context is automatically set to the action name (:update)
|
505
638
|
# This allows conditional validations based on the action
|
506
639
|
end
|
507
640
|
```
|
508
641
|
|
642
|
+
## Troubleshooting
|
643
|
+
|
644
|
+
### Common Issues
|
645
|
+
|
646
|
+
#### 404 Error When Uploading Pages
|
647
|
+
|
648
|
+
If you get a 404 error when uploading documentation pages:
|
649
|
+
|
650
|
+
```
|
651
|
+
Failed to upload page 'Webhooks'!
|
652
|
+
Response Code: 404
|
653
|
+
```
|
654
|
+
|
655
|
+
**Solution:** The legacy rake tasks may not work with ReadMe API v2. Use rdme CLI instead:
|
656
|
+
|
657
|
+
```bash
|
658
|
+
# Install and authenticate with rdme
|
659
|
+
npm install -g rdme
|
660
|
+
rdme login
|
661
|
+
|
662
|
+
# Use the recommended approach
|
663
|
+
rake api_docs:publish_rdme
|
664
|
+
```
|
665
|
+
|
666
|
+
#### Authentication Issues
|
667
|
+
|
668
|
+
If you get authentication errors:
|
669
|
+
|
670
|
+
```bash
|
671
|
+
# Check your authentication status
|
672
|
+
rdme whoami
|
673
|
+
|
674
|
+
# Re-authenticate if needed
|
675
|
+
rdme logout
|
676
|
+
rdme login
|
677
|
+
```
|
678
|
+
|
679
|
+
#### OpenAPI Validation Errors
|
680
|
+
|
681
|
+
Validate your OpenAPI spec before uploading:
|
682
|
+
|
683
|
+
```bash
|
684
|
+
# Validate the generated spec
|
685
|
+
rdme openapi validate doc/openapi.yaml
|
686
|
+
|
687
|
+
# Check for common issues
|
688
|
+
rdme openapi validate doc/openapi.yaml --verbose
|
689
|
+
```
|
690
|
+
|
509
691
|
## Error Reference
|
510
692
|
|
511
693
|
- `ApiRegulator::InvalidParams`: Raised when request parameters fail validation
|
@@ -30,12 +30,12 @@ module ApiRegulator
|
|
30
30
|
openapi: '3.1.0', # Explicitly target OpenAPI 3.1.0
|
31
31
|
info: {
|
32
32
|
title: ApiRegulator.configuration.app_name,
|
33
|
-
description: 'Generated by ApiRegulator'
|
33
|
+
description: 'Generated by ApiRegulator',
|
34
|
+
version: version.presence || '1.0.0'
|
34
35
|
},
|
35
36
|
servers: ApiRegulator.configuration.servers,
|
36
37
|
paths: {}
|
37
38
|
}
|
38
|
-
final_schema[:info][:version] = version if version.present?
|
39
39
|
|
40
40
|
add_components
|
41
41
|
add_security
|
@@ -23,128 +23,116 @@ namespace :api_docs do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
desc "Upload OpenAPI schema to ReadMe"
|
27
|
-
task :
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
desc "Upload OpenAPI schema to ReadMe using rdme CLI (RECOMMENDED)"
|
27
|
+
task upload_rdme: :environment do
|
28
|
+
# Check if rdme is available
|
29
|
+
unless system("which rdme > /dev/null 2>&1")
|
30
|
+
puts "❌ rdme CLI not found. Please install it first:"
|
31
|
+
puts " npm install -g rdme"
|
32
|
+
puts " rdme login"
|
33
|
+
exit 1
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
schema_path =
|
36
|
+
version = ENV['VERSION'] || ApiRegulator.configuration.default_version
|
37
|
+
schema_path = ApiRegulator::OpenApiGenerator.schema_file_path(version: version)
|
38
|
+
|
37
39
|
unless File.exist?(schema_path)
|
38
|
-
raise "OpenAPI schema file not found at #{schema_path}"
|
40
|
+
raise "OpenAPI schema file not found at #{schema_path}. Run 'rake api_docs:generate' first."
|
39
41
|
end
|
40
|
-
openapi_content = File.read(schema_path)
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
puts "📄 Uploading OpenAPI specification with rdme CLI..."
|
44
|
+
puts " Schema: #{schema_path}"
|
45
|
+
puts " Version: #{version || 'default'}"
|
46
|
+
puts ""
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
# Use rdme CLI to upload
|
49
|
+
if system("rdme openapi upload #{schema_path}")
|
50
|
+
puts "✅ OpenAPI schema successfully uploaded!"
|
50
51
|
else
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
request["Authorization"] = "Basic #{Base64.strict_encode64(readme_api_key)}"
|
55
|
-
request["Content-Type"] = "application/json"
|
56
|
-
request["x-readme-version"] = version if version.present?
|
57
|
-
request.body = {
|
58
|
-
spec: JSON.parse(openapi_content)
|
59
|
-
}.to_json
|
60
|
-
|
61
|
-
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
62
|
-
http.request(request)
|
52
|
+
puts "❌ Failed to upload OpenAPI schema"
|
53
|
+
exit 1
|
63
54
|
end
|
55
|
+
end
|
64
56
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
57
|
+
desc "Upload OpenAPI schema to ReadMe (LEGACY - may not work with ReadMe API v2)"
|
58
|
+
task :upload => :environment do
|
59
|
+
puts "⚠️ WARNING: This rake task is deprecated and may not work with ReadMe API v2."
|
60
|
+
puts " Please use the rdme CLI instead:"
|
61
|
+
puts " "
|
62
|
+
puts " # Install rdme CLI"
|
63
|
+
puts " npm install -g rdme"
|
64
|
+
puts " "
|
65
|
+
puts " # Authenticate with ReadMe"
|
66
|
+
puts " rdme login"
|
67
|
+
puts " "
|
68
|
+
puts " # Upload using rdme CLI"
|
69
|
+
puts " rake api_docs:upload_rdme"
|
70
|
+
puts " "
|
71
|
+
puts " For more information, see: https://github.com/readmeio/rdme"
|
72
|
+
puts " "
|
73
|
+
|
74
|
+
# Check if rdme is available
|
75
|
+
if system("which rdme > /dev/null 2>&1")
|
76
|
+
puts "✅ rdme CLI is installed. Running: rake api_docs:upload_rdme"
|
77
|
+
Rake::Task["api_docs:upload_rdme"].invoke
|
75
78
|
else
|
76
|
-
puts "
|
77
|
-
puts "
|
78
|
-
|
79
|
-
pp JSON.parse(response.body)
|
79
|
+
puts "❌ rdme CLI not found. Please install it first:"
|
80
|
+
puts " npm install -g rdme"
|
81
|
+
exit 1
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
|
-
desc 'Generate and upload OpenAPI schema'
|
85
|
+
desc 'Generate and upload OpenAPI schema using rdme CLI (RECOMMENDED)'
|
86
|
+
task publish_rdme: :environment do
|
87
|
+
Rake::Task["api_docs:generate"].invoke
|
88
|
+
Rake::Task["api_docs:upload_rdme"].invoke
|
89
|
+
|
90
|
+
puts "📄 Uploading documentation pages with rdme CLI..."
|
91
|
+
system("rdme docs upload #{ApiRegulator.configuration.docs_path}/")
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'Generate and upload OpenAPI schema (LEGACY - may not work with ReadMe API v2)'
|
84
95
|
task publish: :environment do
|
85
96
|
Rake::Task["api_docs:generate"].invoke
|
86
97
|
Rake::Task["api_docs:upload"].invoke
|
87
|
-
|
98
|
+
|
99
|
+
# Check if rdme is available for uploading pages
|
100
|
+
if system("which rdme > /dev/null 2>&1")
|
101
|
+
puts "📄 Uploading documentation pages with rdme CLI..."
|
102
|
+
system("rdme docs upload #{ApiRegulator.configuration.docs_path}/")
|
103
|
+
else
|
104
|
+
puts "⚠️ rdme CLI not found. Skipping documentation pages upload."
|
105
|
+
puts " Install rdme CLI to upload documentation pages:"
|
106
|
+
puts " npm install -g rdme"
|
107
|
+
puts " rdme docs upload #{ApiRegulator.configuration.docs_path}/"
|
108
|
+
end
|
88
109
|
end
|
89
110
|
|
90
|
-
desc "Upload custom pages to ReadMe"
|
111
|
+
desc "Upload custom pages to ReadMe (DEPRECATED - Use rdme CLI instead)"
|
91
112
|
task :upload_pages => :environment do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
request_body["slug"] ||= slug
|
116
|
-
|
117
|
-
raise("Title missing in #{file_path}") unless request_body["title"].present?
|
118
|
-
|
119
|
-
# Build the API request
|
120
|
-
if check_if_page_exists(slug)
|
121
|
-
uri = URI.parse("#{base_readme_api_endpoint}/#{slug}")
|
122
|
-
request = Net::HTTP::Put.new(uri)
|
123
|
-
else
|
124
|
-
uri = URI.parse("#{base_readme_api_endpoint}")
|
125
|
-
request = Net::HTTP::Post.new(uri)
|
126
|
-
end
|
127
|
-
request["Authorization"] = "Basic #{Base64.strict_encode64(readme_api_key)}"
|
128
|
-
request["Content-Type"] = "application/json"
|
129
|
-
request["x-readme-version"] = version if version.present?
|
130
|
-
request.body = request_body.compact.to_json
|
131
|
-
|
132
|
-
# Send the request
|
133
|
-
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
134
|
-
http.request(request)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Handle the response
|
138
|
-
case response.code.to_i
|
139
|
-
when 200
|
140
|
-
puts "Page '#{request_body["title"]}' successfully updated!"
|
141
|
-
when 201
|
142
|
-
puts "Page '#{request_body["title"]}' successfully created!"
|
143
|
-
else
|
144
|
-
puts "Failed to upload page '#{request_body["title"]}'!"
|
145
|
-
puts "Response Code: #{response.code}"
|
146
|
-
puts "Response Body: #{response.body}"
|
147
|
-
end
|
113
|
+
puts "⚠️ WARNING: This rake task is deprecated and may not work with ReadMe API v2."
|
114
|
+
puts " Please use the rdme CLI instead:"
|
115
|
+
puts " "
|
116
|
+
puts " # Install rdme CLI"
|
117
|
+
puts " npm install -g rdme"
|
118
|
+
puts " "
|
119
|
+
puts " # Authenticate with ReadMe"
|
120
|
+
puts " rdme login"
|
121
|
+
puts " "
|
122
|
+
puts " # Upload documentation pages"
|
123
|
+
puts " rdme docs upload #{ApiRegulator.configuration.docs_path}/"
|
124
|
+
puts " "
|
125
|
+
puts " For more information, see: https://github.com/readmeio/rdme"
|
126
|
+
puts " "
|
127
|
+
|
128
|
+
# Check if rdme is available
|
129
|
+
if system("which rdme > /dev/null 2>&1")
|
130
|
+
puts "✅ rdme CLI is installed. Running: rdme docs upload #{ApiRegulator.configuration.docs_path}/"
|
131
|
+
system("rdme docs upload #{ApiRegulator.configuration.docs_path}/")
|
132
|
+
else
|
133
|
+
puts "❌ rdme CLI not found. Please install it first:"
|
134
|
+
puts " npm install -g rdme"
|
135
|
+
exit 1
|
148
136
|
end
|
149
137
|
end
|
150
138
|
|
@@ -152,15 +140,13 @@ namespace :api_docs do
|
|
152
140
|
task :fetch_categories => :environment do
|
153
141
|
# Configuration
|
154
142
|
readme_api_key = ENV['RDME_API_KEY'].presence || raise("RDME_API_KEY is not set")
|
155
|
-
|
156
|
-
readme_categories_api_endpoint = "https://dash.readme.com/api/v1/categories"
|
143
|
+
readme_categories_api_endpoint = "https://api.readme.com/v2/categories"
|
157
144
|
|
158
145
|
# Build the API request
|
159
146
|
uri = URI.parse(readme_categories_api_endpoint)
|
160
147
|
request = Net::HTTP::Get.new(uri)
|
161
|
-
request["Authorization"] = "
|
148
|
+
request["Authorization"] = "Bearer #{readme_api_key}"
|
162
149
|
request["Content-Type"] = "application/json"
|
163
|
-
request["x-readme-version"] = version if version.present?
|
164
150
|
|
165
151
|
# Send the request
|
166
152
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
@@ -171,7 +157,10 @@ namespace :api_docs do
|
|
171
157
|
case response.code.to_i
|
172
158
|
when 200
|
173
159
|
puts "Categories"
|
174
|
-
|
160
|
+
response_data = JSON.parse(response.body)
|
161
|
+
# API v2 response format - returns data in a 'data' wrapper
|
162
|
+
categories = response_data.dig("data") || response_data
|
163
|
+
pp categories
|
175
164
|
else
|
176
165
|
puts "Failed to fetch categories"
|
177
166
|
puts "Response Code: #{response.code}"
|
@@ -195,14 +184,13 @@ namespace :api_docs do
|
|
195
184
|
[metadata, body]
|
196
185
|
end
|
197
186
|
|
198
|
-
def check_if_page_exists(slug)
|
187
|
+
def check_if_page_exists(slug, branch = "stable")
|
199
188
|
readme_api_key = ENV['RDME_API_KEY'].presence || raise("RDME_API_KEY is not set")
|
200
|
-
|
201
|
-
uri = URI.parse("https://
|
189
|
+
|
190
|
+
uri = URI.parse("https://api.readme.com/v2/custom_pages/#{slug}")
|
202
191
|
request = Net::HTTP::Get.new(uri)
|
203
|
-
request["Authorization"] = "
|
192
|
+
request["Authorization"] = "Bearer #{readme_api_key}"
|
204
193
|
request["Content-Type"] = "application/json"
|
205
|
-
request["x-readme-version"] = version if version.present?
|
206
194
|
|
207
195
|
# Send the request
|
208
196
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-regulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Massanek
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|