Configuration reference (json_api:) and optional dependencies¶
The bundle's configuration tree is intentionally tiny. Most of what makes a
JSON:API type work — discovery, routing, the data layer, validation — is wired by
service tags and autoconfiguration, not configuration keys (see
capability composition and the data layer).
What json_api: configures is the small set of values that can't fall out of
discovery: the API's base_uri and version, the server default paginator's
page-size cap, the ?include nesting-depth cap, an optional structural linter toggle,
and — for the multi-API case — additional named servers.
There is no Configuration.php and no Extension class. The tree is declared
inline in the bundle's configure() (an AbstractBundle), and the extension alias
json_api is auto-derived from the bundle name. The whole tree lives in
JsonApiBundle::configure().
The config tree¶
The main top-level keys, all optional:
# config/packages/json_api.yaml
json_api:
base_uri: 'https://music.example'
version: '1.1'
max_include_depth: 3
strict_query_parameters: true
link_objects: true
reject_read_only_attributes: false
pagination:
max_per_page: 50
doctrine:
window_functions: true
atomic_operations:
enabled: false
defaults:
cache_headers:
max_age: 60
public: true
servers:
admin:
base_uri: 'https://admin.music.example/admin'
— config/packages/json_api.yaml
(the example app's real config; the admin server is the multi-server
witness).
| Key | Type | Default | What it does |
|---|---|---|---|
base_uri |
scalar | '' |
The base prepended to every generated link. Empty (the default): links are absolute, built from the request's scheme + host plus the prefix the server's routes are imported under, so each tenant/host gets correct self-links with no hardcoded host. Set a value to pin a fixed canonical base regardless of the request; it must then include that prefix itself. Trailing slashes are tolerated. |
version |
scalar | '1.1' |
The JSON:API version the implicit default server advertises. Defaults to '1.1', so set it only to pin a non-default version — most apps omit it (the example app's '1.1' above is just the explicit-version witness). |
max_include_depth |
int | 3 |
The cap on ?include nesting depth (relationship hops from the primary resource). 0 is unlimited. A resource's own maxIncludeDepth() overrides it. |
output_timezone |
scalar | null |
The zone every DateTime attribute of the default server renders in, such as UTC, unless the field sets its own outputTimezone(). Date and Time attributes are left alone. null or '' renders each value in the zone it carries. Named servers inherit it. See output_timezone. |
link_objects |
bool | true |
Render the links the server builds as JSON:API link objects ({"href": …}), which carry a describedby into the OpenAPI document. false renders bare URL strings. Named servers inherit it. |
strict_query_parameters |
bool | true |
Reject an unrecognized top-level query-parameter family — and an unknown fields[type] sparse-fieldset member — with a 400. false restores the old silent-ignore behaviour. |
pagination.max_per_page |
int | 100 |
The page-size cap the built-in server default paginator clamps page[size]/page[limit] to. 0 installs no built-in default (those collections render unpaginated). |
doctrine.window_functions |
bool | true |
Use SQL window functions (ROW_NUMBER/COUNT OVER) for the bounded windowed-include batch. Requires MySQL ≥ 8, MariaDB ≥ 10.2, SQLite ≥ 3.25, or any PostgreSQL. On an older engine the default true throws a 500 at the first windowed include — set false for the per-parent bounded fallback. |
atomic_operations.enabled |
bool | false |
Emit the Atomic Operations endpoint (POST {path}) per server. |
atomic_operations.path |
scalar | /operations |
The path the Atomic Operations endpoint is served at. Must not equal a resource's collection path (the loader fails fast if it does). |
atomic_operations.scopes |
list | null |
The OAuth scopes the Atomic Operations endpoint itself needs on every server, replacing the scope resolver's answer. [] needs none. Each operation in a batch is still checked against its own scopes. |
schema_validation |
bool | false |
Registers the optional opis structural linter. Enabling it without opis/json-schema fails the build. |
defaults.cache_headers |
map | {} |
Fleet-wide default HTTP cache directives for GET reads. A server's own defaults.cache_headers and then a resource's own cacheHeaders merge over these. |
defaults.deprecation / sunset / sunset_link |
scalar | null |
Fleet-wide default deprecation/sunset headers. A server's own defaults and then a resource's own deprecation/sunset/sunsetLink override these, key by key. |
reject_read_only_attributes |
bool | false |
Answer a create or update that sends an attribute the client cannot write in that request, such as a readOnly() or computed one, with a 403 ATTRIBUTE_WRITE_PROHIBITED pointing at each such attribute, instead of ignoring it. The check runs before validation, so it wins over a 422. Named servers inherit it. |
exceptions |
map | {} |
Map an exception class to an HTTP status, so a thrown instance renders as a JSON:API error with that status. See errors. |
error_codes.paths |
list | [] |
Directories scanned at build time for your DescribedErrorInterface exceptions, which the OpenAPI error catalogue then documents beside core's. See errors. |
profiles |
list | the four built-ins | The ProfileInterface classes every server recognizes: CursorPaginationProfile, CountableProfile, RelationshipQueriesProfile and NestedFieldsetsProfile by default. Drop one to stop recognizing and advertising it (its query parameters leave the OpenAPI document too), or add your own class. Without NestedFieldsetsProfile a request still selects keys of an attribute declaring a nested fieldset, but the response no longer advertises the profile. |
openapi |
map | see OpenAPI | Document generation, serving, the viewer, describedby links, examples and security schemes. Every key is covered on the OpenAPI page. |
servers |
map | [] |
Additional named servers, keyed by name. Each takes base_uri, version, output_timezone, link_objects, reject_read_only_attributes, openapi_examples and a defaults block of its own. |
base_uri and version configure the implicit default server — link core
server.md for what
a core Server does with them. A single-API app sets just base_uri (and usually
nothing else) and never touches servers:.
Empty
base_uri(the default) emits request-host-absolute links — a request tohttps://albums.example/albums/1renders aselflink with"href": "https://albums.example/albums/1", scheme and host taken from the incoming request's origin. That is the multi-tenant / multi-host recipe: one deployment served under several hostnames emits correct absolute self-links per host with no per-request configuration. Behind a TLS-terminating proxy this works as long as the request is proxy-aware — configure Symfony's trusted proxies so the public scheme/host (X-Forwarded-Proto/X-Forwarded-Host) flow into the request the bundle reads. Set a non-emptybase_urionly when every link must carry a single fixed canonical host regardless of the request; it is a compile-time constant applied to every request and is not request-host aware. Trailing slashes on a configured base are tolerated (https://api.example/andhttps://api.exampleare equivalent).
Mounting a server under a prefix¶
A server's routes can be imported under a prefix (see routing):
With an empty base_uri, links follow the mount. The bundle records each route's
import prefix when the router loads its routes, and on every request it bases the
links on the request origin plus that prefix. A request to
https://tenant.example/api/v5/advertisers/1 renders https://tenant.example/api/v5/advertisers/1
as both the resource and the document self, and pagination links read
https://tenant.example/api/v5/advertisers?page[number]=2… with the prefix once. Each
named server follows its own import, so default under /api/v5 and admin under
/admin each link under their own prefix. A prefix with placeholders
(/{tenant}/api) works too: its value comes from the request path. A front controller
served below the web root (/app/index.php) adds its base path in the same way.
The OpenAPI document advertises the same prefix as a relative servers URL
(/api/v5); see OpenAPI for placeholders and what it
can't see.
A configured base_uri is used as it is, so it has to include the prefix:
Resource links append the server-relative path to that base. Document self and
pagination links reuse the request path, which already starts with /api/v5, so core
drops the base's own path from the front of it and the prefix appears once. A
configured base without the prefix (https://api.example for routes under /api/v5)
renders resource links that miss the prefix.
Hand-written routes (see routing)
don't go through the route loader, so nothing records their prefix. Set the
_jsonapi_mount route default on them yourself, or an empty base links them from the
request origin alone.
Container parameters¶
The bundle sets these container parameters, which you can read elsewhere (for example
as %haddowg_json_api.base_uri% in a service definition):
| Parameter | Source | Value |
|---|---|---|
haddowg_json_api.base_uri |
base_uri |
the configured (or empty) base URI |
haddowg_json_api.version |
version |
the configured (or '1.1') version |
haddowg_json_api.max_include_depth |
max_include_depth |
the resolved include-depth cap (default 3, 0 = unlimited) |
haddowg_json_api.pagination.max_per_page |
pagination.max_per_page |
the resolved page-size cap (default 100, 0 = no built-in default) |
haddowg_json_api.doctrine.window_functions |
doctrine.window_functions |
whether the Doctrine provider runs the native windowed-include batch (default true) or the per-parent bounded fallback |
haddowg_json_api.atomic_operations.enabled |
atomic_operations.enabled |
whether each server gets the Atomic Operations endpoint (default false) |
haddowg_json_api.atomic_operations.path |
atomic_operations.path |
the endpoint's path (default /operations) |
haddowg_json_api.atomic_operations.scopes |
atomic_operations.scopes |
the endpoint's own scope list, or null to ask the scope resolver (the default) |
haddowg_json_api.openapi |
openapi |
the whole openapi block as plain arrays and scalars, rebuilt into the document config at runtime |
haddowg_json_api.openapi.scope_scheme |
openapi.security.scope_scheme |
the security scheme operation scopes are listed under (default oauth2) |
json_api.exceptions |
exceptions |
the exception class → HTTP status map (default []) |
haddowg_json_api.error_code_paths |
error_codes.paths |
the directories scanned for your described error codes (default []) |
haddowg_json_api.servers |
derived | the list of all server names, e.g. ['default', 'admin'] |
haddowg_json_api.entity_class_by_type |
derived | the type → entity class map declared through #[AsJsonApiResource(entity:)], published with or without Doctrine |
haddowg_json_api.installed_versions |
derived | the version and commit of haddowg/json-api-symfony and haddowg/json-api the container was compiled against, checked on boot (see upgrading) |
haddowg_json_api.servers is the resolved name list — always including the implicit
default — that the compiler pass reads to validate resource-to-server assignments
and bucket each type onto the right server.
pagination.max_per_page¶
The bundle gives every server a default paginator — by default a
page-number/page-size strategy
(core PagePaginator) —
and pagination.max_per_page is the cap it clamps a client's page[size] to.
A client controls the page size, so without a ceiling ?page[size]=1000000 would
force your store to fetch a million rows — a page-size denial-of-service vector.
The cap closes it by clamping the resolved size down to the maximum (the same
clamp-don't-400 stance core takes for every garbage page[…] value), so an
over-large request returns the capped number of items with a 200 and
meta.page.perPage reports the cap.
The cap is on by default at 100 — every collection resolving to the server
default is protected without any configuration. Set 0 to install no built-in
default paginator: collections that resolve to the server default then render
unpaginated (the whole list, no page links). A resource (or relation) that
declares its own
pagination()
paginator overrides the server default entirely and sets its own cap with
withMaxPerPage().
The cap concept, the wither and the disable-with-0 semantics are all owned by
core — see core
pagination.md → Capping the page size.
max_include_depth¶
A compound document can grow without bound in two ways: a deeply nested
?include=a.b.c.d.e walks the relationship graph as far as the client asks, and a
default-included relation pointing back at its own type (or a mutual pair — A
default-includes B, B default-includes A) recurses the renderer forever. Both are
denial-of-service vectors, and the second is a latent infinite loop. max_include_depth
closes both: it caps the nesting depth of an ?include, where depth is the number
of relationship hops from the primary resource — ?include=a is depth 1,
?include=a.b.c is depth 3.
The cap is on by default at 3 — a request for a path deeper than the cap is a
400 (INCLUSION_DEPTH_EXCEEDED), and a default-include cascade silently stops at the
cap (so a mutual default-include cycle terminates rather than looping). Set 0 for
unlimited (core's unopinionated default). A resource overrides the server default
for requests where it is the primary/root type by implementing core's
IncludeControlsInterface::maxIncludeDepth():
final class CommentResource extends AbstractResource
{
public function maxIncludeDepth(): ?int
{
return 1; // this type only ever compounds one hop deep
}
}
The depth cap is one of four composing include safeguards. The
other three are author-declared, not config: a per-relation cannotBeIncluded() opt-out,
a root-scoped allowed-include-paths whitelist
(IncludeControlsInterface::getAllowedIncludePaths()) and a root-scoped excluded-paths
list (IncludeControlsInterface::getExcludedIncludePaths()). See
relationships → controlling what can be included
for all four. The depth-cap concept and the IncludeControlsInterface seam are owned by
core; the bundle supplies only the opinionated default of 3 and threads it to each
server.
Customising the server default paginator¶
The built-in default is PagePaginator. To make a server default to a different
strategy — a CursorPaginator,
an OffsetPaginator, or your own — register a PaginatorInterface service under a
conventional id. The ServerFactory reads it via nullOnInvalid(), so
registering the service is the entire wiring (no tag, no compiler pass). Two ids,
resolved by-server-first then generic:
| Service id | Applies to |
|---|---|
haddowg.json_api.default_paginator |
every server (the generic default) |
haddowg.json_api.default_paginator.<name> |
one server only (overrides the generic for that server) |
# config/services.yaml
services:
# Cursor pagination for every server's default…
haddowg.json_api.default_paginator:
class: haddowg\JsonApi\Pagination\CursorPaginator
# …but keep the page-number default on the `admin` server only.
haddowg.json_api.default_paginator.admin:
class: haddowg\JsonApi\Pagination\PagePaginator
factory: [haddowg\JsonApi\Pagination\PagePaginator, make]
A custom paginator owns its own page-size ceiling, so pagination.max_per_page
applies only to the built-in PagePaginator fallback — set a cap on your own
paginator with its own withMaxPerPage() where the strategy supports one. The full
resolution order a server walks is: this-server service → generic service →
built-in capped PagePaginator (when max_per_page > 0) → none (max_per_page: 0).
As always, a resource/relation pagination() still wins over whatever the server
resolves.
schema_validation¶
schema_validation is an optional dev/CI structural linter, distinct from the
always-relevant semantic validation. When true, the bundle wires core's
DocumentValidator + VendoredSchemaProvider so write bodies are checked against
the JSON:API JSON Schema before they reach the handler (a 400 on a malformed
document) — link core
schema-validation.md
for what the linter checks. It is off by default and is not a substitute for the
Symfony Validator bridge, which validates values against your
declared constraints (a 422).
opis/json-schema is a suggest dependency, so enabling schema_validation
without it is a wiring mistake the bundle catches at container-build time:
json_api.schema_validation is enabled but opis/json-schema is not installed;
require opis/json-schema (dev/CI) to use the structural document linter.
You can toggle it per-environment by layering a partial override — the example app's
SchemaValidationKernel
does exactly this, merging ['schema_validation' => true] over the shipped config so
base_uri/servers stay unchanged.
output_timezone¶
Set it when your data holds local times but the API should answer in one zone:
A DateTime attribute stored as 2024-06-01T21:30:00+02:00 then renders as
2024-06-01T19:30:00+00:00. The conversion is core's Server::withOutputTimezone()
(see core's server docs),
so these rules come from core:
- A field's own
outputTimezone()wins over the server zone. DateandTimefields never take the server zone. A calendar date stored as local midnight would land on the previous day in UTC, and a time of day has no date to convert against. Give such a field its ownoutputTimezone()if you do want it moved.- It reaches every place a resource renders its attributes: primary data,
included, related endpoints,on()flattened attributes, andDateTimechildren of aMap,ObjorOneOf. - A hand-written serializer formats its own values and is not affected.
The bundle also applies it to DateTime pivot fields
in meta.pivot, with the same rules.
The value must be a zone PHP's \DateTimeZone accepts, normally an identifier such as
UTC or Europe/London. null (the default) and '' both mean no conversion.
Anything else fails the container build:
Invalid configuration for path "json_api.output_timezone": "Europe/Londn" is not a
timezone PHP recognises. ...
A named server inherits the top-level zone, sets its own, or turns conversion off
with ''. See named servers.
strict_query_parameters¶
By default the bundle rejects an unrecognized top-level query-parameter family
with a 400. Before this, a misspelled or unsupported
family was silently dropped — so ?filtr[title]=x (a typo for filter) returned a
wrong-but-200 collection instead of an error, and a client could not tell its
query was ignored. Strict mode turns that silent failure into a loud one.
A family is recognized when its base name is:
- a reserved JSON:API family —
include,fields,filter,sort,page,profile(their internal key validation is unchanged: an unknownfilter[…]/sortkey or a badpagestill400s on its own); - a negotiated profile's keyword — the Relationship Queries
profile's
relatedQuery/rQand the Countable profile'swithCountare recognized only when the profile is registered and the client negotiated it inAccept, so addressing one without negotiation400s rather than being ignored; - any param an app registers via
Server::withCustomQueryParameter().
Anything else is a 400 (QUERY_PARAM_UNRECOGNIZED, source.parameter = the
offending base name). This aligns with the spec, which mandates a 400 for a
query param that follows neither the reserved-family rules nor the
custom-param naming rules and that the server does not recognize, and permits a
400 for a well-named custom param the server does not support — strict mode takes
the 400.
Set it to false to opt out (e.g. while migrating a client that sends stray
params). Note that core's always-on spec baseline still rejects an all-lowercase
custom param (one with no non-a-z character, like ?bogus) regardless of this
toggle — the spec requires it. The toggle governs the strict superset: a
well-named unsupported custom param (one carrying an uppercase letter or other
non-a-z character) is 400'd when strict and ignored when relaxed.
Unknown sparse-fieldset members¶
The same gate also rejects an unknown fields[type] member. A sparse fieldset
such as ?fields[articles]=title,bogus previously dropped bogus silently and
returned a wrong-but-200 document; with strict_query_parameters on (the default)
a member that names no declared field of a known resource type is now a 400
(FIELDSET_MEMBER_UNRECOGNIZED, source.parameter = fields, the message naming
the offending member) — mirroring how an unknown ?include path already 400s. The
check covers every named fields[type], including the types of ?included
related resources, so a typo in an included type's fieldset is caught too.
The recognized member set is a resource's full declared field namespace — every
attribute and relationship name it declares, including id, hidden, write-only and
non-sparse fields. So a member is "unknown" only when it names no
declared field at all (a real typo): naming a hidden field is tolerated (a hidden
name and a bogus name behave identically, so there is no information leak), as is id
or a non-sparse field. A fields[type] for a type the server cannot resolve (an
unregistered type) is left alone — only unknown members of known types are
rejected. An <attribute>.<key> member is known when the attribute declares a
nested fieldset that accepts the key;
any other dotted member is unknown. Setting strict_query_parameters: false stands this
member check down too, restoring the silent-drop behaviour.
Response headers (caching and deprecation)¶
Two cross-cutting HTTP-response concerns are declarative: an
RFC-7234 HTTP cache policy for a type's reads, and a deprecation/sunset signal (the
IETF Deprecation header field plus the RFC-8594 Sunset header). Both are emitted
by one route-scoped kernel.response listener that reads
the resource attribute (falling back to the global json_api.defaults) — you never
mutate the response in an after-hook for these.
Cache headers¶
Declare cache directives on #[AsJsonApiResource(cacheHeaders: …)]. The map keys
are max_age, s_maxage (the shared/CDN lifetime), public/private,
no_cache, must_revalidate, and vary (a list of response-header names added to
Vary). An optional nested operations key overrides them per read shape —
collection, read, related, relationship:
#[AsJsonApiResource(cacheHeaders: [
'max_age' => 60,
'public' => true,
'vary' => ['Accept'],
'operations' => [
'collection' => ['max_age' => 30], // the collection caches for less
],
])]
final class TrackResource extends AbstractResource { /* … */ }
They map onto Cache-Control + Vary and are applied only to a successful
GET — never a write (POST/PATCH/DELETE) and never an error document
(caching either is wrong). A resource that declares no cacheHeaders (and has no
json_api.defaults.cache_headers) gets no Cache-Control at all — unchanged
behaviour. The global default applies to a resource that declares none; a
resource-level value merges over the default directive-by-directive (your
max_age wins, an unset directive inherits the default), and a per-operation
override merges over the resource-level value. An app that set Cache-Control
itself (e.g. in an after-hook) is never clobbered.
Response headers belong to the resource class, not the type name. When two servers serve the same type through different classes, each server emits only its own class's cache, deprecation and sunset headers, and a server whose class declares none gets the global defaults. A class assigned to several servers applies its headers on each.
Deprecation + Sunset¶
Declare a deprecation on #[AsJsonApiResource(deprecation: …, sunset: …,
sunsetLink: …)]. deprecation is true (emit a bare Deprecation: true) or a
date string (Deprecation: <date>); sunset is an HTTP-date (Sunset: <date>);
when sunsetLink is set, a companion Link: <uri>; rel="sunset" is emitted too:
#[AsJsonApiResource(
deprecation: true,
sunset: 'Sat, 31 Dec 2050 23:59:59 GMT',
sunsetLink: 'https://music.example/deprecations/tracks',
)]
final class LegacyTrackResource extends AbstractResource { /* … */ }
The Deprecation header is the IETF Deprecation header field
(draft-ietf-httpapi-deprecation-header); Sunset and the sunset link relation
are RFC 8594. The bundle passes both date values through verbatim, so format
them for whichever draft revision your consumers expect — the latest Deprecation
draft wants a structured-field date such as @1688169599.
Unlike caching, deprecation/sunset ride every response for the type — reads
and writes — because a deprecated endpoint is deprecated regardless of method.
The same json_api.defaults.deprecation / sunset / sunset_link keys supply a
fleet-wide default a resource overrides. An explicit Deprecation/Sunset header
your app already set is never clobbered.
To deprecate some of a type's operations rather than all of it, list them by core
operation name in deprecatedOperations:
#[AsJsonApiResource(
sunset: 'Sat, 31 Dec 2050 23:59:59 GMT',
deprecatedOperations: ['delete', 'fetchRelated.agencies'],
)]
A response from a listed operation carries Deprecation: true, or the date the type or a
default declares, beside the type's Sunset. The type's other operations get only the
Sunset. A custom action declared #[AsJsonApiAction(deprecated: true)] sends the header
the same way. The resource's own deprecation, sunset and deprecatedOperations, and
an action's deprecated, also mark the
OpenAPI document.
Per-server defaults¶
A named server takes the same defaults block under json_api.servers.<name>. It
applies only to that server's responses, which is how you deprecate a whole API
version at once while its successor runs beside it:
json_api:
defaults:
deprecation: true
cache_headers:
max_age: 60
public: true
servers:
v5:
defaults:
sunset: 'Sat, 01 May 2027 00:00:00 GMT'
sunset_link: 'https://music.example/migrating-to-v6'
cache_headers:
max_age: 30
v6: ~
Each header value resolves in this order: the resource's own declaration, then its
server's defaults, then the global json_api.defaults. The merge is key by key, so
in the example every v5 response carries the global Deprecation: true beside the
server's Sunset and sunset Link, while v6 gets only Deprecation: true. A
resource on v5 that declares its own sunset keeps it, and still inherits the
server's sunset_link unless it sets sunsetLink too. Cache directives follow the
same order with their usual merge: reads on v5 cache for 30 seconds and stay public
from the global block. no_cache and must_revalidate switch on at any layer and
can't be switched off by a lower one, and vary lists add up across all three.
The implicit default server has no block of its own: the top-level defaults is
its block, and the fallback for every named server. A server block takes the same
keys and fails the build on the same bad values as the global one, such as a
non-integer max_age or a sunset that isn't a string. The OpenAPI document
describes none of these headers on any server, and the defaults mark nothing in it as
deprecated, so a server block doesn't change it.
Named servers (json_api.servers)¶
The architecture is N-server-capable but single-server optimized. The
top-level base_uri/version define the implicit default server, so most apps
need no servers: block at all. When you genuinely run more than one API surface —
say a public catalog and an internal admin API with a different base URI — declare the
extra surfaces under servers::
json_api:
base_uri: 'https://music.example'
servers:
admin:
base_uri: 'https://admin.music.example/admin'
Each named server inherits the top-level value when its own is omitted — the
admin server above declares only base_uri and inherits version: '1.1'.
output_timezone inherits the same way when it is omitted or null, like base_uri.
To render a server's values in their own zone while the top level sets one, give it
an empty string:
json_api:
output_timezone: UTC
servers:
tokyo:
output_timezone: Asia/Tokyo
legacy:
output_timezone: '' # no conversion on this server
link_objects inherits the same way, so one server can keep bare string links (for a
client that predates link objects, say) while the rest render objects:
reject_read_only_attributes inherits too, so a newer API version can refuse what an
older one silently drops:
That server's OpenAPI document then lists the ATTRIBUTE_WRITE_PROHIBITED error; the
others don't.
openapi_examples overrides json_api.openapi.examples for one server's document, so an
internal API can drop the generated operation examples
while the public one keeps them:
A type shared by several servers (server: ['default', 'admin']) renders in each
server's own zone. Every server builds its own instance of the resource service, so
nothing a server sets on it reaches the others.
Every
declared server (including default) gets one ServerFactory, registered under the
id haddowg.json_api.server_factory.<name>.
Reserved name. A named server may not be literally default — that name
belongs to the implicit top-level server. Declaring it is a build-time
LogicException:
The JSON:API server name "default" is reserved for the implicit server defined by
the top-level base_uri/version; declare other servers under different names.
Configuration only declares servers. The rest of the multi-server story lives on three other pages, cross-linked so they don't drift:
- Assignment — which types join which server — is the
server:argument on the resource attribute (#[AsJsonApiResource(server: 'admin')], or a list for a shared type). See resources. - Route mounting — one per-server import per surface (
resource: admin, under aprefix:) — lives in yourroutes/json_api.yaml. See routing. - End-to-end resolution — how a request reaches its own server's
ServerFactoryand renders that server'sbase_uriin links — is on multi-server and testing.
Optional dependencies¶
The bundle's hard runtime dependencies are minimal (see installation).
Everything beyond the read/write core is opt-in via a suggest dependency. Each one
degrades gracefully when absent — but the degradation differs, and two of them
are silent, so read this table before assuming a capability is active.
| Package | Enables | When absent |
|---|---|---|
doctrine/orm (^2.20 \|\| ^3.2) |
The reference Doctrine provider/persister (doctrine) | No Doctrine path; #[AsJsonApiResource(entity:)] mappings are inert. With doctrine/orm installed, an entity: mapping needs an EntityManagerInterface service (doctrine-bundle) or the build fails. Provide your own data provider. |
symfony/validator |
The constraint bridge (validation) | Declared constraints go unchecked, silently. Each written value's JSON type is still checked. |
symfony/event-dispatcher |
The lifecycle-hook seam (lifecycle hooks) | The per-operation events and resource hook methods are inert — the dispatcher is injected ->nullOnInvalid() and the seam is simply off. |
symfony/security-core + symfony/expression-language |
Declarative resource authorization (authorization) | A security expression on a resource, relation or action fails the container build, as it does without a configured firewall. The documentation-only true/false values still work. |
symfony/doctrine-bridge |
The UniqueEntity entity-level rule |
UniqueEntity cannot be translated. Usually present transitively via doctrine/doctrine-bundle. |
egulias/email-validator |
Strict (RFC 5322) email validation (EmailFormat(strict)) |
Strict silently degrades to Symfony's HTML5 email mode. |
opis/json-schema |
The structural document linter (schema_validation) |
Enabling schema_validation: true without it fails the build. |
symfony/intl |
Sourcing a reference-data type (e.g. countries) from the ICU dataset |
The example app's countries type — a standalone CountrySerializer + CountryProvider, no entity — has no data source. |
The two silent degradations are the ones to internalise: without
symfony/validator, CrudOperationHandler's validator resolves to null and writes
are accepted without checking your constraints; and EmailFormat(strict) quietly
falls back to HTML5 validation without egulias/email-validator. Neither raises an
error — see validation for the full bridge behaviour.
symfony/doctrine-bridge is the subtle one: it ships Symfony's UniqueEntity
constraint and validator that the bundle's UniqueEntity VO translates to, and it is
typically only present transitively through doctrine/doctrine-bundle. The bundle
lists it in its own composer.json suggest so the requirement
is discoverable; the example app depends on it directly. See the UniqueEntity
section of validation.
These suggest entries are declared in the bundle's
composer.json and mirrored in the
example app's composer.json.
Why this page is short¶
Almost nothing in the bundle is configured through json_api:. A resource is
discovered because its service is tagged by autoconfiguration; a custom data provider
shadows Doctrine because it's tagged at a higher priority; a constraint translator
registers because it implements an autoconfigured interface. The tag/priority model —
not config — is how you compose and override behaviour:
- The discovery and capability tags (
RESOURCE_TAG,SERIALIZER_TAG, …) → capability composition. - The data-layer tags (
DATA_PROVIDER_TAG,DATA_PERSISTER_TAG,DOCTRINE_EXTENSION_TAG) and their priority/first-match resolution → the data layer and custom data providers. - The validation tag (
CONSTRAINT_TRANSLATOR_TAG) → validation.
If you find yourself looking for a config key to turn something on, it's almost certainly a tag instead.
Next / See also¶
- Resources and
#[AsJsonApiResource]— including theserver:assignment argument. - Routing — the per-server route import and the operation allow-list.
- Multi-server and testing — end-to-end server resolution.
- Validation — what
symfony/validator(and the optional linter) buys you. - Core server.md and schema-validation.md.