skyward-api 0.2.0 → 0.4.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/README.md +49 -45
- data/lib/skyward/api/assembly/boot.rb +214 -66
- data/lib/skyward/api/cli/app_file.rb +9 -5
- data/lib/skyward/api/cli/check.rb +12 -29
- data/lib/skyward/api/cli/serve/reloader.rb +44 -3
- data/lib/skyward/api/cli/serve.rb +9 -2
- data/lib/skyward/api/cli/serve.ru +16 -1
- data/lib/skyward/api/commands.rb +18 -11
- data/lib/skyward/api/endpoints/declarations.rb +5 -1
- data/lib/skyward/api/endpoints/route.rb +3 -1
- data/lib/skyward/api/inputs/coercer.rb +37 -4
- data/lib/skyward/api/openapi.rb +2 -0
- data/lib/skyward/api/serializer/writers.rb +12 -1
- data/lib/skyward/api/serializer.rb +25 -7
- data/lib/skyward/api/version.rb +1 -1
- data/lib/skyward/api.rb +1 -0
- data/sig/generated/skyward/api/assembly/boot.rbs +99 -29
- data/sig/generated/skyward/api/cli/app_file.rbs +5 -4
- data/sig/generated/skyward/api/cli/check.rbs +2 -12
- data/sig/generated/skyward/api/cli/serve/reloader.rbs +28 -7
- data/sig/generated/skyward/api/cli/serve.rbs +4 -1
- 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/serializer/writers.rbs +6 -0
- data/sig/generated/skyward/api/serializer.rbs +13 -1
- metadata +17 -6
- data/lib/skyward/api/cli/executable.rb +0 -15
- data/sig/generated/skyward/api/cli/executable.rbs +0 -11
- data/sig/manual/skyward/api/cli/executable.rbs +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e72e644d6adbeff511700cdcc2197311da17c48b90100c21842aad90da0ab109
|
|
4
|
+
data.tar.gz: 5b39f4e0d513aeca35ded649fddaf796aa5026a563d84649b692d9d3d6079003
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e22a5084b19c1dfbbc09a2b544123d916697db91df7aca9d6a8b8d77a5dc25ee36a7b94468ae24b06d4bdf2b63061d3effab0c4c1b9377044b397216045f0218
|
|
7
|
+
data.tar.gz: d3658ebfe3ecddc6a091af040ae41c324711349961695192074da79d30dad57d411b2a5bcbd3a5e75d36d582cab75ebacb9620db33243cba94f90ce2dd838e42
|
data/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Skyward API
|
|
2
2
|
|
|
3
3
|
> [!CAUTION]
|
|
4
|
-
>
|
|
4
|
+
> Skyward API is pre-1.0. This README is its spec, most of it is built, and [Status](#status) lists exactly what is. Any release may change the API, so don't run it in production yet.
|
|
5
5
|
|
|
6
|
-
A
|
|
6
|
+
A Ruby web framework where **an endpoint is a method**, and its type signature is the API contract.
|
|
7
7
|
|
|
8
|
-
Its inputs are keyword arguments
|
|
8
|
+
Its inputs are keyword arguments and its response is the return value. Add an RBS signature and Skyward API coerces and validates the request against it, publishes it as your OpenAPI document, and Steep checks the method against it. Leave the signature off and it's plain Ruby.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
It's half of Skyward. The other half is [Skyward ORM](../skyward-orm/README.md), and you can use either without the other.
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
13
13
|
# config.ru
|
|
@@ -31,7 +31,7 @@ $ curl localhost:9292/hello/ruby?shout=true
|
|
|
31
31
|
{"message":"HELLO, RUBY"}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
The rest of this README is reference. If you only read one section, read [Types](#types).
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
@@ -41,7 +41,7 @@ That's the whole framework. The rest of this README is detail.
|
|
|
41
41
|
- [Endpoints](#endpoints)
|
|
42
42
|
- [Inputs](#inputs)
|
|
43
43
|
- [Responses](#responses)
|
|
44
|
-
- [Types
|
|
44
|
+
- [Types](#types)
|
|
45
45
|
- [OpenAPI docs](#openapi-docs)
|
|
46
46
|
- [Building an app](#building-an-app)
|
|
47
47
|
- [Providers](#providers)
|
|
@@ -49,7 +49,7 @@ That's the whole framework. The rest of this README is detail.
|
|
|
49
49
|
- [Testing](#testing)
|
|
50
50
|
- [Production](#production)
|
|
51
51
|
- [CLI](#cli)
|
|
52
|
-
- [Coming from
|
|
52
|
+
- [Coming from other frameworks](#coming-from-other-frameworks)
|
|
53
53
|
- [Design principles](#design-principles)
|
|
54
54
|
- [Status](#status)
|
|
55
55
|
|
|
@@ -107,7 +107,7 @@ Skyward API fills each keyword argument by its name:
|
|
|
107
107
|
| ----------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
108
108
|
| a path parameter (`id:` for `/:id`) | the URL path |
|
|
109
109
|
| `body:` | the parsed JSON request body |
|
|
110
|
-
| `request:` | the raw `Skyward::API::Request
|
|
110
|
+
| `request:` | the raw `Skyward::API::Request`, for headers, cookies and the IP |
|
|
111
111
|
| a [provided](#providers) name (`current_user:`) | your provider |
|
|
112
112
|
| anything else | the query string |
|
|
113
113
|
|
|
@@ -126,7 +126,7 @@ def create(body:)
|
|
|
126
126
|
end
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
`request:`
|
|
129
|
+
`request:` covers what typed inputs don't. It's a frozen `Skyward::API::Request`, built only when an endpoint or a provider asks for it, with the request's `headers` by lowercase name (`request.headers["authorization"]`), its `cookies`, the client's `ip`, its `request_id`, and `env`, the raw Rack env, for anything else. Its type is `Skyward::API::Request`, it never comes from the query string, and it never appears in the docs.
|
|
130
130
|
|
|
131
131
|
---
|
|
132
132
|
|
|
@@ -165,7 +165,7 @@ Error responses use [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) `applicat
|
|
|
165
165
|
}
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
Return a Rack triple for anything a value can't express: streaming, files, or a content type other than JSON. Its status, headers and body are sent as given, so a body that streams through `each` or `call` works. Rack 3 wants lowercase header names, and Skyward API doesn't rewrite them. A typed endpoint sends a triple only when its return type says so, with `Skyward::API::rack`, which is `[Integer, Hash[String, String], untyped]`, written `rack` under the [`# @rbs use` line](#types):
|
|
169
169
|
|
|
170
170
|
```ruby
|
|
171
171
|
# @rbs id: Integer
|
|
@@ -176,20 +176,22 @@ def export(id:)
|
|
|
176
176
|
end
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
Nothing checks what a triple sends
|
|
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
|
+
|
|
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.
|
|
180
182
|
|
|
181
183
|
---
|
|
182
184
|
|
|
183
|
-
## Types
|
|
185
|
+
## Types
|
|
184
186
|
|
|
185
|
-
Everything above works without types. Add a signature and
|
|
187
|
+
Everything above works without types. Add a signature and:
|
|
186
188
|
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
-
|
|
189
|
+
- `"42"` in the path becomes `42` when the signature says `Integer`.
|
|
190
|
+
- A body that doesn't match its type gets a 422 saying exactly what's wrong, before your method runs.
|
|
191
|
+
- The signature becomes the OpenAPI operation, with every response it can return.
|
|
192
|
+
- Steep checks your handlers like any other Ruby, because that's all they are.
|
|
191
193
|
|
|
192
|
-
Signatures are plain [RBS](https://github.com/ruby/rbs). Write them inline with [rbs-inline](https://github.com/soutaro/rbs-inline), or in `sig/*.rbs` files. Skyward API reads both, from the `.rbs` files under `sig/` (or the directory you pass as `Skyward.app(signatures:)`), so run rbs-inline
|
|
194
|
+
Signatures are plain [RBS](https://github.com/ruby/rbs). Write them inline with [rbs-inline](https://github.com/soutaro/rbs-inline), or in `sig/*.rbs` files. Skyward API reads both, from the `.rbs` files under `sig/` (or the directory you pass as `Skyward.app(signatures:)`). `skyward serve`, `skyward routes` and `skyward openapi` regenerate `sig/generated` from your inline annotations first, so you never run rbs-inline yourself. There's no schema DSL to learn and nothing to keep in sync: **the type you write for Steep is the API contract.**
|
|
193
195
|
|
|
194
196
|
A file whose signatures name Skyward API's types starts with `# @rbs use Skyward::API::*`, so they can write `Responses::NotFound`, `Responses::Created[Todo]` and `Request`: RBS doesn't look names up through the superclass, so without the line even an API class's signatures would need `Skyward::API::Responses::NotFound`. The line reaches only signatures, so Ruby code writes the full name, and so does a `#:` after an expression, which Steep also reads as Ruby.
|
|
195
197
|
|
|
@@ -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` |
|
|
@@ -363,7 +366,7 @@ end
|
|
|
363
366
|
|
|
364
367
|
A `summary:` is one line, and Skyward API refuses to boot if it has a line break. A `description:` is Markdown.
|
|
365
368
|
|
|
366
|
-
Comments are never read
|
|
369
|
+
Comments are never read, so they never reach your docs, and changing one can't change what you publish.
|
|
367
370
|
|
|
368
371
|
Docs are served only when you pass `docs: true`, so leave it out to hide them. With it, a route or a static file at `/openapi.json` or `/docs` fails boot. The document and the page at `/docs` are built once, at boot, and the same app always writes the same bytes. The document is your API's contract with the code that calls it. Skyward API doesn't write clients: write the document at build time, and generate a client from it with whatever tooling suits that code:
|
|
369
372
|
|
|
@@ -499,12 +502,13 @@ end
|
|
|
499
502
|
|
|
500
503
|
## Errors
|
|
501
504
|
|
|
502
|
-
Skyward API checks your app
|
|
505
|
+
Skyward API checks your app at boot, so mistakes show up when you start it, not at 3am:
|
|
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
|
|
|
511
|
+
app/todos_api.rb:12
|
|
508
512
|
get "/:id", to: :show
|
|
509
513
|
...
|
|
510
514
|
def show(todo_id:)
|
|
@@ -512,7 +516,7 @@ Skyward::Core::BootError: TodosAPI#show (GET /todos/:id)
|
|
|
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
|
|
|
@@ -555,7 +559,7 @@ describe TodosAPI do
|
|
|
555
559
|
end
|
|
556
560
|
```
|
|
557
561
|
|
|
558
|
-
|
|
562
|
+
There's no server or Rack in that test. The fake goes in through `initialize`.
|
|
559
563
|
|
|
560
564
|
When you want the whole stack, including routing, coercion, providers and middleware, use the test client:
|
|
561
565
|
|
|
@@ -578,9 +582,9 @@ end
|
|
|
578
582
|
|
|
579
583
|
## Production
|
|
580
584
|
|
|
581
|
-
|
|
585
|
+
Without any configuration, you get:
|
|
582
586
|
|
|
583
|
-
- **
|
|
587
|
+
- **Work done at boot.** Routes are compiled into a single matcher, and signatures are compiled into coercers and validators, all at boot. API objects are created once. A request is a route lookup, a coercion and a method call.
|
|
584
588
|
- **Bounded request bodies.** A body is read only for an endpoint that takes `body:`, and only up to `Skyward.app(max_body_size:)` bytes, 1 MiB (`1_048_576`) by default. A larger `Content-Length`, or a body that runs past the limit, answers 413 without reading the rest, and a body whose `Content-Type` isn't `application/json` or `*+json` answers 415.
|
|
585
589
|
- **Bounded error lists.** A 422 lists at most 1,000 problems, and coercion stops once it has found them. Each message writes its expected type in at most 200 characters, worked out at boot, so a small body can't produce a large response.
|
|
586
590
|
- **Bounded coercion.** A union's members only find whether a value fits, without writing errors, and a union nested in several members coerces each value once, so overlapping members don't multiply the cost of coercing a body by the type's depth.
|
|
@@ -654,44 +658,44 @@ No type error detected.
|
|
|
654
658
|
|
|
655
659
|
---
|
|
656
660
|
|
|
657
|
-
## Coming from
|
|
661
|
+
## Coming from other frameworks
|
|
658
662
|
|
|
659
|
-
- **Sinatra.** The routes will
|
|
660
|
-
- **Rails.** There's no controller instance per request and no `params` hash. Inputs arrive as arguments, and dependencies
|
|
661
|
-
- **FastAPI.**
|
|
663
|
+
- **Sinatra.** The routes will look familiar. The handler is a named method instead of a block, so you can call it, test it and type it.
|
|
664
|
+
- **Rails.** There's no controller instance per request and no `params` hash. Inputs arrive as arguments, and dependencies through `initialize`.
|
|
665
|
+
- **FastAPI.** Same idea: the function signature is the API contract. Here it's Ruby, with RBS for the type hints.
|
|
662
666
|
- **Grape.** You get the docs without the DSL.
|
|
663
667
|
|
|
664
668
|
---
|
|
665
669
|
|
|
666
670
|
## Design principles
|
|
667
671
|
|
|
668
|
-
1. **
|
|
669
|
-
2. **
|
|
670
|
-
3. **One
|
|
671
|
-
4. **Responses are values.** You return what happened. Nothing is raised for an ordinary outcome.
|
|
672
|
-
5. **Dependencies
|
|
673
|
-
6. **Boot does the work.**
|
|
672
|
+
1. **Plain Ruby.** An endpoint is a method on a class you wrote, with keyword arguments in and a value out.
|
|
673
|
+
2. **Optional types.** Nothing requires a signature. Each one you add gets you coercion, validation, docs and type checking for that endpoint.
|
|
674
|
+
3. **One contract.** The signature is the schema, so nothing is written twice.
|
|
675
|
+
4. **Responses are values.** You return what happened. Nothing is raised for an ordinary outcome like a 404.
|
|
676
|
+
5. **Dependencies are passed in.** Collaborators arrive through `initialize`, and per-request values through providers. Nothing reaches for globals.
|
|
677
|
+
6. **Boot does the work.** Mistakes stop the app from booting, and routes and types are compiled once, at boot, instead of on every request.
|
|
674
678
|
|
|
675
679
|
---
|
|
676
680
|
|
|
677
681
|
## Status
|
|
678
682
|
|
|
679
|
-
This README is the spec
|
|
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
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 tried in mount order, then declaration order. 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.
|
|
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,
|
|
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. 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.
|
|
692
|
-
- **`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
|
|
693
|
-
- **`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 { ... }`. 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
|
-
- **`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, 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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
695
699
|
- **The test client.** `Skyward::API::Test.client(app)` drives any object with `call(env)` in-process, with no server, and never loads Minitest or RSpec. Its `get`, `post`, `put`, `patch`, `delete`, `head` and `options` each take a path, which may include a query string. `json:` sends a JSON body with `content-type: application/json`, and without it no body is sent. `headers:` sends request headers by their HTTP names, and `cookies:` sends a Hash as a `cookie` header. Each returns a frozen response with `status`, `headers` as the app returned them, `body` as text, and `json`, the body parsed with Symbol keys when the content type is JSON or `+json` and the body isn't empty, and `nil` otherwise. The client reads the whole body and closes it when it responds to `close`.
|
|
696
700
|
- **Middleware.** `use` adds Rack middleware, with the same arguments as `Rack::Builder#use`, so CORS comes from rack-cors. Middleware wraps the routes in declaration order, the first `use` outermost, wherever it sits relative to `mount`. Request IDs and request logs sit outside it, so a response from middleware still carries an ID and is logged. The stack is built once, at boot, and the app stays frozen, though the middleware objects themselves aren't frozen. Error handling sits outside it too, so an exception from middleware is still answered with a 500.
|
|
697
701
|
- **Request logs.** Unless `Skyward.app` is given `logger: nil`, every request logs one JSON object on one line, whatever answered it, including a 404 or a 500: `time` (when the request arrived, ISO 8601 in UTC to the millisecond), `method`, `path` (Rack's `SCRIPT_NAME` and `PATH_INFO`, so never the query string), `status`, `duration_ms` (until the app returns its response, to two decimal places) and `request_id`. It writes to `$stdout`, or calls `info` on the `logger:` it's given.
|