I've actually a problem with $ref when displaying the swagger ui:
Resolver error at paths./private/api/v1/users.get.responses.200.schema.$ref
Could not resolve reference: ../../Entity/User.php#/definitions/User
/Controller/PrivateApi/UserController.php
/**
* @Route("/v1/users")
*
*/
class UserController extends BaseController
{
/**
* List users.
*
* @Route("", methods={"GET"})
* @SWG\Response(
* response=200,
* description="Returns the list of users",
* @SWG\Schema(ref="../../Entity/User.php#/definitions/User")
* )
* @SWG\Parameter(
* name="order",
* in="query",
* type="string",
* description="The field used to order users"
* )
* @SWG\Tag(name="Users")
*/
public function getAction(Request $request, ParamFetcherInterface $paramFetcher)
{
.......
}
}
/Entity/User.php
/**
*
* @SWG\Definition(definition="User", type="object")
*
*/
class User
{
/**
* @var string
*
* @ORM\Column()
*
* @Serializer\Expose
* @Serializer\Groups({"UPDATE", "CREATE", "SHOW", "LIST"})
*
* @SWG\Property()
*
*/
private $name;
.....
}
/**
* @SWG\Definition(
* definition="UserFull",
* type="object",
* allOf={
* @SWG\Schema(ref="#/definitions/User"),
* @SWG\Schema(
* required={"name"},
* @SWG\Property(property="uuid", format="int64", type="integer")
* )
* }
* )
*/
config.yml:
# Nelmio API Doc (swagger)
nelmio_api_doc:
models:
use_jms: true
routes:
path_patterns: # an array of regexps
- ^/api
- ^/public
- ^/private
documentation:
basePath: /
info:
title: ''
description: '',
version: 1.0
Thanks
@SWG\Definition is not supported by this bundle, that's why we provide @Model.
Ok, so it's not possible to add custom model ? not an entity linked with database.
Sometimes, the controller get data from many entities and make new data model object with new datas.
```
But I can not expose the model to swagger. The model on the swagger-ui is empty.
We could provide a config option to configure parameters using @Definition (by looking only in some folders) or you could just define your models in swagger.documentation.
The model on the swagger-ui is empty.
If you're using the JMS serializer check that you correctly configured your model parameters exposition.
Is it possible to combine definitions using the @Model annotation?
see example here: https://github.com/zircote/swagger-php/issues/243#issuecomment-141102541
If not, we really need @SWG\Definition support in this bundle.
My solution:
Define the definition in config.yml:

Define the schema:

Output doc:

Output json:

Thanks @zhanghuanchong.
I came up with the same solution :)
Still, @SWG\Definition would be a much neater solution.
A partial @Definition support will be there soon (https://github.com/nelmio/NelmioApiDocBundle/pull/1151), awaiting PRs to have a more complete support :)
@zhanghuanchong (or @gijsstegehuis) I've tried to use your solution but without any success :cry: .
This is what i have in config.yml:

And this is what i have in my controller:

Could you please provide more info on how to do it for objects?
Edit:
Downgrade zircote/swagger-php to 2.0.10 and it will work.
@devrck looks like there's a typo in your code:
Replacing $/definitions with #definitions should make it work.
@gijsstegehuis yes it was a typo but that was not the solution. The problem was with the version of zircote/swagger-php and I downgraded it to 2.0.10 for this to work.
@devrck https://github.com/nelmio/NelmioApiDocBundle/pull/1232 should fix your issue (and the related bc break in zircote/swagger-php).
Closing as #1232 is merged.
Most helpful comment
Is it possible to combine definitions using the
@Modelannotation?see example here: https://github.com/zircote/swagger-php/issues/243#issuecomment-141102541
If not, we really need
@SWG\Definitionsupport in this bundle.