我将参数设置为数组,如http://jmsyst.com/libs/serializer/master/reference/annotations中所述
class QuestionAnswer
{
/**
* @JMS\Type("ArrayCollection<Rest\Bundle\Entity\Fixture\QuestionOptions>")
* @Groups({"QuestionAnswer"})
*/
public $question_options_array ;
}
Run Code Online (Sandbox Code Playgroud)
并在另一个类中定义一些选项
class QuestionOptions
{
/**
* @JMS\Type("integer")
* @Groups({"get_option"})
*/
public $question_option_id ;
/**
* @JMS\Type("string")
* @Groups({"post_option"})
*/
public $question_option_description;
}
Run Code Online (Sandbox Code Playgroud)
在@ApiDoc我定义
* input={
* "class" = "Rest\BeautyBundle\Entity\Fixture\ProfileQuestionAnswer",
* "groups"={"QuestionAnswer", "get_option"},
* },
Run Code Online (Sandbox Code Playgroud)
在更新之前它运作良好.但composer update只有"QuestionAnswer"组名称起作用后才能显示QuestionOptions类的所有属性.如何以更新前的方式提交数组中的属性?
我使用注释的input属性@ApiDoc来指定我的api的参数,这些参数是表单的字段.
* @ApiDoc(
* section="User",
* resource=true,
* input={
* "class"="Nik\UserBundle\Form\UserType",
* },
* ....
Run Code Online (Sandbox Code Playgroud)
data_class of form是一个对属性进行约束验证的实体.
我希望nelmio api doc将参数格式指定为实体的验证约束,但格式为空.
如何在nelmio ApiDocBundle中指定参数格式?
编辑:也许我写了一个糟糕的问题.
我们可以为input&指定解析器output,如果我们没有为这些指定解析器,它会为input&调用所有解析器output,然后调用所有解析器UserType.
nelmio有一个名为ValidationParser的解析器,它有一个名为parseConstraint的方法,format用于输入和输出,但是这个方法没有为我的文档调用,为什么?
我将NelmioApiDocBundle与PHP框架Symfony3一起用于REST API.我想在/ api/doc页面中显示我的参数说明.如果不手动添加参数,这可能吗?我想从输入/输出类导入它.
这就是我的文档的外观:
这是我的@ApiDoc控制器动作(/ api/user/login)生成文档:
* @ApiDoc(
* section = "user",
* resource = true,
* description = "Checks the user credentials and returns an authentication & refresh token if they are correct",
* input = { "class" = "AppBundle\Libraries\Core\User\LoginRequest", "name" = "" },
* output = { "class" = "AppBundle\Libraries\Core\User\LoginResponse", "name" = "" },
* statusCodes = {
* 200 = "Returned when successful",
* 400 = "Returned when request …Run Code Online (Sandbox Code Playgroud) 我目前正在使用 NelmioApiDocBundle,我对它还不是很熟悉。我正在编写的 API 必须提供更改特定用户密码的途径。文档应说明,更改密码既需要旧密码,也需要新密码。因为我没有发现之间的区别的解释Requirements和Parameters,我想首先是用于从路由数据,而后者用于API调用本身。
归档此类文档的第一次尝试是实现一个简单的模型,然后 JMSSerializerBundle 会自动转换该模型:
class ChangePasswordParam
{
/**
* @Type("string")
* @var string
*/
protected $oldPassword;
/**
* @Type("string")
* @var string
*/
protected $newPassword;
}
Run Code Online (Sandbox Code Playgroud)
Controller 通过这个 action 方法接受 API 调用:
/**
* Changes the password for a specific user.
*
* @Post("/{username}/changepassword")
* @View()
* @ApiDoc(
* description="Changes the password of a User",
* input="FQCN\ChangePasswordParam"
* )
*
* @param string $username
* @param ChangePasswordParam $passwordParam
*
* @return Response
*/ …Run Code Online (Sandbox Code Playgroud) php symfony fosrestbundle jmsserializerbundle nelmioapidocbundle
我的 Symfony 4 应用程序中有一个 API 端点,我想用 NelmioApiDocBundle 和 Swagger 记录它。端点将 JSON 作为请求数据,并返回一些自定义 JSON 作为响应。如何使用注释将它们的示例添加到文档中?我在文档页面上看不到任何示例,只有描述。
/**
* @Route("/order/import", methods={"POST"}, name="order_import")
* @OA\RequestBody (
* request="order",
* description="Order data in JSON format",
* @OA\Schema(
* type="object",
* example={"hello": "world"}
* )
* )
* @OA\Response(
* response=200,
* description="Returns the JSON data after import",
* @OA\Schema(
* type="object",
* example={"foo": "bar"}
* )
* )
* @OA\Tag(name="import")
Run Code Online (Sandbox Code Playgroud) 我已经安装了NelmioApiDocBundle用于Symfony的我新的面向API项目,我无法摆脱的.{_format},这束添加到我的端点网址后缀.
这是它的样子:
我的API不支持_formatas后缀.它支持将其作为查询参数或请求标头.正因为如此,如果我尝试从NelmioApiDocBundle沙箱做这个端点的请求时,它得到一个404错误响应.
这是我目前关于nelmio的config.yml部分:
yml
nelmio_api_doc:
name: My API doc
sandbox:
enabled: true
endpoint: null
accept_type: application/json
body_format:
formats: null
default_format: json
request_format:
formats:
json: application/json
xml: null
method: accept_header
default_format: json
authentication:
name: bearer
delivery: query
cache:
enabled: false
file: '%kernel.cache_dir%/api-doc.cache'
我的注释是:
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Schema (
* type="object",
* @OA\Property(property="status", required=true, description="EventStatus", type="string"),
* @OA\Property(property="comment", required=false, description="Change Status Comment", type="string"),
* example={
* "status": "test status",
* "comment": "test comment"
* }
* )
* )
* )
Run Code Online (Sandbox Code Playgroud)
我尝试添加一个“示例”键,但没有成功。

我有一个这样的 DTO:
# AppBundle\DTO
/**
* @OA\Schema(
* schema="ProductDto",
* type="object",
* required={
* "foo",
* "bar",
* "baz",
* },
* )
*/
class ProductDto
{
/**
* @OA\Property(description="foo bar baz")
* @var string|null
*/
private $foo;
...
}
Run Code Online (Sandbox Code Playgroud)
我试图在我的控制器中引用这个 DTO,但似乎这个文件没有被解析。
# AppBundle\Controller\Api\v1
class ProductController {
...
/**
* @OA\Post(
* @OA\RequestBody(
* required=true,
* content={
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="object",
* ref="#/components/schemas/ProductDto",
* ),
* ),
* }
* ),
* )
*/
public function …Run Code Online (Sandbox Code Playgroud) 是否可以删除 NelmioApiDocBundle 基于 Web 的输出中显示的徽标标头?如果是这样,怎么办?
我想/api/doc在现有网站中包含此端点的输出(如果您使用默认设置)。但是,该网站已经有一个标题,恕我直言,添加第二个标题将是一个糟糕的用户体验。但我在文档中找不到任何地方描述如何排除这个 90 年代风格的网页设计。
我在下面提供了默认配置的屏幕截图,这是我在 Insomnia 等工具中查看文档时得到的。正如您所看到的,绿色标题在滚动时覆盖了页面。
我正在尝试将 NelmioApiDocBundle 用于 Symfony 3.4 项目 API 文档,同时还尝试从 OAuth 2 授权开始进行项目 API 访问。
到目前为止,我已经按照本教程了解如何让 FOSOAuthServerBundle 工作。到目前为止,我可以 1.) 使用命令行命令创建客户端:
php bin/console fos:oauth-server:create-client --redirect-uri="___" --grant-type="authorization_code" --grant-type="password" --grant-type="refresh_token" - -grant-type="token" --grant-type="client_credentials"
2.) 我还可以通过访问服务器上的此 url 手动获取访问令牌
3.) 我可以使用令牌来访问 Symfony 项目中需要 OAuth 访问的区域,方法是将令牌包含在 GET 参数中
但是,在 NelmioApiDocBundle 授权中,我无法完成此工作。这是一个屏幕截图:
如果输入我的 client_id 和密钥,它将按预期进入登录页面。我可以输入我的登录信息,然后按预期进入“批准”或“拒绝”页面。此时,如果我单击“批准”或“拒绝”,它会尝试使用http://localhost:3200/oauth2-redirect.html的“redirect_uri” 。无论我做什么,我都无法更改重定向 URI。
如何获得正确的重定向 URI?
symfony ×9
php ×4
openapi ×2
rest ×2
doctrine-orm ×1
swagger ×1
swagger-php ×1
swagger-ui ×1
symfony-2.7 ×1
symfony-3.4 ×1