Make the docs clearer about models (#1185)

* Make the docs clearer about models

* Fixes
This commit is contained in:
Guilhem N 2018-01-13 13:21:23 +01:00 committed by GitHub
parent 73a5f104d6
commit 4d95dde523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -168,19 +168,29 @@ Use models
As shown in the example above, the bundle provides the ``@Model`` annotation. As shown in the example above, the bundle provides the ``@Model`` annotation.
When you use it, the bundle will deduce your model properties. When you use it, the bundle will deduce your model properties.
.. note::
   A model can be a Symfony form type, a Doctrine ORM entity or a general PHP object.
It has two options: It has two options:
* ``type`` to specify your model's type:: * ``type`` to specify your model's type::
/** /**
* @Model(type=User::class)     * @SWG\Response(
*/     * response=200,
    *     @Model(type=User::class)
    * )
    */
* ``groups`` to specify the serialization groups used to (de)serialize your model:: * ``groups`` to specify the serialization groups used to (de)serialize your model::
/**   /**
* @Model(type=User::class, groups={"non_sensitive_data"})     * @SWG\Response(
*/     * response=200,
    *     @Model(type=User::class, groups={"non_sensitive_data"})
    * )
    */
.. caution:: .. caution::
@ -191,8 +201,8 @@ It has two options:
/** /**
* @SWG\Response( * @SWG\Response(
* response="200",         *   response="200",
* description="Success",         *   description="Success",
* @SWG\Schema(@Model(type=User::class)) * @SWG\Schema(@Model(type=User::class))
* ) * )
*/ */
@ -208,7 +218,7 @@ It has two options:
responses: responses:
200: 200:
schema: schema:
items: { $ref: '#/definitions/MyModel' }                   items: { $ref: '#/definitions/User' }
while you probably expected: while you probably expected:
@ -217,7 +227,7 @@ It has two options:
# ... # ...
responses: responses:
200: 200:
schema: { $ref: '#/definitions/MyModel' }               schema: { $ref: '#/definitions/User' }
To obtain the output you expected, remove the ``@Schema`` annotation:: To obtain the output you expected, remove the ``@Schema`` annotation::
@ -225,10 +235,10 @@ It has two options:
* @SWG\Response( * @SWG\Response(
* response="200", * response="200",
* description="Success", * description="Success",
* @Model(type=MyModel::class)         *   @Model(type=User::class)
* ) * )
*/ */
public function myAction() public function getUserAction()
{ {
} }