0

I try to use the nelmioapidocbundle :

namespace App\Controller;

use App\Entity\User;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Service\UserService;
use Nelmio\ApiDocBundle\Annotation as Doc;
use Symfony\Component\Routing\Annotation\Route;

t works when I use the config description like this

paths:
        /api/login_check:
            post:
                tags:
                    - Login
                description: Login into the api.
                produces:
                    - application/json
                parameters:
                    - name: username
                      description: User to login
                      in: body
                      required: true
                      schema:
                          type: object
                          properties:
                              _username:
                                  type: string
                              _password:
                                  type: string
                responses:
                    '200':
                        description: Login successful
                        schema:
                            type: object
                            properties:
                                token:
                                    type: string

but when I use annotations (with is installed, I can use @Route without any problem, I get this error :

[Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method App\Controller\AuthController::register() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /Sites/symfony/guest/config/routes/../../src/Controller/ (which is being imported from "Sites/symfony/guest/config/routes/annotations.yaml"). Make sure annotations are installed and enabled.

Any idea ?

Altivec
  • 39
  • 1
  • 6
  • Have you **read** that error message? To me, it looks pretty obvious what to do – Nico Haase Jun 02 '20 at 11:09
  • Yes, I am sure annotations are installed and enabled, because I can define new @Route without any problem. Shoud I define special configuration for nelmioapidocbundle in the config/routes/annotations.yaml ? Actually, it has the current configuration : controllers: resource: ../../src/Controller/ type: annotation – Altivec Jun 02 '20 at 11:57
  • That's not what my question should point to: according to the error message, you should have imported `Nelmio\ApiDocBundle\Annotation\ApiDoc` to your controller – Nico Haase Jun 02 '20 at 11:58
  • This change nothing ... Even if I remove apiDoc in the annotations : /** * … * * @Doc\ApiDoc( * resource=true, * description="Get the list of all articles." * ) */ I follow the official documentation on symfony to install, that should be a small thing, but can't find it ... – Altivec Jun 02 '20 at 12:03
  • 1
    Which NelmioApiDocBundle version do you use? If you are using version 3.*, they removed `Nelmio\ApiDocBundle\Annotation\ApiDoc`. https://symfony.com/doc/master/bundles/NelmioApiDocBundle/index.html – Leprechaun Jun 03 '20 at 21:10
  • I'm using the 3.6.1 version, but the symfony document showusage of openapi 3.0 but my version use openapi 2.0 ... I think only 4.x will use openapi3.0 I'm also getting error when using the official documentation... [Semantical Error] The annotation "@OpenApi\Annotations\Response" ... – Altivec Jun 04 '20 at 22:07

0 Answers0