【发布时间】:2018-04-26 13:33:15
【问题描述】:
我正在 Symfony 中创建小型 API,并且正在使用 Api Platform。
在/src/BooksBundle/Resources/config/api_resources/resources.xml 我将路径设置为:
<collectionOperations>
<collectionOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="path">/{shop}/books</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>books_list</attribute>
<attribute>list</attribute>
</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
在swagger.yml,我已经设置了路径和参数
paths:
/api/{shop}/books:
get:
tags:
- Book
operationId: getBookCollection
produces:
- application/json
- application/ld+json
- text/html
summary: Retrieves the collection of Book resources.
responses:
'200':
description: Book collection response
schema:
type: array
items:
$ref: '#/definitions/Book-book_list'
'401':
description: Unauthorized
parameters:
- name: title
in: query
required: false
type: string
- name: shop
in: path
required: true
type: string
我的路线例如:127.0.0.1/api/shopName/books?title=sometitle
作为回应,我收到此错误:Unable to generate an IRI for "BookBundle\Entity\Book".
我调查了异常,消息是:
Some mandatory parameters are missing ("shop") to generate a URL for route "api_books_get_collection".
所以我需要一种通过 API 平台中的路径发送参数的方法,由于某种原因,这不起作用。
仅供参考,为什么我认为这是配置问题。我的参数 Shop in entity Book,有 getter 和 setter,如果我在实体中输入固定值,从配置和路由中删除参数,url 127.0.0.1/api/books?title=sometitle 完美运行,我得到完整的 Hydra Json 响应。
【问题讨论】:
标签: symfony swagger api-platform.com