Skip to content

Commit

Permalink
Fix missing HTTP methods in generated restbed C++ code
Browse files Browse the repository at this point in the history
There was a wrong handling of "x-codegen-other-methods".

Change-Id: If6526d2672434beb5ebb0871d84cb80d84c34c38
  • Loading branch information
LukasWoodtli committed Oct 6, 2021
1 parent cce9999 commit e063d48
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,14 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
if (!foundInNewList) {
if (op1.path.equals(op.path)) {
foundInNewList = true;
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) op1.vendorExtensions.get("x-codegen-otherMethods");
final String X_CODEGEN_OTHER_METHODS = "x-codegen-other-methods";
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) op1.vendorExtensions.get(X_CODEGEN_OTHER_METHODS);
if (currentOtherMethodList == null) {
currentOtherMethodList = new ArrayList<CodegenOperation>();
}
op.operationIdCamelCase = op1.operationIdCamelCase;
currentOtherMethodList.add(op);
op1.vendorExtensions.put("x-codegen-other-methods", currentOtherMethodList);
op1.vendorExtensions.put(X_CODEGEN_OTHER_METHODS, currentOtherMethodList);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.0-SNAPSHOT
unset
58 changes: 57 additions & 1 deletion samples/server/petstore/cpp-restbed/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -247,6 +247,9 @@ PetApiPetPetIdResource::PetApiPetPetIdResource(const std::string& context /* = "
this->set_method_handler("DELETE",
std::bind(&PetApiPetPetIdResource::handler_DELETE_internal, this,
std::placeholders::_1));
this->set_method_handler("GET",
std::bind(&PetApiPetPetIdResource::handler_GET_internal, this,
std::placeholders::_1));
this->set_method_handler("POST",
std::bind(&PetApiPetPetIdResource::handler_POST_internal, this,
std::placeholders::_1));
Expand Down Expand Up @@ -323,6 +326,54 @@ void PetApiPetPetIdResource::handler_DELETE_internal(const std::shared_ptr<restb
defaultSessionClose(session, status_code, result);
}

// x-extension
void PetApiPetPetIdResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {

const auto request = session->get_request();

// Getting the path params
const int64_t petId = getPathParam_petId_x_extension(request);


int status_code = 500;
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
std::string result = "";

try {
std::tie(status_code, resultObject) =
handler_GET(petId);
}
catch(const PetApiException& e) {
std::tie(status_code, result) = handlePetApiException(e);
}
catch(const std::exception& e) {
std::tie(status_code, result) = handleStdException(e);
}
catch(...) {
std::tie(status_code, result) = handleUnspecifiedException();
}

if (status_code == 200) {
result = resultObject->toJsonString();

const constexpr auto contentType = "application/json";
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
return;
}
if (status_code == 400) {

const constexpr auto contentType = "text/plain";
returnResponse(session, 400, result.empty() ? "Invalid ID supplied" : result, contentType);
return;
}
if (status_code == 404) {

const constexpr auto contentType = "text/plain";
returnResponse(session, 404, result.empty() ? "Pet not found" : result, contentType);
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void PetApiPetPetIdResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) {

Expand Down Expand Up @@ -364,6 +415,11 @@ int PetApiPetPetIdResource::handler_DELETE(
throw PetApiException(501, "Not implemented");
}

std::pair<int, std::shared_ptr<Pet>> PetApiPetPetIdResource::handler_GET(
int64_t const & petId)
{
throw PetApiException(501, "Not implemented");
}
int PetApiPetPetIdResource::handler_POST(
int64_t const & petId, std::string const & name, std::string const & status)
{
Expand Down
9 changes: 8 additions & 1 deletion samples/server/petstore/cpp-restbed/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -128,6 +128,8 @@ class PetApiPetPetIdResource: public restbed::Resource
virtual int handler_DELETE(
int64_t const & petId, std::string const & apiKey);

virtual std::pair<int, std::shared_ptr<Pet>> handler_GET(
int64_t const & petId);
virtual int handler_POST(
int64_t const & petId, std::string const & name, std::string const & status);

Expand All @@ -149,6 +151,10 @@ class PetApiPetPetIdResource: public restbed::Resource
}


virtual int64_t getPathParam_petId_x_extension(const std::shared_ptr<const restbed::Request>& request)
{
return request->get_path_parameter("petId", 0L);
}
virtual int64_t getPathParam_petId_x_extension(const std::shared_ptr<const restbed::Request>& request)
{
return request->get_path_parameter("petId", 0L);
Expand All @@ -169,6 +175,7 @@ class PetApiPetPetIdResource: public restbed::Resource

private:
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
};

Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
58 changes: 57 additions & 1 deletion samples/server/petstore/cpp-restbed/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -390,6 +390,9 @@ UserApiUserUsernameResource::UserApiUserUsernameResource(const std::string& cont
this->set_method_handler("DELETE",
std::bind(&UserApiUserUsernameResource::handler_DELETE_internal, this,
std::placeholders::_1));
this->set_method_handler("GET",
std::bind(&UserApiUserUsernameResource::handler_GET_internal, this,
std::placeholders::_1));
this->set_method_handler("PUT",
std::bind(&UserApiUserUsernameResource::handler_PUT_internal, this,
std::placeholders::_1));
Expand Down Expand Up @@ -470,6 +473,54 @@ void UserApiUserUsernameResource::handler_DELETE_internal(const std::shared_ptr<
defaultSessionClose(session, status_code, result);
}

// x-extension
void UserApiUserUsernameResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {

const auto request = session->get_request();

// Getting the path params
const std::string username = getPathParam_username_x_extension(request);


int status_code = 500;
std::shared_ptr<User> resultObject = std::make_shared<User>();
std::string result = "";

try {
std::tie(status_code, resultObject) =
handler_GET(username);
}
catch(const UserApiException& e) {
std::tie(status_code, result) = handleUserApiException(e);
}
catch(const std::exception& e) {
std::tie(status_code, result) = handleStdException(e);
}
catch(...) {
std::tie(status_code, result) = handleUnspecifiedException();
}

if (status_code == 200) {
result = resultObject->toJsonString();

const constexpr auto contentType = "application/json";
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
return;
}
if (status_code == 400) {

const constexpr auto contentType = "text/plain";
returnResponse(session, 400, result.empty() ? "Invalid username supplied" : result, contentType);
return;
}
if (status_code == 404) {

const constexpr auto contentType = "text/plain";
returnResponse(session, 404, result.empty() ? "User not found" : result, contentType);
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void UserApiUserUsernameResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {

Expand Down Expand Up @@ -522,6 +573,11 @@ int UserApiUserUsernameResource::handler_DELETE(
throw UserApiException(501, "Not implemented");
}

std::pair<int, std::shared_ptr<User>> UserApiUserUsernameResource::handler_GET(
std::string const & username)
{
throw UserApiException(501, "Not implemented");
}
int UserApiUserUsernameResource::handler_PUT(
std::string const & username, std::shared_ptr<User> const & body)
{
Expand Down
9 changes: 8 additions & 1 deletion samples/server/petstore/cpp-restbed/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -221,6 +221,8 @@ class UserApiUserUsernameResource: public restbed::Resource
virtual int handler_DELETE(
std::string const & username);

virtual std::pair<int, std::shared_ptr<User>> handler_GET(
std::string const & username);
virtual int handler_PUT(
std::string const & username, std::shared_ptr<User> const & body);

Expand All @@ -237,6 +239,10 @@ class UserApiUserUsernameResource: public restbed::Resource
}


virtual std::string getPathParam_username_x_extension(const std::shared_ptr<const restbed::Request>& request)
{
return request->get_path_parameter("username", "");
}
virtual std::string getPathParam_username_x_extension(const std::shared_ptr<const restbed::Request>& request)
{
return request->get_path_parameter("username", "");
Expand All @@ -257,6 +263,7 @@ class UserApiUserUsernameResource: public restbed::Resource

private:
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
void handler_PUT_internal(const std::shared_ptr<restbed::Session> session);
};

Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/ApiResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Category.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Order.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/cpp-restbed/model/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down

0 comments on commit e063d48

Please sign in to comment.