openwrt-iac / uapi / docs / 3.5.0 / API versioning policy
The URL prefix /api/v<N>/ tracks the wire-contract major: uapi 3.x serves
under /api/v3/, a future v4 would mount at /api/v4/. Within a given
installed major, additions are backwards-compatible.
Package version follows semver, with the major version aligned to the API major:
(x+1).0.0): breaking on-the-wire change. A given uapi
installation serves exactly one API major; we do NOT mount /api/v(x+1)/
alongside /api/v<x>/ in the same binary. Operators who need to keep an old
client working keep the previous package version installed (older APKs remain
attached to their GitHub Releases at
https://github.com/openwrt-iac/uapi/releases, and the signed git tag is the
canonical contract document).x.(y+1).0): backwards-compatible additions only (see below).x.y.(z+1)): bug fixes only. No surface change.A client tested against x.y.z works against every future x.y'.z' with y' >=
y.
A major is expensive to have, not to fill. Operators pin a package, clients regenerate, the migration document gets written, and the feed carries two lines for a while. That cost is paid the moment the major exists and barely moves with how much it contains. So when one happens, take everything.
The objective of a major is to raise quality and remove complexity, and it should break as much as it needs to in order to do that. Not only the changes that are individually unavoidable: every compatibility shim, mirrored field name, union type kept for an old client, over-declared response, and branch that exists solely to keep a previous contract working is eligible, and the default answer is to remove it. Simplification is a sufficient reason on its own. A compatibility branch nobody can delete is a permanent tax on every future change to the code around it, and a major is the only moment the tax can be repealed.
Two things follow.
Minors stay strict, and that is the trade. Being permissive in a major is what lets a minor refuse. The carve-outs above are deliberately narrow and their tests are meant to be applied literally; when a change does not qualify, the answer is to queue it for the major rather than to widen a carve-out. A rule bent once stops being a rule.
Queued debt has to be written down or it will not be swept. Anything
deferred with "this
needs a major" belongs in docs/roadmap.md under the objectives for the next
major,
with enough detail to act on years later. The failure mode is not shipping a
breaking change; it is arriving at a
major, shipping the three items someone remembered, and paying the whole cost
again for the
rest.
code
gracefully.deprecated: true in build/openapi.json, an entry added to
docs/deprecations.md, and the actual removal scheduled for the next major.
The deprecation log is the canonical place the operator-facing migration
lives.docs/deprecations.md removal target.Carve-out. When the declared type could not represent the field's real state, correcting it can ship in a minor with a CHANGELOG entry naming this carve-out, the branch it relies on, and the affected values. Two branches qualify, and each needs evidence rather than an argument.
(a) No value of it was ever a correct answer. 2.5.0's
system.urandom_seed and lldpd.lldp_description, both typed boolean while
holding a filesystem path and free text respectively: true was unreachable
as a truthful answer, and every write replaced the operator's value with
"1".
(b) The server violated its own declared type for a reachable
configuration, so no generated client could rely on the field even though
individual reads conformed. 2.5.0's dhcp/hosts.tag, declared ["string",
"null"] while a section storing list tag returned an array. That is the
ordinary uci spelling for more than one tag and what LuCI writes, so the
schema was wrong for a configuration operators actually have. A scalar option
tag 'red' did read back correctly under the old type, which is exactly why
branch (a) does not cover it.
Branch (b) exists because the original wording of this carve-out was narrower
than its own opening clause: it demanded that no value ever be correct, which
is a strictly smaller set than "the declared type could not represent the
field's real state". tag fell in the gap and shipped anyway, and
#126 is what surfaced that
the rule and the release disagreed.
A correction under either branch can land silently, so the CHANGELOG entry
has to say how loudly it fails. The type gate rejects a wrong JSON type, but
only if the client sends one. A client whose configuration language coerces
booleans to strings never does: HCL, most YAML-to-JSON paths with an unquoted
true, and shell interpolation all turn true into "true", which is a
valid string and is accepted. 2.5.0's lldp_description takes it and
advertises the literal text true; urandom_seed takes it and stays off,
because its reader only acts on a value starting with /. Boolean-to-string
is the coercion-prone direction. String-to-array is not, which is why
dhcp/hosts.tag fails loudly for every client. Say which case the field is
in, and if it is the silent one, say what to grep for instead of an error.
Neither branch covers widening a type for convenience, nor a field where every reachable configuration produced a conforming read. Branch (b) requires naming the uci configuration under which the old server broke its own schema. If you cannot name one, the change waits for the major. - Making a previously-optional request field required. - Tightening validation to reject previously-accepted payloads. (Carve-out: when the previously-accepted payload produced broken state no caller can rely on, tightening can ship as a patch with an explicit CHANGELOG entry naming the carve-out. 2.2.1's cross-section uniqueness check is the precedent.)
Security carve-out. A security fix can refuse, in a minor, a payload that
an earlier release accepted, when its CHANGELOG entry names this carve-out,
says which payloads it now refuses, and says why. Unlike the carve-out above,
it also covers a payload whose state a caller could rely on. 3.2.0's check of
the IPv6 prefix length in a token's allowed_cidrs is the precedent.
There is no parallel mount; we don't carry two surface areas in a single binary
on resource-constrained hardware. Operators who need to keep a v1 client working
keep the v1 package installed (the v1.2.1 APK stays available on the feed; the
signed v1.2.1 git tag is the canonical v1 contract). The migration table for
v1 → v2 lives at docs/migration-v1-to-v2.md.
/raw/ stabilityURL structure, verbs, auth/scope behavior, and error envelope are stable within
a package major. Payload shape follows uci, which is OpenWrt's moving target. If
OpenWrt changes the firewall package schema, /raw/firewall/... payloads
change with it. Documented loudly so users don't expect curated-level stability
from raw. See docs/raw.md for the full stability disclaimer.
The emitted openapi.json carries the same version as the API it describes
(info.version: "2.3.0" for uapi v2.3.0). The spec is the source of truth for
what's in the contract at any given release.
Property schemas under components.schemas.*.properties carry two non-standard
annotations beyond the OpenAPI baseline shape:
default: the value fromUci synthesizes when the underlying uci option
is absent. Standard OpenAPI 3.1 / JSON Schema 2020-12 keyword. The framework
does NOT apply this default to incoming requests; it is documentation of the
server-side fallback so IaC clients can keep the field sticky
(Optional+Computed) instead of mistakenly treating it as caller-owned.x-uapi-clear-on-omit (vendor extension, boolean): when present and
true, the field is caller-owned and clearing it converges. The flag is
mutually exclusive with default: (a defaulted-and-clearable field produces
perpetual non-converging diffs). Note what the flag does not mean: the
server accepts explicit JSON null for any modeled field and clears the
underlying uci option, flagged or not, which is what makes a read-modify-write
work at all when the read answered null. The flag marks where clearing is
safe, not where it is possible, and its value is that a defaulted field is
never marked, so a client that treats flagged fields as clearable cannot enter
the diff loop above.Both annotations are enforced by make lint-defaults. See
docs/adding-a-resource.md for the authoring rules.
A generated client can rely on two properties of the split, both enforced by
lint-openapi-shape
rather than left to the generator's habits.
A <Name>Request exists exactly when the resource can be written. Read-only
endpoints get a
response schema and no request schema, so a client may treat a missing request
half as "not
writable, or removed". That inference is what makes a removed resource fail
codegen loudly
instead of generating something that no longer exists.
For a curated resource, the response half contains every field of the request
half. The
request half is the response's property map minus the response-only entries
(runtime,
managed) and anything marked readOnly, so the containment is structural
rather than a
coincidence of the current field set. A client may therefore derive writability
by membership:
a field present in the response and absent from the request is server-derived,
which is how
network/interfaces.ipaddr reads as computed with no special case.
A request type can be wider than the response type of the same field while a
write form is
phased out. network/interfaces.ip6prefix is the case since 3.2.0: a read is
always an array,
and a write still takes the space-separated string that the 3.1 spec declared,
until the next
major removes it. A type in <Name>Patch is also wider where it takes a null
that a read does
not return, because a null removes the field. The merge-patch body below says
which fields.
A request can also be narrower than the response, since 3.2.0, where a read returns a value that the request schema does not take. Four kinds of value qualify:
mtu below 68
or a route
table of 0,listen_port -1 for a
service name that /etc/services does not know,network/interfaces.proto that uapi does not model, such as the 6in4 that
LuCI writes,probe_count above 10, the bonding type of network/devices that LuCI
writes, or the HELPER target of firewall/rules.The response declares what a read can return, and the request declares what a
write can send,
so a read-modify-write of such a value fails against the request schema. The
server refuses it
too, except where the rule is in validate_new(), such as the -1 of
network/wireguard_peers.persistent_keepalive: there the server takes a write
that leaves the
stored value as it is. The server also takes a write that sends back a value of
the fourth kind, a PUT of the read too, and refuses one that changes a field to
it, with the message that it gave before the read widened. The description of
each such field says so. A firewall/rules PUT of HELPER stays refused,
because a PUT removes the set_helper option, which uapi does not model, and
firewall4 skips a HELPER rule without it. A module declares the difference
with x-uapi-write, and tests/unit/write_overlay_test.uc checks each such
keyword against the refusal in validate().
The response half of a curated resource declares no pattern, since 3.2.0. A
pattern says what a
write may send, and a read returns a value as uci holds it. uci, LuCI or an
older uapi can store
a value that breaks the pattern, such as a clientid with dashes, so a pattern
in the response
would be a promise that a GET breaks. The request half keeps every pattern, and
the sweep of
/diagnostics?validate=1 lists a stored value that breaks one.
The merge-patch body of a PATCH requires nothing, since 3.2.0. The server type-checks that body and merges it into the stored section. It checks the required fields on the result, so a body can leave out a field that a create requires.
application/json body of a PATCH is <Name>Patch, on a CRUD resource
and on a
singleton. It has the properties of <Name>Request with the same types,
enums, patterns and
bounds, and it takes null as the list below says. It has no required and no
conditionals.match of firewall/redirects, has no
required either. The
server merges it into the stored object.<Name>Patch has no defaults. A merge-patch body has none, and a client that
fills defaults
would overwrite stored values on every PATCH.<Name>Patch leaves descriptions and examples to <Name>Request, because the
document ships
on the router. A deprecated field keeps its description, which says why.<Name>Request. That schema
stays in the document for a client that names it, and it does not change.
Before 3.2.0 it was
the PATCH body of the singleton, so a regenerated client finds that body under
<Name>Patch.application/json-patch+json body is JsonPatch.The merge-patch body of a PATCH takes null on a field where the server removes
the field for a
null, since 3.2.0. RFC 7396 removes a member with null. The server skips a null
in its type
check, the merge sets the field to null, and toUci leaves the option out, so
the write removes
it. A read then gives what it gives for an unset option, often the default. On a
nested object
such as match, a null removes that member only. An array does not take null
items, because a
merge patch replaces an array whole. These fields keep the type of
<Name>Request, because a
null does not remove them:
id. A PATCH ignores it.wireless/interfaces.key. A null keeps the
stored secret.<Name>Request requires, such as network/interfaces.proto or
the match of
firewall/redirects. The merged section needs it, so the server refuses its
null with 422.
The one exception is mwan3/interfaces.family, which validate() does not
require, so a null
removes it. Some of these fields take null in <Name>Request, because a read
can return null
for them, such as firewall/rules.target and mwan3/interfaces.family. The
merge-patch body
takes that null too.wireless/interfaces.mode. The server refuses its null with 422, because
wifi-scripts sets up
no interface without a mode, and storing ap would turn a station into an
access point. A
create or a PUT that leaves mode out stores ap. The module names such a
field in
openapi_patch_non_null.This changes no <Name>Request and no <Name>Response.
Before 3.2.0 the merge-patch body was an allOf of the Request, which refuses
null on most
fields. So a strict client refused partial bodies and removals that the server
accepts.
The two operation-shaped pairs, BatchRequest and TokenCreateRequest, are
hand-written rather
than generated from a resource module, and are legitimately request-only in
places: a token
create sends scopes and gets back a token. They are outside the rule, and
outside the lint.