skyward-api 0.3.0 → 0.4.1
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/LICENSE +21 -0
- data/README.md +60 -56
- data/lib/skyward/api/assembly/boot.rb +239 -91
- data/lib/skyward/api/assembly/builder.rb +2 -2
- data/lib/skyward/api/assembly/dispatcher.rb +12 -12
- data/lib/skyward/api/assembly/static.rb +36 -36
- data/lib/skyward/api/cli/app_file.rb +2 -2
- data/lib/skyward/api/cli/check.rb +9 -9
- data/lib/skyward/api/cli/routes.rb +2 -2
- data/lib/skyward/api/cli/serve/reloader.rb +6 -6
- data/lib/skyward/api/cli/serve.rb +15 -15
- data/lib/skyward/api/cli/serve.ru +2 -2
- data/lib/skyward/api/commands.rb +10 -10
- data/lib/skyward/api/endpoints/declarations.rb +7 -3
- data/lib/skyward/api/endpoints/route.rb +3 -1
- data/lib/skyward/api/inputs/coercer.rb +53 -20
- data/lib/skyward/api/inputs.rb +9 -9
- data/lib/skyward/api/middleware/request_id.rb +3 -3
- data/lib/skyward/api/middleware/request_log.rb +5 -5
- data/lib/skyward/api/middleware/rescue.rb +7 -7
- data/lib/skyward/api/openapi/docs.rb +5 -5
- data/lib/skyward/api/openapi.rb +52 -50
- data/lib/skyward/api/request.rb +8 -8
- data/lib/skyward/api/routing/percent_encoding.rb +1 -1
- data/lib/skyward/api/routing/router.rb +68 -27
- data/lib/skyward/api/serializer/writers.rb +27 -16
- data/lib/skyward/api/serializer.rb +39 -21
- data/lib/skyward/api/test/client.rb +25 -25
- data/lib/skyward/api/version.rb +1 -1
- data/lib/skyward/api.rb +15 -14
- data/sig/generated/skyward/api/assembly/boot.rbs +99 -29
- data/sig/generated/skyward/api/endpoints/route.rbs +8 -4
- data/sig/generated/skyward/api/inputs/coercer.rbs +20 -2
- data/sig/generated/skyward/api/routing/router.rbs +52 -9
- data/sig/generated/skyward/api/serializer/writers.rbs +6 -0
- data/sig/generated/skyward/api/serializer.rbs +13 -1
- metadata +19 -4
- /data/sig/{manual/zeitwerk/loader.rbs → _private/zeitwerk.rbs} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae83d4087ae6b30e2f71d46ccbe2411aa9b0eda9fb9e808668729ccd26285dc6
|
|
4
|
+
data.tar.gz: b0931995b0908395f024d9aafcfe52c361c722cc37c92374c76ed697a9f9108c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c0a5328e129791a84710b9a4a9e2a47194199af046e6a11d61252720cc6152fb6b59487a9472cc75897d3a222255994bf3cc7c333c90128a5dab56a31b2a176b
|
|
7
|
+
data.tar.gz: 98185ca66483e2f962be0c23750e2b6141d510a732234104cde6bb778a7671d5a301b31d66a71dd2099eb7d79cc5ce6ca7949dc90a43cc82cd1bf2c92926d531
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jake Bottrall
|
|
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.
|
data/README.md
CHANGED
|
@@ -11,14 +11,14 @@ It's half of Skyward. The other half is [Skyward ORM](../skyward-orm/README.md),
|
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
13
13
|
# config.ru
|
|
14
|
-
require
|
|
14
|
+
require 'skyward/api'
|
|
15
15
|
|
|
16
16
|
class Hello < Skyward::API
|
|
17
|
-
get
|
|
17
|
+
get '/hello/:name', to: :greet
|
|
18
18
|
|
|
19
|
-
def greet(name:, shout:
|
|
19
|
+
def greet(name:, shout: 'false')
|
|
20
20
|
message = "Hello, #{name}"
|
|
21
|
-
{ message: shout ==
|
|
21
|
+
{ message: shout == 'true' ? message.upcase : message }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -59,7 +59,7 @@ The rest of this README is reference. If you only read one section, read [Types]
|
|
|
59
59
|
|
|
60
60
|
```ruby
|
|
61
61
|
# Gemfile
|
|
62
|
-
gem
|
|
62
|
+
gem 'skyward-api'
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
Skyward API supports every Ruby that isn't end-of-life (3.3 and later, as of November 2026), and runs on any Rack 3 server. It recommends [Falcon](https://github.com/socketry/falcon) or Puma. `skyward serve` runs Falcon, so add `gem "falcon"` to use it.
|
|
@@ -72,15 +72,15 @@ An endpoint is a public method. The class lists its routes at the top, and each
|
|
|
72
72
|
|
|
73
73
|
```ruby
|
|
74
74
|
class TodosAPI < Skyward::API
|
|
75
|
-
get
|
|
76
|
-
get
|
|
75
|
+
get '/', to: :index, summary: 'List todos, newest first.'
|
|
76
|
+
get '/:id', to: :show, summary: 'Fetch a single todo.'
|
|
77
77
|
|
|
78
78
|
def initialize(todos:)
|
|
79
79
|
super()
|
|
80
80
|
@todos = todos
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
def index(done: nil, limit:
|
|
83
|
+
def index(done: nil, limit: '50')
|
|
84
84
|
@todos.list(done:, limit: Integer(limit))
|
|
85
85
|
end
|
|
86
86
|
|
|
@@ -116,12 +116,12 @@ Ruby already has syntax for required and optional, so Skyward API uses it. A key
|
|
|
116
116
|
Without types, path and query values arrive as `String`s and `body:` arrives as a `Hash` with symbol keys. That makes it a good fit for pattern matching:
|
|
117
117
|
|
|
118
118
|
```ruby
|
|
119
|
-
post
|
|
119
|
+
post '/', to: :create
|
|
120
120
|
|
|
121
121
|
def create(body:)
|
|
122
122
|
case body
|
|
123
123
|
in { title: String => title } then created @todos.create(title:)
|
|
124
|
-
else unprocessable
|
|
124
|
+
else unprocessable 'title is required'
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
```
|
|
@@ -151,7 +151,7 @@ Return a value and Skyward API turns it into a response. There's no `render`, no
|
|
|
151
151
|
Every helper takes `headers:`:
|
|
152
152
|
|
|
153
153
|
```ruby
|
|
154
|
-
created todo, headers: {
|
|
154
|
+
created todo, headers: { 'location' => "/todos/#{todo.id}" }
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
Error responses use [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) `application/problem+json`:
|
|
@@ -172,12 +172,14 @@ Return a Rack triple for anything a value can't express: streaming, files, or a
|
|
|
172
172
|
# @rbs return: rack | Responses::NotFound
|
|
173
173
|
def export(id:)
|
|
174
174
|
todo = @todos.find(id)
|
|
175
|
-
todo ? [200, {
|
|
175
|
+
todo ? [200, { 'content-type' => 'text/csv' }, [todo.to_csv]] : not_found
|
|
176
176
|
end
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
Nothing checks what a triple sends, which is why it's opt-in through the return type. An `Array[T]` return is always JSON, even with three items.
|
|
180
180
|
|
|
181
|
+
Where the return type is `untyped`, as an untyped endpoint's is, or has an `untyped` member, as `Todo | untyped` does, nothing says a value is a triple. So it's sent as one only when it's an `Array` of exactly three items: an `Integer` from 100 to 599, a `Hash`, and a body that responds to `each` or `call`. Anything else is JSON, so `[200, {}, "hi"]` is a JSON array. An untyped endpoint can't return a three-item array that passes, such as `[200, {}, []]`, as JSON. Type its return as an `Array` for that.
|
|
182
|
+
|
|
181
183
|
---
|
|
182
184
|
|
|
183
185
|
## Types
|
|
@@ -212,16 +214,16 @@ NewTodo = Data.define(
|
|
|
212
214
|
)
|
|
213
215
|
|
|
214
216
|
class TodosAPI < Skyward::API
|
|
215
|
-
description
|
|
217
|
+
description 'Things to do, and the satisfaction of ticking them off.'
|
|
216
218
|
|
|
217
|
-
get
|
|
218
|
-
get
|
|
219
|
-
post
|
|
220
|
-
post
|
|
219
|
+
get '/', to: :index, summary: 'List todos, newest first.'
|
|
220
|
+
get '/:id', to: :show, summary: 'Fetch a single todo.'
|
|
221
|
+
post '/', to: :create, summary: 'Create a todo.'
|
|
222
|
+
post '/:id/complete', to: :complete, summary: 'Mark a todo as done.', description: <<~TEXT
|
|
221
223
|
Marking a todo that's already done is fine: it stays done, and the
|
|
222
224
|
response is the same.
|
|
223
225
|
TEXT
|
|
224
|
-
delete
|
|
226
|
+
delete '/:id', to: :destroy, summary: 'Delete a todo.'
|
|
225
227
|
|
|
226
228
|
# @rbs @todos: TodoStore
|
|
227
229
|
|
|
@@ -274,12 +276,13 @@ end
|
|
|
274
276
|
| `String` | string | `string` |
|
|
275
277
|
| `Integer` | `42`, or `"42"` in a path or query | `integer` |
|
|
276
278
|
| `Float` | number | `number` |
|
|
279
|
+
| `BigDecimal` | a decimal string, such as `"12.50"` | `string`, format `decimal` |
|
|
277
280
|
| `bool` | `true` / `false`, or `"true"`, `"false"`, `"1"`, `"0"` in a query | `boolean` |
|
|
278
281
|
| `Date`, `Time` | ISO 8601 strings | `string`, format `date` / `date-time` |
|
|
279
282
|
| `T?` | absent or `null` | not required / nullable |
|
|
280
283
|
| `:low \| :high` | `"low"` or `"high"`, given to you as a Symbol | `enum` |
|
|
281
284
|
| `Array[T]` | array; repeated keys in a query (`?tag=a&tag=b`) | `array` |
|
|
282
|
-
| `Hash[String, T]` | object
|
|
285
|
+
| `Hash[String, T]` | object; an `untyped` value keeps String keys at every level | `object` with `additionalProperties` |
|
|
283
286
|
| `{ id: Integer }` (record) | object | inline `object` |
|
|
284
287
|
| a class with typed readers | object | `object` component, referenced by `$ref` |
|
|
285
288
|
| `A \| B` (such classes) | either | `oneOf` |
|
|
@@ -334,16 +337,16 @@ Documentation is plain Ruby values, written where the thing it describes is decl
|
|
|
334
337
|
```ruby
|
|
335
338
|
App = Skyward.app(
|
|
336
339
|
docs: true,
|
|
337
|
-
title:
|
|
338
|
-
version:
|
|
339
|
-
description:
|
|
340
|
+
title: 'Best Todos Ever',
|
|
341
|
+
version: '1.0.0',
|
|
342
|
+
description: 'Lists of things to do, and the todos on them.'
|
|
340
343
|
) { ... }
|
|
341
344
|
|
|
342
345
|
class TodosAPI < Skyward::API
|
|
343
|
-
description
|
|
346
|
+
description 'Things to do, and the satisfaction of ticking them off.'
|
|
344
347
|
|
|
345
|
-
get
|
|
346
|
-
post
|
|
348
|
+
get '/', to: :index, summary: 'List todos, newest first.'
|
|
349
|
+
post '/:id/complete', to: :complete, summary: 'Mark a todo as done.', description: <<~TEXT
|
|
347
350
|
Marking a todo that's already done is fine: it stays done, and the
|
|
348
351
|
response is the same.
|
|
349
352
|
TEXT
|
|
@@ -382,7 +385,7 @@ A client generated from the document takes its names from it, so every name is o
|
|
|
382
385
|
To name a schema yourself, pass `schema_names:`. It needs no change to the class, so it works for Skyward ORM records and other gems' classes too:
|
|
383
386
|
|
|
384
387
|
```ruby
|
|
385
|
-
Skyward.app(docs: true, schema_names: { Statuses::Record =>
|
|
388
|
+
Skyward.app(docs: true, schema_names: { Statuses::Record => 'Status' }) { ... }
|
|
386
389
|
```
|
|
387
390
|
|
|
388
391
|
A schema name has only letters, digits, `.`, `-` and `_`, as OpenAPI requires, and no two schemas share one, including `Problem`. Skyward API refuses to boot otherwise.
|
|
@@ -397,8 +400,8 @@ By default the page loads Scalar from the jsDelivr CDN at a pinned version, with
|
|
|
397
400
|
|
|
398
401
|
```ruby
|
|
399
402
|
# public/scalar.js is dist/browser/standalone.js from the @scalar/api-reference package.
|
|
400
|
-
Skyward.app(docs: true, scalar_url:
|
|
401
|
-
app.static
|
|
403
|
+
Skyward.app(docs: true, scalar_url: '/scalar.js') do |app|
|
|
404
|
+
app.static '/', from: 'public'
|
|
402
405
|
# ...
|
|
403
406
|
end
|
|
404
407
|
```
|
|
@@ -413,22 +416,22 @@ A URL you pass gets no integrity hash, because Skyward API can't know it. A rela
|
|
|
413
416
|
|
|
414
417
|
```ruby
|
|
415
418
|
# app.rb
|
|
416
|
-
require
|
|
417
|
-
require_relative
|
|
419
|
+
require 'skyward/api'
|
|
420
|
+
require_relative 'todos_api'
|
|
418
421
|
|
|
419
422
|
App = Skyward.app(docs: true) do |app|
|
|
420
423
|
todos = TodoStore.new(database: DB)
|
|
421
424
|
|
|
422
425
|
app.use Rack::Deflater
|
|
423
|
-
app.static
|
|
426
|
+
app.static '/', from: 'public'
|
|
424
427
|
|
|
425
|
-
app.mount TodosAPI.new(todos:), at:
|
|
428
|
+
app.mount TodosAPI.new(todos:), at: '/todos'
|
|
426
429
|
end
|
|
427
430
|
```
|
|
428
431
|
|
|
429
432
|
```ruby
|
|
430
433
|
# config.ru
|
|
431
|
-
require_relative
|
|
434
|
+
require_relative 'app'
|
|
432
435
|
run App
|
|
433
436
|
```
|
|
434
437
|
|
|
@@ -442,8 +445,8 @@ Skyward API doesn't build CORS, compression or sessions, because Rack already ha
|
|
|
442
445
|
```ruby
|
|
443
446
|
app.use Rack::Cors do
|
|
444
447
|
allow do
|
|
445
|
-
origins
|
|
446
|
-
resource
|
|
448
|
+
origins 'https://todos.example'
|
|
449
|
+
resource '*', headers: :any, methods: %i[get post delete]
|
|
447
450
|
end
|
|
448
451
|
end
|
|
449
452
|
```
|
|
@@ -469,19 +472,19 @@ class CurrentUser
|
|
|
469
472
|
# @rbs request: Request
|
|
470
473
|
# @rbs return: User | Responses::Unauthorized
|
|
471
474
|
def call(request)
|
|
472
|
-
@sessions.user_for(request.cookies[
|
|
475
|
+
@sessions.user_for(request.cookies['session']) || Skyward.unauthorized('Sign in first')
|
|
473
476
|
end
|
|
474
477
|
|
|
475
478
|
end
|
|
476
479
|
|
|
477
480
|
App = Skyward.app do |app|
|
|
478
481
|
app.provide :current_user, CurrentUser.new(sessions: Sessions.new)
|
|
479
|
-
app.mount TodosAPI.new(todos:), at:
|
|
482
|
+
app.mount TodosAPI.new(todos:), at: '/todos'
|
|
480
483
|
end
|
|
481
484
|
```
|
|
482
485
|
|
|
483
486
|
```ruby
|
|
484
|
-
get
|
|
487
|
+
get '/', to: :index
|
|
485
488
|
|
|
486
489
|
# @rbs current_user: User
|
|
487
490
|
# @rbs return: Array[Todo]
|
|
@@ -503,16 +506,17 @@ Skyward API checks your app at boot, so mistakes show up when you start it, not
|
|
|
503
506
|
|
|
504
507
|
```
|
|
505
508
|
Skyward::Core::BootError: TodosAPI#show (GET /todos/:id)
|
|
506
|
-
The route has a path parameter :id, but the method has no `id:` keyword.
|
|
509
|
+
The route has a path parameter :id, but the method has no `id:` keyword. Add `id:` to the method, or rename the path parameter.
|
|
507
510
|
|
|
508
|
-
|
|
511
|
+
app/todos_api.rb:12
|
|
512
|
+
get '/:id', to: :show
|
|
509
513
|
...
|
|
510
514
|
def show(todo_id:)
|
|
511
515
|
^^^^^^^^
|
|
512
516
|
Did you mean `def show(id:)`?
|
|
513
517
|
```
|
|
514
518
|
|
|
515
|
-
Boot also catches a route that names a method the class doesn't have, a route that shadows another, an unknown type in a signature, and a
|
|
519
|
+
Boot also catches a route that names a method the class doesn't have, a route that shadows another, an unknown type in a signature, and a signature whose keywords differ from the method's. With `strict: true`, it also catches every untyped endpoint: one that has no signature at all, or whose signature types a keyword or the return as `untyped`.
|
|
516
520
|
|
|
517
521
|
When your code raises at runtime, Skyward API responds with a 500 problem+json that carries the request ID and logs the exception. In development, the response also includes the backtrace.
|
|
518
522
|
|
|
@@ -528,10 +532,10 @@ When your code raises at runtime, Skyward API responds with a 500 problem+json t
|
|
|
528
532
|
To send exceptions to Sentry or a similar service, pass `on_error:`. It's called once per exception, after it's logged, with the exception and the Rack env, and takes anything that responds to `call(exception, env)`:
|
|
529
533
|
|
|
530
534
|
```ruby
|
|
531
|
-
report = ->(exception, env) { Sentry.capture_exception(exception, tags: { request_id: env[
|
|
535
|
+
report = ->(exception, env) { Sentry.capture_exception(exception, tags: { request_id: env['skyward.request_id'] }) }
|
|
532
536
|
|
|
533
537
|
App = Skyward.app(on_error: report) do |app|
|
|
534
|
-
app.mount TodosAPI.new(todos:), at:
|
|
538
|
+
app.mount TodosAPI.new(todos:), at: '/todos'
|
|
535
539
|
end
|
|
536
540
|
```
|
|
537
541
|
|
|
@@ -560,14 +564,14 @@ There's no server or Rack in that test. The fake goes in through `initialize`.
|
|
|
560
564
|
When you want the whole stack, including routing, coercion, providers and middleware, use the test client:
|
|
561
565
|
|
|
562
566
|
```ruby
|
|
563
|
-
describe
|
|
567
|
+
describe 'POST /todos' do
|
|
564
568
|
let(:client) { Skyward::API::Test.client(App) }
|
|
565
569
|
|
|
566
570
|
it "rejects a priority that doesn't exist" do
|
|
567
|
-
response = client.post
|
|
571
|
+
response = client.post '/todos', json: { title: 'Ship it', priority: 'urgent' }
|
|
568
572
|
|
|
569
573
|
assert_equal 422, response.status
|
|
570
|
-
assert_equal
|
|
574
|
+
assert_equal 'body.priority', response.json[:errors].first[:at]
|
|
571
575
|
end
|
|
572
576
|
end
|
|
573
577
|
```
|
|
@@ -617,7 +621,7 @@ DELETE /todos/:id TodosAPI#destroy (id: Integer) -> (Responses::NoC
|
|
|
617
621
|
The executable comes with Skyward Core, which every Skyward gem depends on. It finds each gem's `lib/skyward/<gem>/commands.rb` with `Gem.find_files` and loads it, and that file registers the gem's commands:
|
|
618
622
|
|
|
619
623
|
```ruby
|
|
620
|
-
Skyward::Core::CLI.register(
|
|
624
|
+
Skyward::Core::CLI.register('routes', 'List every route and the method that serves it') do |args|
|
|
621
625
|
# ...
|
|
622
626
|
end
|
|
623
627
|
```
|
|
@@ -626,7 +630,7 @@ Skyward API's commands run in your app's directory. `skyward serve` runs `config
|
|
|
626
630
|
|
|
627
631
|
### `skyward check` in CI
|
|
628
632
|
|
|
629
|
-
Run `skyward check` as a required CI step in every Skyward app. Skyward API reads signatures at boot, and `rbs` stays one of its runtime dependencies
|
|
633
|
+
Run `skyward check` as a required CI step in every Skyward app. Skyward API reads the signatures you deployed at every boot, and `rbs` stays one of its runtime dependencies in 1.0, as [Skyward Core](../skyward-core/README.md#what-it-owns) explains, so a deploy with stale signatures quietly validates requests against the old contract. `check` is what catches it. It checks three things, in order, and checks all three even after one fails, then exits 1 if any failed:
|
|
630
634
|
|
|
631
635
|
1. **Signatures.** It runs rbs-inline over the app's Ruby, outside `test/`, `spec/`, `vendor/`, `tmp/` and hidden directories, and fails if the result differs from `sig/generated`, listing the files that differ and the command that regenerates them.
|
|
632
636
|
2. **Strict boot.** It loads `app.rb` with `SKYWARD_STRICT=1`, so an untyped endpoint, or any other boot error, fails it.
|
|
@@ -637,8 +641,8 @@ It needs rbs-inline and Steep in the app's bundle, and a `Steepfile`:
|
|
|
637
641
|
```ruby
|
|
638
642
|
# Gemfile
|
|
639
643
|
group :development, :test do
|
|
640
|
-
gem
|
|
641
|
-
gem
|
|
644
|
+
gem 'rbs-inline', require: false
|
|
645
|
+
gem 'steep', require: false
|
|
642
646
|
end
|
|
643
647
|
```
|
|
644
648
|
|
|
@@ -679,16 +683,16 @@ No type error detected.
|
|
|
679
683
|
This README is the spec, and this section lists each part of it that's built, as it lands. Anything it describes that isn't listed here isn't built yet.
|
|
680
684
|
|
|
681
685
|
- **Route declarations.** An API class subclasses `Skyward::API` and lists its routes with `get`, `post`, `put`, `patch` and `delete`, each with an optional `summary:` and `description:`, and describes itself with `description`. A subclass starts with its parent's routes. A path that doesn't start with `/`, a path parameter that isn't a valid keyword name or appears twice, or a `to:` that isn't a Symbol raises `ArgumentError` where it's declared. The rest is checked at boot, below.
|
|
682
|
-
- **Building an app.** `Skyward.app` yields a builder and returns a frozen Rack app, and the builder is frozen once the block returns. `mount` attaches an API object at a prefix (`at:`, `/` by default), and raises `Skyward::Core::BootError` given anything but a `Skyward::API` instance. One object can be mounted at several prefixes. A request matches a route when its method and whole path match, trailing slash included, with each path parameter matching one non-empty segment, percent-decoded. Routes are
|
|
683
|
-
- **Checks at boot.** `Skyward.app` loads the RBS signatures under `signatures:` (`"sig"` by default, relative to the current directory) along with Skyward API's own, so an app's signatures can subclass `Skyward::API`. It refuses to boot with a `Skyward::Core::BootError` on the first problem it finds, and the message starts with the route's label, such as `TodosAPI#show (GET /todos/:id)`, then says what's wrong and how to fix it. It refuses a `summary:` with a line break; a route that an earlier one with the same verb, in any mount, matches every path of, as `/todos/:id` does `/todos/new`; a method that isn't public, or that takes positional arguments or `**rest`; a signature whose keywords differ from the method's, in name or in being required, which means it's stale; a path parameter with no keyword of its name; a path parameter whose name is provided; a `request:` keyword typed as anything but `Skyward::API::Request`; a provided keyword whose type isn't its provider's value, as Providers below describes; a type that can't be read; and a path or query keyword typed as a record, a hash, a class, or an array in a path or inside an array. Each endpoint keeps its method type as its signature file writes it, or for an untyped endpoint, below, as rbs-inline would, and its keywords, with each one's name, its source (the path for a path parameter, the body for `body:`, the request for `request:`, and otherwise the query string), whether it's required and its type, keeps the provider of each provided keyword apart from them, in keyword order, and keeps the members of its return type, reading `Skyward::API::Responses::Created[T]` with the type of its value, the other response values by their class, and `Skyward::API::rack`, or the tuple it names, as a Rack triple, and refusing a `Skyward::API::Responses::Created` without one. A class or method with no signature, including when there's no `signatures:` directory at all, is an untyped endpoint: each keyword is `untyped`, required as the method requires it, and so is its return type, which is what rbs-inline writes for a method with no annotations. `request:` may be typed `untyped` too, and is still the request. With `Skyward.app(strict: true)`, or with `SKYWARD_STRICT=1` in the environment whatever `strict:` says, once the other checks pass, boot refuses every untyped endpoint, not just the first, each starting with its label: one with no signature, or one whose signature types a keyword or a member of its return type as `untyped`, naming which. `untyped` inside a type, as in `Array[untyped]`, isn't refused, and nor is `request:`.
|
|
684
|
-
- **Inputs.** Each endpoint's keywords are compiled into coercers at boot, and filled on each request before the method runs: a path parameter from the path, `body:` from the JSON body, `request:` with the request, below, a provided keyword from its provider, below, and any other keyword from the query string, each but `request:` and a provided keyword coerced to its type. In a path or query, `Integer` matches `-?\d+`, `Float` is parsed with `Float()` and must be finite, and `bool` takes `true`, `false`, `1` and `0`. In a body, a number or boolean must already be one, and an Integer is accepted as a Float. `Date` is `YYYY-MM-DD` and must exist, and `Time` is ISO 8601 with `T`, seconds, an optional fraction and `Z` or `±HH:MM`. A symbol union takes a symbol's name and gives the Symbol, and a union takes its first member that fits, in declared order. `Array[T]` in a query comes from repeated keys, one value is a one-item array, and `tag[]` is a different key; an `untyped` keyword takes the last value of a key given more than once, and any other keyword given more than once doesn't fit. A record becomes a Hash with Symbol keys, and a class with typed readers is built with `new(**fields)`, both ignoring undeclared keys. `Hash[String, T]` takes a JSON object, empty or not, and coerces each value by `T`, keeping its key a String. An `untyped` path or query value is its String,
|
|
686
|
+
- **Building an app.** `Skyward.app` yields a builder and returns a frozen Rack app, and the builder is frozen once the block returns. `mount` attaches an API object at a prefix (`at:`, `/` by default), and raises `Skyward::Core::BootError` given anything but a `Skyward::API` instance. One object can be mounted at several prefixes. A request matches a route when its method and whole path match, trailing slash included, with each path parameter matching one non-empty segment, percent-decoded. Routes are compiled into one matcher at boot, and when several routes match a request, the first in mount order, then declaration order, answers. The method is called with its inputs, below, and its return value is answered by its return type, as Responses below describes. A request whose path no route matches gets a 404 problem+json.
|
|
687
|
+
- **Checks at boot.** `Skyward.app` loads the RBS signatures under `signatures:` (`"sig"` by default, relative to the current directory) along with Skyward API's own, so an app's signatures can subclass `Skyward::API`. It refuses to boot with a `Skyward::Core::BootError` on the first problem it finds, and the message starts with the route's label, such as `TodosAPI#show (GET /todos/:id)`, then says what's wrong and how to fix it. It refuses a `summary:` with a line break; a route that an earlier one with the same verb, in any mount, matches every path of, as `/todos/:id` does `/todos/new`; a method that isn't public, or that takes positional arguments or `**rest`; a signature whose keywords differ from the method's, in name or in being required, which means it's stale; a path parameter with no keyword of its name; a path parameter whose name is provided; a `request:` keyword typed as anything but `Skyward::API::Request`; a provided keyword whose type isn't its provider's value, as Providers below describes; a type that can't be read; and a path or query keyword typed as a record, a hash, a class, or an array in a path or inside an array. Each endpoint keeps its method type as its signature file writes it, or for an untyped endpoint, below, as rbs-inline would, and its keywords, with each one's name, its source (the path for a path parameter, the body for `body:`, the request for `request:`, and otherwise the query string), whether it's required and its type, keeps the provider of each provided keyword apart from them, in keyword order, and keeps the members of its return type, reading `Skyward::API::Responses::Created[T]` with the type of its value, the other response values by their class, and `Skyward::API::rack`, or the tuple it names, as a Rack triple, and refusing a `Skyward::API::Responses::Created` without one. A class or method with no signature, including when there's no `signatures:` directory at all, is an untyped endpoint: each keyword is `untyped`, required as the method requires it, and so is its return type, which is what rbs-inline writes for a method with no annotations. `request:` may be typed `untyped` too, and is still the request. With `Skyward.app(strict: true)`, or with `SKYWARD_STRICT=1` in the environment whatever `strict:` says, once the other checks pass, boot refuses every untyped endpoint, not just the first, each starting with its label: one with no signature, or one whose signature types a keyword or a member of its return type as `untyped`, naming which. `untyped` inside a type, as in `Array[untyped]`, isn't refused, and nor is `request:`. Every line of the problem is indented two spaces, and below it a refusal shows an excerpt of the code at fault, indented four, as Skyward Core renders it, and then a hint, indented two. `get`, `post`, `put`, `patch` and `delete` record the file and line they're called from, and the route's line has carets under `summary:`'s value for a line break, under the path of both routes for a shadowed one, and under `to:`'s value for a method that isn't public. The `def` has carets under its parameters for positional arguments or `**rest`, under the keyword for a `request:`, provided, path or query keyword's type or a type that can't be read, and under its name for a return type that can't be read. A path parameter that's provided shows the route with carets under the parameter, then the `def` with carets under the keyword. A path parameter with no keyword shows the route, then the `def`, and the hint ``Did you mean `def show(id:)`?``, the `def` line's parameters with the keyword it means renamed: of the keywords the query string would carry, the closest by Ruby's `DidYouMean`, or else the only one that ends in `_<parameter>` or that the parameter ends in `_<keyword>`, as `todo_id:` for `/:id`. The carets go under that keyword, or under the parameters when none is meant, and there's a hint only when the parameter list is written whole on the `def` line. A method that isn't public gets ``index is private. Move it above `private`.`` when the class has a private or protected method of that name, or else `Did you mean to: :index?` naming the closest of the class's own public methods, and a type that can't be read gets Skyward Core's `Did you mean` for a misspelt class name. An RBS error reading the signature shows Skyward Core's excerpt of the RBS and its suggestion. A stale signature, and `strict: true`'s refusals, have no excerpt, and a route or method in a file that can't be read, as from `eval`, gets no excerpt, and no `def` hint.
|
|
688
|
+
- **Inputs.** Each endpoint's keywords are compiled into coercers at boot, and filled on each request before the method runs: a path parameter from the path, `body:` from the JSON body, `request:` with the request, below, a provided keyword from its provider, below, and any other keyword from the query string, each but `request:` and a provided keyword coerced to its type. In a path or query, `Integer` matches `-?\d+`, `Float` is parsed with `Float()` and must be finite, and `bool` takes `true`, `false`, `1` and `0`. In a body, a number or boolean must already be one, and an Integer is accepted as a Float. `Date` is `YYYY-MM-DD` and must exist, and `Time` is ISO 8601 with `T`, seconds, an optional fraction and `Z` or `±HH:MM`. `BigDecimal` takes a String of an optional `-`, digits, and an optional `.` and digits (`"12.50"`, `"-3"`, `"0.001"`), the same in a path, a query and a body, and gives `BigDecimal(raw)`. Anything else doesn't fit, an exponent, `NaN` and an empty string included, and so doesn't a JSON number, which is parsed as a `Float` and may have lost digits: `expected BigDecimal (a decimal string, such as "12.50"), got 12.5`. A symbol union takes a symbol's name and gives the Symbol, and a union takes its first member that fits, in declared order. `Array[T]` in a query comes from repeated keys, one value is a one-item array, and `tag[]` is a different key; an `untyped` keyword takes the last value of a key given more than once, and any other keyword given more than once doesn't fit. A record becomes a Hash with Symbol keys, and a class with typed readers is built with `new(**fields)`, both ignoring undeclared keys. `Hash[String, T]` takes a JSON object, empty or not, and coerces each value by `T`, keeping its key a String. An `untyped` path or query value is its String. Each value of a `Hash[String, untyped]` or `Hash[String, untyped?]` is the JSON as it's parsed, with String keys at every level. Any other `untyped` part of a body, such as an untyped endpoint's `body:`, an `untyped` field or an item of `Array[untyped]`, is the JSON as it's parsed, with Symbol keys at every level. An empty query value is a value, so `?limit=` doesn't fit `Integer`. A missing required keyword or field is `nil` when it's nullable, and otherwise `is required`. An absent optional keyword isn't passed, so Ruby's default applies, and an absent optional record field is left out. A request that doesn't fit answers a 422 problem+json titled `Unprocessable Content`, whose `errors` list every problem, up to the first 1,000, after which coercion stops, each with where it is (`path.id`, `query.limit`, `body.priority`, `body.tags[1]`, `body.scores["alice"]`, with a hash's key JSON-quoted so a dot or bracket in it is unambiguous, and a key longer than 200 characters cut to 200, ending `…`) and a message, such as `expected :low | :normal | :high, got "urgent"`, whose expected type, when longer than 200 characters, is cut to 200, ending `…`. A query string with unescaped bytes outside ASCII is a 422 at `query`, and a body that isn't JSON, or isn't UTF-8, is a 422 at `body`. The body is read only for an endpoint with `body:`, as [Production](#production) describes, and a missing or empty one is absent.
|
|
685
689
|
- **The request.** An endpoint that takes `request:` is passed a frozen `Skyward::API::Request`, built from the Rack env once on each request, only for an endpoint that takes it or a provided keyword, and passed even when the keyword has a default. It wraps the env rather than subclassing `Rack::Request`, because Skyward API doesn't depend on Rack. `headers` is a frozen Hash of every `HTTP_` variable in the env, named in lowercase with dashes (`request.headers["authorization"]`), along with `content-type` and `content-length`. `cookies` is a frozen Hash read from the `cookie` header, each value percent-decoded with a `+` left as it is, and the first of two cookies with one name wins. `ip` is the client's address as Rack finds it: the remote address, unless it's a trusted proxy (a loopback or private address, `localhost` or a Unix socket), and otherwise the last `X-Forwarded-For` address that isn't one, or the first when every one is, or the remote address when there's no `X-Forwarded-For`, or `nil` with neither. The `Forwarded` header isn't read. `request_id` is the request's ID, and `env` is the env itself.
|
|
686
690
|
- **Providers.** The builder's `provide(name, provider)` registers anything that responds to `call(request)`, such as an object, a lambda or a `Method`, under a Symbol name, and raises `Skyward::Core::BootError` for a name that's already provided, or for `body` or `request`, which Skyward API fills itself. A keyword with a provided name is filled by its provider, never from the query string, and passed even when it has a default. On each request, once a route matches, each provider the endpoint asks for runs once, in keyword order, with the request, the same `Skyward::API::Request` that `request:` gets, before the body is read or any input is coerced, so a caller a provider turns away gets its response rather than a 422 that shows the inputs' shape. When a provider returns a response value (`Skyward::API::Responses::NoContent`, `Skyward::API::Responses::BadRequest`, `Skyward::API::Responses::Unauthorized`, `Skyward::API::Responses::Forbidden`, `Skyward::API::Responses::NotFound`, `Skyward::API::Responses::Conflict`, `Skyward::API::Responses::Unprocessable` or `Skyward::API::Responses::Redirect`), no later provider runs, the method never runs, and the value is answered as Responses below describes, written by the provider's return type, or by its own status for a provider with no signature; anything else it returns, `nil` and a `Skyward::API::Responses::Created` included, is the keyword's value. At boot, Skyward API reads the provider's signature: the `call` of its class, which may be inherited, or a `Method`'s own name, in either case read from the module that defines it. A provider whose `call` is defined on a single object, such as a module with `extend self` or a class with `def self.call`, has no signature Skyward API can read, so boot refuses it: provide an instance of a class. The response values in its return type are added to the document's responses of every endpoint that asks for its name, and the rest of the return type's members must be exactly the keyword's type's members, compared as RBS types in any order, with a `T?` as `T` and `nil`, so several members are compared as their union, and a return type of only response values matches no keyword; boot refuses a keyword that doesn't match. A provider with no signature, or whose `call` returns `untyped`, as a lambda's does, adds no responses and its value isn't checked. A provider that raises is answered with a 500, as Errors below describes, and so is a typed provider's response value that its return type doesn't list, which raises `Skyward::API::ReturnTypeError` naming the provider. A keyword typed `untyped`, nullable or not, as each of an untyped endpoint's keywords is, takes any provider's value unchecked, since untyped code isn't checked anywhere else, and is still filled by its provider, never from the query string, with the provider's responses still added to the endpoint's. With `strict: true`, a signature that types a provided keyword as `untyped`, nullable or not, is refused like one that types any other keyword so, but a provider with no signature, or whose `call` returns `untyped`, doesn't make the endpoints that ask for it untyped, since `strict:` refuses untyped endpoints, not providers.
|
|
687
|
-
- **Responses.** An API's instances have private helpers that return frozen response values, each taking `headers:`: `created(value)` returns a `Skyward::API::Responses::Created[T]`, `no_content` a `Skyward::API::Responses::NoContent`, `bad_request(detail)` a `Skyward::API::Responses::BadRequest`, `unauthorized(detail)` a `Skyward::API::Responses::Unauthorized`, `forbidden(detail)` a `Skyward::API::Responses::Forbidden`, `not_found(detail = nil)` a `Skyward::API::Responses::NotFound`, `conflict(detail)` a `Skyward::API::Responses::Conflict`, `unprocessable(detail)` a `Skyward::API::Responses::Unprocessable` and `redirect(to, status: 303)` a `Skyward::API::Responses::Redirect`. `bad_request`, `unauthorized`, `forbidden` and `redirect` are also public module functions on `Skyward`, such as `Skyward.unauthorized("Sign in first")`, for code outside an API class. `redirect` raises `ArgumentError` for a `status:` other than 301, 302, 303, 307 or 308, or a `to` with a line break. At boot, each endpoint compiles a serializer for every member of its return type, and a returned value goes to the first member it fits: by class for a class with typed readers and for a response value, and by shape otherwise. A class with typed readers is written by calling each reader it declares, never `to_h`, and a record is read from a Hash by its declared keys, leaving out an optional key that's absent, so nothing undeclared is ever written. Integers, Floats, Strings and booleans are written as JSON, an enum's Symbol as its name, a `Date` as `YYYY-MM-DD`, a `Time` in UTC as ISO 8601 with six fractional digits (`2026-10-18T09:30:00.123456Z`), and `nil` only where the type is nullable. JSON has no `Infinity` or `NaN`, so `Float` fits only a finite Float. A `Hash[String, T]` writes each value as `T`, so a value's undeclared fields are dropped too, and String or Symbol keys as strings; a Hash with any other key doesn't fit it. A plain value answers 200 with `content-type: application/json`; `Skyward::API::Responses::Created[T]` answers 201 with its value written as `T`; `Skyward::API::Responses::NoContent` answers 204 with no body; `Skyward::API::Responses::BadRequest`, `Skyward::API::Responses::Unauthorized`, `Skyward::API::Responses::Forbidden`, `Skyward::API::Responses::NotFound`, `Skyward::API::Responses::Conflict` and `Skyward::API::Responses::Unprocessable` answer 400, 401, 403, 404, 409 and 422 with RFC 9457 `application/problem+json`, whose `detail` appears only when given; and `Skyward::API::Responses::Redirect` answers its status with a `location` header and no body. A response value's `headers:` are added to its response, and Skyward adds no `WWW-Authenticate` to a 401, so pass it in `headers:`. A part typed `untyped` is written as untyped code's is: scalars as themselves, Symbols as their names, dates and
|
|
688
|
-
- **OpenAPI document.** With `Skyward.app(docs: true)`, the app builds its OpenAPI 3.1 document once, at boot, and answers GET and HEAD at `/openapi.json` with it as `application/json`, before any route or static file. The same app always writes the same bytes. Its `info` has `Skyward.app`'s `title:` (`"API"` by default), `version:` (`"0.1.0"` by default) and, when given, `description:`. Each API class is a tag, in mount order, with its `description`, and each route is an operation under its path, with each path parameter as `{name}`, tagged with its class, with its `summary:` and `description:` when given and the operation ID `<Tag>_<method>`; a tag is the class's constant path with `::` as `.`. A path keyword is a required parameter, and a query keyword is a parameter, required when the method requires it and it isn't nullable, whose schema leaves out `null`. `body:` is an `application/json` request body, required on the same terms. Each member of the return type is a response: a plain type a 200 `application/json`, `Skyward::API::Responses::Created[T]` a 201 of `T`, `Skyward::API::Responses::NoContent` a 204, each problem its status with the `Problem` schema as `application/problem+json`, `Skyward::API::Responses::Redirect` a `3XX` with a `location` header, and `Skyward::API::rack` a `default` with no schema. The response values of each provider the endpoint asks for are its responses too. Members with the same status are one response, `oneOf` their schemas. `request:` and a provided keyword aren't part of the HTTP contract, so neither is a parameter, schema or component, or counts as an input. An endpoint with other keywords also lists 422, and one with `body:` 413 and 415, and the responses are ordered by status. `Integer`, `Float`, `String` and `bool` are `integer`, `number`, `string` and `boolean`, `Date` and `
|
|
691
|
+
- **Responses.** An API's instances have private helpers that return frozen response values, each taking `headers:`: `created(value)` returns a `Skyward::API::Responses::Created[T]`, `no_content` a `Skyward::API::Responses::NoContent`, `bad_request(detail)` a `Skyward::API::Responses::BadRequest`, `unauthorized(detail)` a `Skyward::API::Responses::Unauthorized`, `forbidden(detail)` a `Skyward::API::Responses::Forbidden`, `not_found(detail = nil)` a `Skyward::API::Responses::NotFound`, `conflict(detail)` a `Skyward::API::Responses::Conflict`, `unprocessable(detail)` a `Skyward::API::Responses::Unprocessable` and `redirect(to, status: 303)` a `Skyward::API::Responses::Redirect`. `bad_request`, `unauthorized`, `forbidden` and `redirect` are also public module functions on `Skyward`, such as `Skyward.unauthorized("Sign in first")`, for code outside an API class. `redirect` raises `ArgumentError` for a `status:` other than 301, 302, 303, 307 or 308, or a `to` with a line break. At boot, each endpoint compiles a serializer for every member of its return type, and a returned value goes to the first member it fits: by class for a class with typed readers and for a response value, and by shape otherwise. A class with typed readers is written by calling each reader it declares, never `to_h`, and a record is read from a Hash by its declared keys, leaving out an optional key that's absent, so nothing undeclared is ever written. Integers, Floats, Strings and booleans are written as JSON, an enum's Symbol as its name, a `Date` as `YYYY-MM-DD`, a `Time` in UTC as ISO 8601 with six fractional digits (`2026-10-18T09:30:00.123456Z`), a `BigDecimal` as a String of its digits with `to_s("F")`, which never uses an exponent and keeps no scale (`"12.5"` for `BigDecimal("12.50")`, `"100.0"`, `"-0.001"`), and `nil` only where the type is nullable. JSON has no `Infinity` or `NaN`, so `Float` fits only a finite Float, and `BigDecimal` only a finite BigDecimal. A `Hash[String, T]` writes each value as `T`, so a value's undeclared fields are dropped too, and String or Symbol keys as strings; a Hash with any other key doesn't fit it. A plain value answers 200 with `content-type: application/json`; `Skyward::API::Responses::Created[T]` answers 201 with its value written as `T`; `Skyward::API::Responses::NoContent` answers 204 with no body; `Skyward::API::Responses::BadRequest`, `Skyward::API::Responses::Unauthorized`, `Skyward::API::Responses::Forbidden`, `Skyward::API::Responses::NotFound`, `Skyward::API::Responses::Conflict` and `Skyward::API::Responses::Unprocessable` answer 400, 401, 403, 404, 409 and 422 with RFC 9457 `application/problem+json`, whose `detail` appears only when given; and `Skyward::API::Responses::Redirect` answers its status with a `location` header and no body. A response value's `headers:` are added to its response, and Skyward adds no `WWW-Authenticate` to a 401, so pass it in `headers:`. A part typed `untyped` is written as untyped code's is: scalars as themselves, Symbols as their names, dates, times and BigDecimals as above, Hashes and Arrays item by item, and anything else through `to_h`; a return type of `untyped` also answers each response value with its own status. A value, or any part of it, that doesn't fit its type raises `Skyward::API::ReturnTypeError` before anything is written, naming the endpoint's label, what came back (a scalar's value, or else only its class) and where, and the type it should have been, so it's answered with a 500 as Errors below describes. Skyward API's signatures declare `Skyward::API::rack` as `[Integer, Hash[String, String], untyped]`, and a member typed with it, or with that tuple written out, takes an Array of an Integer, a Hash and a body, and sends it as given, without checking or rewriting any of it, so a body that streams through `each` or `call` works. An `Array[T]` member is always JSON, even for three items. The request ID is still added to a triple, and `HEAD` drops its body, closing it when it responds to `close`. An untyped endpoint's return type is `untyped`, so it's answered the same way. Where a return type, or a member of one, is `untyped`, an `Array` of exactly three items, an `Integer` from 100 to 599, a `Hash`, and a body that responds to `each` or `call`, is sent as given, as a typed triple is, and anything else as above, so `[200, {}, "hi"]` is a JSON array. `untyped` inside a type, as in `Array[untyped]`, never sends a triple.
|
|
692
|
+
- **OpenAPI document.** With `Skyward.app(docs: true)`, the app builds its OpenAPI 3.1 document once, at boot, and answers GET and HEAD at `/openapi.json` with it as `application/json`, before any route or static file. The same app always writes the same bytes. Its `info` has `Skyward.app`'s `title:` (`"API"` by default), `version:` (`"0.1.0"` by default) and, when given, `description:`. Each API class is a tag, in mount order, with its `description`, and each route is an operation under its path, with each path parameter as `{name}`, tagged with its class, with its `summary:` and `description:` when given and the operation ID `<Tag>_<method>`; a tag is the class's constant path with `::` as `.`. A path keyword is a required parameter, and a query keyword is a parameter, required when the method requires it and it isn't nullable, whose schema leaves out `null`. `body:` is an `application/json` request body, required on the same terms. Each member of the return type is a response: a plain type a 200 `application/json`, `Skyward::API::Responses::Created[T]` a 201 of `T`, `Skyward::API::Responses::NoContent` a 204, each problem its status with the `Problem` schema as `application/problem+json`, `Skyward::API::Responses::Redirect` a `3XX` with a `location` header, and `Skyward::API::rack` a `default` with no schema. The response values of each provider the endpoint asks for are its responses too. Members with the same status are one response, `oneOf` their schemas. `request:` and a provided keyword aren't part of the HTTP contract, so neither is a parameter, schema or component, or counts as an input. An endpoint with other keywords also lists 422, and one with `body:` 413 and 415, and the responses are ordered by status. `Integer`, `Float`, `String` and `bool` are `integer`, `number`, `string` and `boolean`, `Date`, `Time` and `BigDecimal` are strings of format `date`, `date-time` and `decimal`, `untyped` is any value, a literal is a `const`, an enum is a string `enum`, `Array[T]` is an `array` of `T`, `Hash[String, T]` is an `object` whose `additionalProperties` is `T`'s schema, so `{}` for `untyped`, a record is an inline `object` with `required` naming its required keys, a union is `oneOf` its members, and a nullable type adds `null` to its `type`, except that a nullable enum, literal, union, class or `untyped` is `anyOf` it and `null`. A class with typed readers is a `$ref` to an `object` component named by its constant path with `::` as `.`, or by `Skyward.app(schema_names:)`. A nullable field is required in a response but not in a request, and a class reached from any keyword gets the request form. The components are ordered by name, and always include `Problem`, with `type`, `title` and `status` required and an optional `detail` and `errors`. With `docs: true`, boot refuses a route whose path is `/openapi.json`, a static file there, two operations with the same ID (which two routes to one method, or a class mounted twice, have), a schema name with anything but letters, digits, `.`, `-` and `_`, and two types with the same schema name, including `Problem`. An `untyped` path or query keyword is a `string`, since that's all either carries, and an untyped endpoint's body and 200 response are any value, `{}`.
|
|
689
693
|
- **API reference.** With `docs: true`, the app also answers GET and HEAD at `/docs`, before any route or static file, with an HTML page built once, at boot, as `text/html; charset=utf-8`. Its title is `Skyward.app`'s `title:`, HTML-escaped. It points Scalar at the document by the relative URL `openapi.json`, so it works under a prefix, and loads Scalar from jsDelivr, as `@scalar/api-reference` 1.75.1's `dist/browser/standalone.js` with its `sha384` integrity hash and `crossorigin="anonymous"`, or else from `Skyward.app(scalar_url:)`, HTML-escaped, with no hash. It has no inline JavaScript: Scalar is configured through `data-url` and `data-configuration`, which turns off its default fonts. Another method at `/docs` is answered as if there were no page, and `/docs/` isn't served. With `docs: true`, boot refuses a route whose path is `/docs`, and a static file there.
|
|
690
694
|
- **Request IDs.** The app `Skyward.app` returns gives every request an ID: an incoming `X-Request-Id` of 1 to 200 visible ASCII characters with no spaces, or else a random UUID from `SecureRandom`. The ID is stored in the Rack env as `skyward.request_id` before anything else runs, and every response carries it as `x-request-id`, replacing one the app set.
|
|
691
|
-
- **HTTP's own answers.** A path that matches routes only under other methods gets a 405 problem+json with an `allow` header listing the methods of every route matching it, in the order `GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS`, with `HEAD` wherever there's `GET` and always `OPTIONS`. `HEAD` runs the GET route and answers its status and headers with an empty body. `OPTIONS` on a routed path answers 204 with `allow`, and on any other path 404.
|
|
695
|
+
- **HTTP's own answers.** A path that matches routes only under other methods gets a 405 problem+json with an `allow` header listing the methods of every route matching it, in the order `GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS`, with `HEAD` wherever there's `GET` and always `OPTIONS`. `HEAD` runs the GET route and answers its status and headers with an empty body. `OPTIONS` on a routed path answers 204 with `allow`, and on any other path 404.
|
|
692
696
|
- **`skyward serve`.** Skyward API registers it with the `skyward` command. It runs the current directory's `config.ru`, needing no `app.rb`, under one Falcon process bound to `localhost`, on `PORT` (9292 by default), with `RACK_ENV=development` unless it's already set. It writes no files but `sig/generated`. With no `config.ru`, or no Falcon in the bundle `skyward` runs in, it exits 1 saying what to do. Under `bundle exec` that's the app's bundle; run bare, `skyward` sees every installed gem. It reloads the app when a `.rb`, `.rbs` or `config.ru` file under the directory is added, changed or removed, outside `tmp/`, `log/`, `vendor/`, `node_modules/` and hidden directories such as `.git/` and `.bundle/`, polling modification times at most once every half second. The first request after a change clears the routes and description of every API class defined in those files, drops those files from `$LOADED_FEATURES` so their `require`s run again, unloads and unregisters each Zeitwerk loader that manages only directories there (so `config.ru` can set it up again), reloads any other Zeitwerk loader with reloading enabled, and builds a new app from `config.ru`. When it starts, it first regenerates `sig/generated` with `Skyward::Core::Signatures::Inline.generate`, using the rbs-inline in that bundle, so the app loads the types the Ruby has now. Then it polls the same files in the background, at most once every half second, and regenerates `sig/generated` as soon as it sees a `.rb` file added, changed or removed, without waiting for a request, so Steep in your editor checks the types you just wrote. The reload still waits for the first request after the change, which regenerates first only if the background hasn't yet: rbs-inline runs once for the `.rb` files as they are, and never twice at once. Without rbs-inline in the bundle, it uses `sig/generated` as it is, runs nothing in the background, and says nothing about it. Regenerating writes only the files whose content changed, so it brings at most one more reload, of `.rbs` files alone, which doesn't regenerate. When rbs-inline fails, `sig/generated` is left as it was. A loader of the app's own needs reloading enabled: Zeitwerk can't unload one without it, or enable it after setup, so the reload fails saying to call `loader.enable_reloading` in development and restart. One reload runs at a time and requests wait for it, while a request in flight finishes on the app it started with. A load that raises, at boot or on a reload, including a `Skyward::Core::BootError` or a `SyntaxError`, answers every request until the next change retries it with the development 500 described under Errors: `type`, `title`, `status`, `detail` and `backtrace`, and an empty body for `HEAD`. So does rbs-inline failing, as a `Skyward::Core::BootError` that carries its output, with an empty `backtrace`. It has no `request_id`, because the app that assigns request IDs is the one that failed to load, and nothing is logged. Only `skyward serve` reloads.
|
|
693
697
|
- **`skyward routes` and `skyward openapi`.** Skyward API registers them with the `skyward` command too. Each loads the current directory's `app.rb`, which must assign `App = Skyward.app { ... }`, after regenerating `sig/generated` as `skyward serve` does, or using it as it is without rbs-inline in the bundle. When rbs-inline fails, it exits 1 with rbs-inline's output, without loading `app.rb`. With no `app.rb`, or no `App` that's a Skyward app, it exits 1 naming the file and what it must assign, and a `Skyward::Core::BootError` exits 1 with its message and no backtrace. `skyward routes` prints a line per endpoint, in mount order and then declaration order: its verb, full path, `Class#method` and its method type as the signature file writes it, with a type wrapped over several lines put on one, or for an untyped endpoint as `(id: untyped, ?done: untyped) -> untyped`. Each column but the last is as wide as its widest entry, then two spaces. An app with no routes prints nothing. `skyward openapi` writes the document the OpenAPI document bullet above describes, as pretty JSON with a trailing newline, whether or not the app passed `docs: true`, so the same app always writes the same bytes. Without `docs: true`, a route or static file at `/openapi.json` or `/docs` doesn't stop it, but the document's other problems exit 1 with their message.
|
|
694
698
|
- **`skyward check`.** Skyward API registers it with the `skyward` command. It checks the current directory's app three ways, in this order, writing `Signatures:`, `Strict boot:` or `Steep:` and then `passed` or `failed` as each finishes, followed by what it found, and runs every check even after one fails, then exits 1 if any failed and 0 otherwise. rbs-inline, the boot and Steep each run in a Ruby of their own, in the app's directory, with the gems of the bundle `skyward` runs in, as `skyward serve` describes, and nothing is written to the directory. **Signatures** runs rbs-inline, in its default opt-in mode, which reads only files marked `# rbs_inline: enabled`, over every `.rb` file in the directory outside `test/`, `spec/`, `vendor/`, `tmp/` and hidden directories, into a temporary directory. It fails when there's no `sig/generated`, or when the result differs from it, listing each file under `sig/generated` that's missing, out of date or not generated from any file, and either way gives the rbs-inline command that regenerates `sig/generated`. It also fails when rbs-inline does, with its output. **Strict boot** loads `app.rb` as `skyward routes` does, without regenerating `sig/generated`, with `SKYWARD_STRICT=1` in the environment, and fails where `skyward routes` would exit 1, with the same message, or on any other error, with its backtrace. It shows the boot's output even when it passes. **Steep** runs `steep check --no-daemon` with the app's `Steepfile`, and passes or fails as Steep does, with its output. Without rbs-inline or Steep in the bundle, or without a `Steepfile`, that check fails saying what to add.
|