1

I am using OpenAPI generator to generate Restbed C++ API server. For some reason, generated method GET_handler_internal contains code where resultObject never gets parsed into a json string, and the result is empty. I can see it both in my project and in OpenAPI examples.

void PetApiPetFindByStatusResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
{

...

std::vector<std::shared_ptr<Pet>> resultObject = std::vector<std::shared_ptr<Pet>>();

...

if (status_code == 200) {

    const constexpr auto contentType = "application/json";
    //I want to return the result here but it would never happen since we are not using resultObject anywhere 
    returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
    return;
  }
}

Full code can be seen here.

Could the reason be in the incorrect OpenAPI spec file? Here is .json that I use:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "My API"
  },
  "paths": {
    "/myobject": {
      "get": {
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MyObject"
                  }
                }
              }
            }
          },
          "default": {
            "description": "unexpected error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "prop1": {
            "type": "string"
          },
          "prop2": {
            "type": "number"
          }
        }
      }
    }
  }
}
cornhedgehog
  • 85
  • 1
  • 5
  • 2
    Your OpenAPI file is correct. This looks like an issue with the OpenAPI Generator. Report it here: https://github.com/OpenAPITools/openapi-generator/issues – Helen Feb 12 '22 at 12:11

0 Answers0