-
|
I was following the documentation on Subresources. All the examples given in the documentation have 1 level of nesting only. It seems, however that multiple Links are also supported. The following resource configuration works for me: #[ApiResource(
uriTemplate: '/foo/{fooId}/bar/{barId}/baz.{_format}',
uriVariables: [
'fooId' => new Link(
fromClass: Foo::class,
toClass: Bar::class,
toProperty: 'foo'
),
'barId' => new Link(
fromClass: Bar::class,
toProperty: 'bar'
),
],
operations: [
new GetCollection(),
]
)]
class Baz { ... }This seems to work. When requesting What I was wondering is, whether I can avoid the bar uriVariable (requesting #[ApiResource(
uriTemplate: '/foo/{fooId}/baz.{_format}',
uriVariables: [
'fooId' => new Link(
fromClass: Foo::class,
toClass: Bar::class,
toProperty: 'foo'
),
'barId' => new Link(
fromClass: Bar::class,
toProperty: 'bar'
),
],
operations: [
new GetCollection(),
]
)]
class Baz { ... }Above configuration returns a "Invalid identifier value or configuration" error in ReadListener. As an alternative, I'm also happy to provide my own DQL directly from the Doctrine Repositories. However, I couldn't find a way to specify a uriVariable that is used for routing only but ignored otherwise from Api-Platform. Either ReadListener is not happy, because I use a uriVariable that is not known to it. Or LinksHandlerTrait compiles an invalid DQL. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Looking at the code of
#[ApiResource(
uriTemplate: '/foo/{fooId}/baz.{_format}',
uriVariables: [
'fooId' => new Link(
fromClass: Foo::class,
expandedValue: "{fooId}"
),
],
operations: [
new GetCollection(),
]
)]
class Baz { ... }The only issue is, that fooId will not appear in OpenAPI documentation as available parameter. I couldn't find any documentation on Is above code supposed to work? Or is this just a glitch? |
Beta Was this translation helpful? Give feedback.
Looking at the code of
LinksHandlerTrait, I figured I can useexpandedValueto haveLinksHandlerTraitignoring the uri variable. Below code seems to work - I don't know why, though 🤣fooIdis properly populated into$context['uri_variables']and I can use aQueryCollectionExtensionInterfaceto filter the Baz collection byfooId:#[ApiResource( uriTemplate: '/foo/{fooId}/baz.{_format}', uriVariables: [ 'fooId' => new Link( fromClass: Foo::class, expandedValue: "{fooId}" ), ], operations: [ new GetCollection(), ] )] class Baz { ... }The only issue is, that fooId will not appear in OpenAPI documentation as available parameter.