nelmio / NelmioApiDocBundle

Generates documentation for your REST API from annotations
MIT License
2.23k stars 835 forks source link

Path Parameter not showing if Entity implements iterface #1620

Closed Stefanobosio closed 4 years ago

Stefanobosio commented 4 years ago

Hello, I'm using FosRestBundle automatic enpoint's nomenclature. I noticed that, if a GET endpoint has a parameter reflecting an Entity that implements an interface, the path parameter is not shown in the doc's endpoint.

My setup is:

"symfony" 4.4.7 "nelmio/api-doc-bundle 3.6.1 "friendsofsymfony/rest-bundle" 2.7.1

What i expect in api/doc page: /api/page-data/{pageData}

What's shown: /api/page-data

No parameters at all are shown in the endpoint documentation even when i explode the endpoint.

How to reproduce:

src/Entity/PageData.php class PageData implements WhateverInterface { ... }

src/Controller/TestController.php

 /**
 * @SWG\Get(
 *     summary="Page",
 *     description="Get page",
 *     @SWG\Response(
 *         response=200,
 *         description="Get page",
 *         @Model(type=PageData::class)
 *     )
 * )
 *
 * @param PageData $pageData
 *
 * @return \Symfony\Component\HttpFoundation\Response
 */
public function getAction(PageData $pageData) {

    return $this->serialize($pageData);
}

If i force the parameter in this way i can see the parameter when exploding the documentation but the url always remains /api/page-data

I can get the result i want only if i explicitly put this annotation:

* @Rest\Route("/page-data/{pageData}")

but i want to use automatic routing from FosRestBundle.

Is there a way I can have the automatic route parameter?

Thank you

GuilhemN commented 4 years ago

Are you sure FOSRestBundle correctly configures your route as /api/page-data/{pageData}?

It ignores several classes by default (see the list) and doesn't add them as path parameters so this may explain your issue if you extend from one of these classes.

Stefanobosio commented 4 years ago

Hello Guilhem, yes you're right! I tried a couple to interface and unfortunately both of them were on that list. I couldn't find any information about this in the documentation, thank you very much for the tip!