rails-api-docs 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.
Potentially problematic release.
This version of rails-api-docs might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +142 -0
- data/LICENSE.txt +21 -0
- data/README.md +552 -0
- data/app/controllers/rails_api_docs/docs_controller.rb +20 -0
- data/config/routes.rb +5 -0
- data/lib/generators/rails-api-docs/init/init_generator.rb +167 -0
- data/lib/generators/rails-api-docs/update/update_generator.rb +28 -0
- data/lib/rails-api-docs/config/appender.rb +98 -0
- data/lib/rails-api-docs/config/builder.rb +175 -0
- data/lib/rails-api-docs/config/loader.rb +30 -0
- data/lib/rails-api-docs/configuration.rb +64 -0
- data/lib/rails-api-docs/engine.rb +27 -0
- data/lib/rails-api-docs/inspectors/body_inferrer.rb +88 -0
- data/lib/rails-api-docs/inspectors/controller_inspector.rb +78 -0
- data/lib/rails-api-docs/inspectors/json_route_detector.rb +189 -0
- data/lib/rails-api-docs/inspectors/route_inspector.rb +126 -0
- data/lib/rails-api-docs/inspectors/schema_inspector.rb +36 -0
- data/lib/rails-api-docs/sample_value.rb +28 -0
- data/lib/rails-api-docs/tasks/rails-api-docs.rake +25 -0
- data/lib/rails-api-docs/templates/api_docs.html.erb +695 -0
- data/lib/rails-api-docs/version.rb +5 -0
- data/lib/rails-api-docs.rb +21 -0
- metadata +155 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ac61ebf23cfaad87159b23315b863391492c5f5e54266ead2947798e4fa3d8e1
|
|
4
|
+
data.tar.gz: 042122d214d9da045aecdea97c55165d8182c5cf988601565c0d2d86c8b79128
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3ec043b12d508bcecffdd7f7122715c5988f04e60bfb2899ba5d8f825cbf88ff22d0cd1e06676d3ac2e3c40e13757970a5278fad058a5bcdad6bf89a74d8a846
|
|
7
|
+
data.tar.gz: 5bb4d2bf08b469c698886b68abfbe45f495285bf9d2fa4f278c006405d766090a6c63410e7cafa93beb01fa635d9fec6f7a8b0ab379b27764ee563d181e7a992
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - Unreleased
|
|
4
|
+
|
|
5
|
+
Initial release.
|
|
6
|
+
|
|
7
|
+
### Inspection & inference
|
|
8
|
+
|
|
9
|
+
- **`Inspectors::RouteInspector`**: walks `Rails.application.routes`,
|
|
10
|
+
normalizes paths (strips `(.:format)`), filters Rails internals
|
|
11
|
+
(`/rails/info`, `/rails/active_storage`, …), groups by controller,
|
|
12
|
+
supports multi-verb `match` and namespaced paths (`api/v1/users`).
|
|
13
|
+
- **`Inspectors::ControllerInspector`** (Prism AST): extracts permitted
|
|
14
|
+
attribute names from `params.permit(:a, :b, …)` calls anywhere in the
|
|
15
|
+
controller file. Handles flat permits, hash-rocket form, and nested
|
|
16
|
+
permits (top-level keys only).
|
|
17
|
+
- **`Inspectors::SchemaInspector`**: resolves controller → ActiveRecord
|
|
18
|
+
model and reads `columns_hash` for type and nullability metadata.
|
|
19
|
+
Best-effort — returns `{}` when the model can't be resolved.
|
|
20
|
+
- **`Inspectors::BodyInferrer`**: composes Controller + Schema to produce
|
|
21
|
+
typed `body:` field lists for `create`/`update` actions, with sensible
|
|
22
|
+
fallbacks (`string` type, `required: false`) when inspectors come up
|
|
23
|
+
empty.
|
|
24
|
+
- **`Inspectors::JsonRouteDetector`** (Prism AST): decides if an endpoint
|
|
25
|
+
is JSON-returning. Walks the controller's superclass chain looking for
|
|
26
|
+
`ActionController::API`; falls back to per-action `render json:`
|
|
27
|
+
detection inside `DefNode` bodies (kwarg and hash-rocket form, inside
|
|
28
|
+
`respond_to` blocks too). Cached per-controller.
|
|
29
|
+
|
|
30
|
+
### YAML generation & merge
|
|
31
|
+
|
|
32
|
+
- **`Config::Builder`**: assembles the full config — `general_configurations`
|
|
33
|
+
with Rails-themed defaults (`#CC0000` primary), `sections` grouped by
|
|
34
|
+
controller, endpoints with method/path/name/description/show, inferred
|
|
35
|
+
path params, body fields from the inferrer, and a response stub.
|
|
36
|
+
- **`Config::Appender` (append-only re-runs)**: re-running
|
|
37
|
+
`rails g rails-api-docs:update` only adds new routes; existing entries —
|
|
38
|
+
including user edits to descriptions, body fields, examples, headers,
|
|
39
|
+
responses — are never modified. Endpoint identity is `"#{method} #{path}"`.
|
|
40
|
+
- **`Config::Loader`**: parses existing YAML; `Loader.header` extracts
|
|
41
|
+
the leading `#`-comment block so it survives re-runs verbatim.
|
|
42
|
+
- **`RailsApiDocs::SampleValue`**: single source of truth for
|
|
43
|
+
type-derived placeholder values (`integer → 1`, `string → "example"`,
|
|
44
|
+
`date → "2026-01-01"`, …). Shared between inferrer, builder, curl
|
|
45
|
+
renderer, and HTML renderer.
|
|
46
|
+
|
|
47
|
+
### Generators
|
|
48
|
+
|
|
49
|
+
- **Two generator commands** (one implementation): `rails-api-docs:init`
|
|
50
|
+
for the first scaffold and `rails-api-docs:update` for re-runs.
|
|
51
|
+
`UpdateGenerator < InitGenerator` aliases the namespace; same code, same
|
|
52
|
+
flags, semantically distinct invocation.
|
|
53
|
+
- **`--api-only`**: filters scaffold to JSON-returning routes only,
|
|
54
|
+
via `JsonRouteDetector`. Persistent via
|
|
55
|
+
`RailsApiDocs.configuration.api_only = true`.
|
|
56
|
+
- **`--only-controllers`**: whitelist controllers by name. Accepts
|
|
57
|
+
space-, comma-, or bracket-separated forms
|
|
58
|
+
(`users posts`, `users,posts`, `[users,posts]`). Bare names match
|
|
59
|
+
across namespaces (`users` matches `users` and `api/v1/users`);
|
|
60
|
+
slash-qualified names are exact. Persistent via
|
|
61
|
+
`RailsApiDocs.configuration.only_controllers = […]`.
|
|
62
|
+
- **`--verbose-yaml`**: emits every possible YAML key per endpoint and
|
|
63
|
+
field with defaults (full discoverability at the cost of file size).
|
|
64
|
+
Persistent via `RailsApiDocs.configuration.verbose_yaml = true`.
|
|
65
|
+
Composes with all other flags.
|
|
66
|
+
- **Other filtering knobs**: `Configuration#ignored_path_prefixes`,
|
|
67
|
+
`#ignored_controllers` (strings or regexps; same boundary-aware
|
|
68
|
+
matching as `only_controllers`), `#ignored_actions`. Blacklist wins
|
|
69
|
+
over whitelist when both apply.
|
|
70
|
+
|
|
71
|
+
### YAML schema
|
|
72
|
+
|
|
73
|
+
- **Pragmatic default**: every inferred body field and path param ships
|
|
74
|
+
with `description: ""` and `example: <type-sample>` — users edit
|
|
75
|
+
values without remembering key names. A minimal `responses["200"]`
|
|
76
|
+
stub is included for every endpoint.
|
|
77
|
+
- **Verbose mode** additionally emits `format`, `enum`, `default`,
|
|
78
|
+
`min`/`max`, `min_length`/`max_length`, `pattern`, `read_only`,
|
|
79
|
+
`write_only`, `nullable` per field; and `deprecated`, `auth`, `tags`,
|
|
80
|
+
`headers`, `request_example`, plus a full `responses["200"]` with
|
|
81
|
+
`headers: []` and `schema: []`.
|
|
82
|
+
- **Response shape**: `responses["XXX"]` accepts `description`,
|
|
83
|
+
`example` (raw string), `headers` (array of field hashes), and
|
|
84
|
+
`schema` (typed response fields rendered as field rows).
|
|
85
|
+
|
|
86
|
+
### HTML renderer
|
|
87
|
+
|
|
88
|
+
- **Three-column self-contained output**: sidebar, central column with
|
|
89
|
+
field tables, right column with cURL and response examples. All CSS
|
|
90
|
+
and JS inlined — no external assets, no asset pipeline.
|
|
91
|
+
- **CSS variables driven by `general_configurations`**: changing
|
|
92
|
+
`primary_color` / `secondary_color` re-themes the whole page.
|
|
93
|
+
- **Unified `render_field` helper**: single source of truth for field
|
|
94
|
+
rendering. Used by body, params, request headers, response headers,
|
|
95
|
+
and response schema. Renders all field-level attributes as badges,
|
|
96
|
+
metas, descriptions, and inline `Example:` lines.
|
|
97
|
+
- **Endpoint-level badges**: `deprecated` (red badge + strikethrough
|
|
98
|
+
title), `auth` (dark monospace badge: "Bearer auth", "Basic auth",
|
|
99
|
+
custom), `tags` (clickable chips).
|
|
100
|
+
- **`Doc::CurlRenderer`**: multi-line cURL with proper shell escaping
|
|
101
|
+
(single quotes via the `'\''` block-form `gsub`). Supports
|
|
102
|
+
`request_example` overrides, per-param `example:` substitution in the
|
|
103
|
+
URL, and auto-injects user-declared `headers:` plus an `Authorization`
|
|
104
|
+
placeholder when `auth:` is set.
|
|
105
|
+
- **Multi-response support**: `responses:` keyed by status code with
|
|
106
|
+
per-status tabs in the right column (2xx green, 4xx amber, 5xx red);
|
|
107
|
+
the central column renders headers + schema per status when present.
|
|
108
|
+
- **Response title + copy buttons**: every cURL block and response
|
|
109
|
+
block has a `<button>` copy icon that copies the currently-active
|
|
110
|
+
`<pre>` content (curl command or active response tab). Uses
|
|
111
|
+
`navigator.clipboard.writeText` with `document.execCommand('copy')`
|
|
112
|
+
fallback for non-secure contexts. Visual flash + checkmark on success.
|
|
113
|
+
- **Tag click filtering**: clicking a tag pill filters the sidebar to
|
|
114
|
+
endpoints carrying that tag. Single-tag exclusive with toggle (same
|
|
115
|
+
tag = clear, different tag = switch). Combines with the text search
|
|
116
|
+
via AND. "Filtered by: <tag> ×" pill shown between search and section
|
|
117
|
+
list. Accessible: `<button>` elements, `aria-pressed`, `aria-live`.
|
|
118
|
+
- **Field example propagation**: `field["example"]` is the single
|
|
119
|
+
source of truth for sample values — it flows into the cURL `--data`
|
|
120
|
+
body and into the default response example block, with the
|
|
121
|
+
type-derived sample as fallback.
|
|
122
|
+
|
|
123
|
+
### Distribution
|
|
124
|
+
|
|
125
|
+
- **Dev mount at `/rails/api-docs`**: `Rails::Engine` mounts a
|
|
126
|
+
`DocsController` in `development` that re-renders the HTML from the
|
|
127
|
+
current YAML on every request — no build step while iterating.
|
|
128
|
+
Friendly setup page when YAML doesn't exist yet.
|
|
129
|
+
- **`rake rails-api-docs:build`**: reads the YAML and writes
|
|
130
|
+
`public/api-docs.html`. Supports `CONFIG=` and `OUTPUT=` env overrides.
|
|
131
|
+
- **Publish-ready gemspec metadata**: `homepage_uri`, `source_code_uri`
|
|
132
|
+
(pointing at `/tree/main` so RubyGems shows both), `changelog_uri`,
|
|
133
|
+
`bug_tracker_uri`, `documentation_uri`, and
|
|
134
|
+
`rubygems_mfa_required = "true"` (enforces MFA on every `gem push`).
|
|
135
|
+
|
|
136
|
+
### Tests
|
|
137
|
+
|
|
138
|
+
- 185 minitest cases covering inspectors, config build/append/load,
|
|
139
|
+
renderer, curl renderer, file builder, responder, init/update
|
|
140
|
+
generators, and JSON route detector. Uses
|
|
141
|
+
`ActionDispatch::Routing::RouteSet` directly — no dummy Rails app
|
|
142
|
+
required.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jackson Pires
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|