Git Product home page Git Product logo

Comments (10)

DjordyKoert avatar DjordyKoert commented on June 10, 2024 1

Yes correct. I will try and find some time somewhere soon to see if I can fix this. If I manage to fix this then a patch will be released for this most likely.

from nelmioapidocbundle.

DjordyKoert avatar DjordyKoert commented on June 10, 2024 1

Good news, I managed to fix it in https://github.com/nelmio/NelmioApiDocBundle/releases/tag/v4.19.3 😄

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Installing the specific 4.17.* version via composer seems to solve the problem, so it must be a recent update:

{
    ...
    "require": {
        ...
        "nelmio/api-doc-bundle": "4.17.*",
        ...
    },
    ...
}
Lock file operations: 0 installs, 1 update, 0 removals
  - Downgrading nelmio/api-doc-bundle (v4.19.2 => v4.18.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading nelmio/api-doc-bundle (v4.18.3)
  - Downgrading nelmio/api-doc-bundle (v4.19.2 => v4.18.3): Extracting archive
Lock file operations: 0 installs, 1 update, 0 removals
  - Downgrading nelmio/api-doc-bundle (v4.18.3 => v4.17.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downloading nelmio/api-doc-bundle (v4.17.1)
  - Downgrading nelmio/api-doc-bundle (v4.18.3 => v4.17.1): Extracting archive

from nelmioapidocbundle.

DjordyKoert avatar DjordyKoert commented on June 10, 2024

Could you share how your CreateUserController __invoke method looks? I assume you are using Symfony's MapRequestPayload attribute there, which I think is causing the issue.

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Yes, it is a Symfony project, and I am using the MapRequestPayload attribute to map the JSON key-value pairs after built-in validation.

The ContentType::APPLICATION_JSON constant equals to application/json.

The Controller's __invoke method has the following attributes (each OA\MediaType belongs to its own OA\Response with different status codes, as you can see):

    #[Route(path: '/api/v3/users', name: 'api_v3_users_create', methods: [Request::METHOD_POST])]
    #[Nelmio\Security(name: null)]
    #[OA\RequestBody(
        content: new OA\MediaType(mediaType: ContentType::APPLICATION_JSON, schema: new OA\Schema(
            ref: new Nelmio\Model(type: CreateUserRequestDto::class),
        )),
    )]
    #[OA\Response(
        response: Response::HTTP_CREATED,
        description: 'Created. New entity created successfully',
        content: new OA\MediaType(mediaType: ContentType::APPLICATION_JSON, schema: new OA\Schema(
            ref: new Nelmio\Model(type: UserEntity::class, groups: ['AtTag', 'MyUserData']),
        )),
    )]
    #[OA\Response(
        response: Response::HTTP_UNSUPPORTED_MEDIA_TYPE,
        description: 'Unsupported Media Type. Expected "Content-Type: application/json" header not provided',
        content: new OA\MediaType(mediaType: ContentType::APPLICATION_JSON, schema: new OA\Schema(properties: [
            new OA\Property(property: 'code', type: 'integer', example: Response::HTTP_UNSUPPORTED_MEDIA_TYPE),
            new OA\Property(property: 'error', type: 'string', example: 'Unsupported Media Type'),
            new OA\Property(property: 'message', type: 'string'),
        ])),
    )]
    #[OA\Response(
        response: Response::HTTP_UNPROCESSABLE_ENTITY,
        description: 'Unprocessable Content. The provided JSON Payload is invalid',
        content: new OA\MediaType(mediaType: ContentType::APPLICATION_JSON, schema: new OA\Schema(properties: [
            new OA\Property(property: 'code', type: 'integer', example: Response::HTTP_UNPROCESSABLE_ENTITY),
            new OA\Property(property: 'error', type: 'string', example: 'Unprocessable Content'),
            new OA\Property(property: 'message', type: 'string'),
        ])),
    )]
    public function __invoke(#[MapRequestPayload] CreateUserRequestDto $requestDTO): JsonResponse

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Hey, @DjordyKoert,

I wondered if the attributes I added in my last comment were helpful. I'm not pushing or rushing for an update (in the end, this is an open-source repo), but it would be nice to get an update, if any, or in case I could provide more details.

Thanks,

from nelmioapidocbundle.

DjordyKoert avatar DjordyKoert commented on June 10, 2024

Hey @DavidGarciaCat sorry for not responding 😅

The information you provided is plenty because I am pretty sure that the issue is caused because of the #[MapRequestPayload] attribute which Nelmio attempts to describe for you.

I think the quick-fix on your end could be to remove the usage #[OA\RequestBody] attribute (or remove the content: param in case you still want to provide a description or something similair for you request body) because. It will still generate a valid api documentation for you endpoint which includes the request body for your endpoint.

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Thanks for the quick response, @DjordyKoert,

If I understood you correctly, this would be a temporary fix to upgrade the bundle and keep rendering the documentation. Still, another minor/patch release will be necessary to fix the exception - am I right here?

Once again, thanks for the quick response.

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Much appreciated for the update - enjoy the rest of your week!

from nelmioapidocbundle.

DavidGarciaCat avatar DavidGarciaCat commented on June 10, 2024

Thanks for the update, @DjordyKoert - Enjoy the rest of your week!

from nelmioapidocbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.