OpenAPITools / OpenAPITools/openapi-generator

[BUG] [C++] [Restbed] Post handler cannot fetch large request Body

Open
#18,404 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I got a generated server with cpp-restbed-generator, and i tried to implement all my endpoints by following this example :

#include "api/PetApi.h"

using namespace org::openapitools::server::api;
using namespace org::openapitools::server::api::PetApiResources;

   
int main() {
    auto service = std::make_shared<restbed::Service>();

    PetsApi petsApi(service);

    petsApi.getPetsResource()->handler_POST_func = [](Pet& pet) {

        return 200; // OK
    };

    auto settings = std::make_shared<restbed::Settings>();
    settings->set_port(8080);

    service->start(settings);
    return 0;
}

I also tried to create my own Resource and override handler_POST.

I extend the Pet model, and when I send a request to the the POST endpoint with a larger parameter, an error occurred :

image

I think I have found out which part of the code trigger this error :

in the generated file PetApi.cpp :

the function extractBodyContent() called in handler_POST_internal :
image

extractBodyContent() :
image

When the request body of the request is short, extractBodyContent() return a valid value containing the request body, but in the case of a request Body more larger, extractBodyContent() return a null value which trigger the error.

Can you help me to fix this bug ?

openapi-generator version

Generator version : 6.6.0

OpenAPI declaration file content or url

https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore.yaml

I just modified the pet model:
image

I changed the name to names in purpose to be able to send larger POST data

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated PetApi.cpp and inspect handler_POST_internal and the extractBodyContent() call shown in the report. Reproduce the issue using the modified petstore.yaml and a large POST body, comparing it with a short body. Done means the generated Restbed POST handler can retrieve and process the larger request body without returning null.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.