API Platform 5.1 contains every change shipped in the v5.0.x releases, plus the changes below.
Notes
- JSON:API: a
PATCHorPUTwhosedata.iddoes not match the endpoint now returns409 Conflict, as the specification requires; it used to be applied to the endpoint's resource (#8752). Withjsonapi.strict_resource_typeenabled, a mismatcheddata.typealso returns409onPATCHandPUT, not only onPOST. - JSON:API:
jsonapi.strict_member_names(off by default) exposes theidandtypeproperties asresourceIdandresourceTypeattributes instead of_idand_type, which are not valid member names, and stops renaminglinks,relationshipsandincluded(#8752). - Resource polymorphism: with
serializer.discriminator_mapenabled (Laravel:api-platform.serializer.discriminator_map), the subtypes declared in the serializer#[DiscriminatorMap]of a resource are read, written and documented. An update never changes the subtype: aPUTorPATCHwith another type, or a JSON-LD@typecontradicting the type property, returns a 422. A subtype that is not a resource is named after its class short name in JSON-LD and Hydra: declare it as a resource (e.g.#[ApiResource(operations: [])]) to give it another name ortypes. GraphQL is not supported yet for these resources: the default GraphQL operations are dropped, explicitgraphQlOperationsthrow. Off by default (#8874). - GraphQL: properties typed as a list of
bool,int,floatorstringare now exposed as[Boolean],[Int],[Float]and[String]instead of theIterablescalar; dictionaries and lists of other types still useIterable, so schemas and clients using these fields must be updated (#8619). - JSON Schema: properties typed with a PHPDoc
array{...}shape are now documented as objects withpropertiesandrequiredinstead of a generic object or array (#8767). - JSON Schema:
api_platform.json_schema.generator(off by default, Symfony only) builds JSON Schemas with thesymfony/json-schemacomponent, which must be installed. It is experimental and also covers Hydra schemas and discriminator maps. See the upgrade guide (#8683). - Serializer: the
api_merge_patch_mapsdenormalization context option (off by default) merges the string-keyed map properties of a resource onPATCHinstead of replacing them: anullvalue removes the key and nested maps are merged recursively (#8921). - Mercure:
mercure.resolve_resource_objects(off by default) publishes one update per resource that exposes the persisted object, for example resources usingstateOptions. The resource objects are found byapi_platform.state.resource_object_resolver. The HTTP cache purge listener resolves them without any option (#8868). - OpenAPI: an operation that sets a
uriTemplateand shares a route can opt in to documenting itsuriTemplateas the path instead of the path of the route, with theopenapi_use_uri_templateextra property set totrue. It is off by default (#8920). - Doctrine ORM, Doctrine ODM and Laravel:
DateFiltervalues are now validated by the parameter validation. A request with aDateFilterparameter that has an unknown operator, no operator, an array value, or anullor empty value now returns a 422 with a violation on the parameter, where the value used to be accepted or ignored. The filter schema is a closed object listingafter,before,strictly_afterandstrictly_before(Laravel:eq,gt,lt,gteandlte), and each OpenAPI parameter now declares a scalar schema. This applies whenever parameter validation is enabled (#8927, #8926). - Laravel:
api-platform.swagger_ui.extra_configurationmerges options into the Swagger UI configuration object. It is commented out in the published configuration (#8890). - Swagger UI: scripts running before the
loadevent can push plugins towindow.apiPlatformSwaggerUiPlugins, and Laravel includes the optionalapi-platform::swagger-ui-stylesheetandapi-platform::swagger-ui-javascriptviews when they exist (#8891). - HTTP cache: when
http_cache.invalidationanddoctrine_mongodb_odmare enabled, a purge listener for Doctrine MongoDB ODM is registered, as the ORM one already was (#8733).
Breaking changes
- eb915e2a1 fix(jsonapi)!: drop non-spec type member from error objects (#8732)
- JSON:API error objects no longer carry a top-level
typemember; readlinks.typeinstead (#8732).
Deprecations
- Parameters are now immutable:
Parameter::setValue()andParameters::add(),remove()andsort()are deprecated and will be removed in 6.0. UseParameter::withValue()andParameters::with(),without()andsorted(), which return a new instance. A parameter provider returns the resolvedParameter(or an operation holding it) instead of mutating the one it receives;ParameterProviderInterface::provide()may now returnOperation|Parameter|null. - The
compositeIdentifierargument ofApiResourcehas no effect and is deprecated, it will be removed in 6.0. SetcompositeIdentifieron aLinkinstead (#8695). - The
queryParameterValidateresource and operation option has no effect and is deprecated, it will be removed in 6.0. UsequeryParameterValidationEnabledinstead (#8763).
Features
- 60468f194 feat(jsonschema): generate schemas with symfony/json-schema (#8683)
- a78f351f6 feat(serializer): resource polymorphism (#8884)
- 2ef1b418e feat(metadata): add SubtypeResolver (#8883)
- 2c01934f8 feat(jsonschema): document discriminator maps as oneOf (#8885)
- 7e92ef19b feat(graphql): skip resources with a discriminator map (#8888)
- 68d3133e0 feat(jsonld): expand IRIs in @type discriminators (#8878)
- 05dc10c3b feat(doctrine): add SubtypeFilter to filter on subclass properties (ORM) (#8651)
- d430f9afd feat(symfony): ApiOperation attribute on controllers (#8628)
- 5dd8bcd36 feat(metadata): immutable parameters (#8855)
- de7751eec feat(metadata): add canonicalUriTemplate to resources and HTTP operations (#8479)
- 61b0fc4d8 feat(httpcache): introduce PurgeTagProviderInterface extension point (#7970)
- d4afa5857 feat(symfony,laravel): hook to register Swagger UI plugins (#8891)
- 7412ee884 feat(jsonld): operations as schema.org actions
- 2d692a6f8 feat(jsonld): potentialAction operation option
- 9090a0dbd feat(jsonapi): spec-compliant PATCH conflicts and member names (#8752)
- bcb592abe feat(jsonapi): opt-in strict resource type check on write (#8739)
- 23c4876d1 feat(doctrine): add an input format to DateFilter (#8678)
- 70abf9361 feat(metadata): add ScalarHeaderParameter (#8679)
- 6f77a4d70 feat(openapi): accept Tag objects in operation tags (#8618)
- d067679df feat(hydra): hydra:title from property jsonldContext (#8616)
- 2c956d173 feat(metadata): ResponseHeaderParameter for declaring HTTP response headers (#7875)
- 557623c16 feat(hydra): normalize Hydra\Collection objects (#8539)
- e22e9210e feat(symfony): map ForeignKeyConstraintViolationException to 409 by default (#8548)
- 16fdcd82b feat(openapi): add openapi_use_uri_template for shared routes (#8920)
- b8f4d7e08 feat(serializer): merge-patch string-keyed maps (api_merge_patch_maps) (#8921)
- aeb298249 feat(state): resolve resource objects for purge and Mercure (#8868)
- 6767a7d1a feat(laravel): validate DateFilter values (#8926)
- 0f9a6a075 feat(doctrine): validate DateFilter values (#8927)
- 4c95cfeb1 feat(laravel): swagger_ui.extra_configuration option (#8890)
- b42652b95 feat(httpcache): add doctrine mongodb odm purge listener (#8733)
- 721a90a41 feat(hal): templated item links in the entrypoint (#8795)
- 1d4592b37 feat(symfony): preserve voter reasons for link security denials (#8682)
- 6513bd1d8 feat(jsonschema): describe PHPDoc array shapes as objects (#8767)
- af3437556 feat(graphql): map scalar arrays to typed lists (#8619)
- cec0a65a4 feat(metadata): deprecate the compositeIdentifier argument of ApiResource (#8695)
Bug fixes
- 45dad9480 fix(metadata): match parameter subclasses in Parameters lookups (#8710)
- 2bba68f6c fix(openapi): document array query params once (#8638)
- e3fe5cd57 fix(jsonld): filter @context by serializer groups (#8563)
- e289136ad fix(hydra): document sub-resource operations on parent link (#8876)
- 5cb08494e fix(httpcache): purge once per request (#8869)
- 9438ec1fd fix(jsonld): use json-streamer PropertyValueTransformerInterface on symfony 8.1 (#8784)