1 回答

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
我找到了解決我的問題的方法。看來 API 平臺(tái)文檔畢竟離答案不遠(yuǎn)了!在資源配置文件中嘗試了一段時(shí)間后,終于決定給這個(gè)services.yaml文件一個(gè)機(jī)會(huì)。我在這個(gè) github 問題上得到了很大幫助。所以,這就是我所做的。
第 1 步 -在services.yaml:
# filters
app.customer_resource.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'firstname': 'partial', 'lastname': 'partial', 'emailAddress': 'partial', 'owner.emailAddress': 'exact' } ]
tags: [ { name: 'api_platform.filter', id: 'customer.search_filter' } ]
autowire: false # required, explained below
autoconfigure: false # required, explained below
注0:在autowire和autoconfigure參數(shù)都在這里需要的,否則你會(huì)得到一個(gè)錯(cuò)誤:
當(dāng)設(shè)置了“parent”時(shí),服務(wù)“app.customer_resource.search_filter”上的屬性“autowire”/“autoconfigure”不能從“_defaults”繼承。將您的子定義移動(dòng)到單獨(dú)的文件或在 [...] 中明確定義此屬性(在資源“[...]”中加載)。
注 1:我注意到這里最重要的元素是“tags”參數(shù)的“id”元素。在我尋找解決方案時(shí),我發(fā)現(xiàn)了,這表明您必須提供過濾器 ID 才能使其工作。在第 2 步中親自查看。vendor/api-platform/core/src/Swagger/Serializer/DocumentationNormalizer::getFilter()
第 2 步 -在您的資源配置文件中(我的在config/resources/customer.yaml)
App\Entity\Customer:
collectionOperations:
get:
filters: ['customer.search_filter']
# ...
我剛剛通過使用(如我所說的)重要過濾器 ID為 GET 收集操作添加了過濾器。所以,這解決了我的問題。但是,如果有人有更好/更簡單的解決方案,我很高興知道。
- 1 回答
- 0 關(guān)注
- 186 瀏覽
添加回答
舉報(bào)