Nelmioapidocbundle: Could not resolve reference when $ref relative path files. "basePath" undefined.

Created on 13 Sep 2017  路  12Comments  路  Source: nelmio/NelmioApiDocBundle

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

Most helpful comment

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.

All 12 comments

@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.

```

  • @SWG\Response(

    • response=200,

    • description="Returns the rewards of an user",

    • @SWG\Schema(

    • type="array",

    • @Model(type=UserConcat::class, groups={"LIST"})

    • )

    • )

      ```

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:
image

Define the schema:
image

Output doc:
image

Output json:
image

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:
image
And this is what i have in my controller:
image

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajaypatelbardoli picture ajaypatelbardoli  路  6Comments

knyk picture knyk  路  6Comments

andydandy80 picture andydandy80  路  4Comments

abidichrak picture abidichrak  路  5Comments

alxfv picture alxfv  路  5Comments