N11
Error
Requests
N11 — Any or Map where a service meets the program
What crosses to a service — a parameter, a body, an answer, what a read holds — has a type the program names: a type with its fields, a dictionary, or Json for JSON whose shape is open. Any and Map say nothing of what arrives, so nothing about it can be checked.
What the compiler said
error[N11]: `body` of `Backend.signUp` is `Map`, which says nothing of what it holds --> src/App.wf:2:5 | 2 | post signUp(body: Map) at "users" -> ! | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Name it: a `type` with its fields, a dictionary `[String: T]`, or `Json` for JSON whose shape is open = docs: https://webfluent.monzeromer.dev/errors/N11
Your editor offers this fix: Write Json. wf fix --code N11 applies it to every place it fits.
The fix
Broken
api Backend(base: "/api") {
post signUp(body: Map) at "users" -> !
}
page P(path: "/", title: "T", description: "D") {
Heading("Join").h1
Button("Join") { on click { Backend.signUp(body: { email: "ada@example.com" }) } }
}
Fixed
type SignUp { email: String }
api Backend(base: "/api") {
post signUp(body: SignUp) at "users" -> !
}
page P(path: "/", title: "T", description: "D") {
Heading("Join").h1
Button("Join") { on click { Backend.signUp(body: SignUp(email: "ada@example.com")) } }
}
Name the type: a type with the fields the service sends, a
dictionary [String: T] for one keyed by name, or Json for JSON whose
shape really is open, which is then matched or decoded. The quick fix
writes Json.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Error.
A request is where a program meets data it did not make. What crosses —
an endpoint's parameters and body, its answer, what a resource holds,
what an http call answers — is a type the program names, so the checker
can hold every use of it to its fields and every answer can be checked
when it arrives. Any and Map say nothing of what is in them.
http.get names what it answers where the answer goes: let rows: [Row] =
try await http.get(url), or resource rows: [Row] = http.get(url). A
write whose answer nothing reads needs no type for it.
lints cannot lower it: it would ship a broken page.