Orl*_*ndo 5 php documentation rest symfony nelmioapidocbundle
我将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 syntax is incorrect",
* 404 = "Returned when the page is not found",
* 429 = "Returned when the client sent too many requests during a time period",
* 500 = "Returned when an internal server error occured",
* 501 = "Returned when an unavailable request method is user (GET, POST, DELETE, PUT, ...)",
* 503 = "Returned when the service is unavailable at the moment eg. due to maintenance or overload"
* },
*
* )
Run Code Online (Sandbox Code Playgroud)
AppBundle\Libraries\Core\User\LoginRequest 类:
class LoginRequest implements JsonSerializable
{
/**
* The username.
*
* @var string
*
* @Assert\NotBlank()
* @Assert\Type("string")
*/
public $username;
/**
* The password.
*
* @var string
*
* @Assert\NotBlank()
* @Assert\Type("string")
*/
public $password;
/**
* Defines whether or not to save the refresh token as cooke.
*
* @var bool
*
* @Assert\NotBlank()
* @Assert\Type("bool")
*/
public $rememberPassword;
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getRememberPassword()
{
return $this->rememberPassword;
}
public function setRememberPassword($rememberPassword)
{
$this->rememberPassword = $rememberPassword;
}
public function jsonSerialize()
{
return [
'username' => $this->username,
'password' => $this->password,
'rememberPassword' => $this->rememberPassword
];
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用这个类的描述,例如.用户名:"用户名.",用于密码:"密码".并且对于rememberPassword:"定义是否将刷新令牌保存为cooke."
谢谢您的帮助.
问候奥兰多
NelmioApiDoc 只有少数几个地方为以后生成的视图提取数据。但您可以做的一件事是将描述添加到实体/模型类的表单类型中。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('rememberPassword', CheckboxType::class, array(
'label' => 'input.remember.password',
// description will be passed to table in ApiDoc view
'description' => 'Defines whether or not to save the refresh token as cookie',
));
}
Run Code Online (Sandbox Code Playgroud)
我知道您想知道是否有方法可以自动将更多信息添加到文档中,但只有很少的方法。但如果您想添加其他信息,可以通过注释来完成,如下例所示。
/**
* Lorem ipsum dolor sit amet
*
* #### Example of expected response ####
* [
* {
* "username": "Lorem ipsum dolor sit amet",
* "password": "Lorem ipsum dolor sit amet",
* "rememberPassword": {
* "1": "Lorem ipsum dolor sit amet",
* "2": "Lorem ipsum dolor sit amet",
* "3": "Lorem ipsum dolor sit amet"
* },
* },
* ...
* ]
*
* @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 syntax is incorrect",
* 404 = "Returned when the page is not found",
* 429 = "Returned when the client sent too many requests during a time period",
* 500 = "Returned when an internal server error occured",
* 501 = "Returned when an unavailable request method is user (GET, POST, DELETE, PUT, ...)",
* 503 = "Returned when the service is unavailable at the moment eg. due to maintenance or overload"
* },
*
* )
*
*/
public function getLoginRequestAction()
{
// your code
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
404 次 |
最近记录: |