Add support for responses with no message-body

This commit is contained in:
Jeremy Guinn 2021-11-26 15:11:50 -07:00
parent b0bf4c0e71
commit 150b469fbc
3 changed files with 15 additions and 12 deletions

View File

@ -31,6 +31,7 @@ ENDPOINT_INFO(createUser) {
info->summary = "Create new User"; info->summary = "Create new User";
info->addConsumes<UserDto>("application/json"); info->addConsumes<UserDto>("application/json");
info->addResponse<UserDto>(Status::CODE_200, "application/json"); info->addResponse<UserDto>(Status::CODE_200, "application/json");
info->addResponse(Status::CODE_500);
} }
ENDPOINT("POST", "demo/api/users", createUser, ENDPOINT("POST", "demo/api/users", createUser,
BODY_DTO(UserDto, userDto)) { BODY_DTO(UserDto, userDto)) {

View File

@ -340,30 +340,31 @@ oatpp::Fields<Object<oas3::OperationResponse>> Generator::generateResponses(cons
for(auto& hint : endpointInfo.responses) { for(auto& hint : endpointInfo.responses) {
auto mediaType = oas3::MediaTypeObject::createShared(); auto response = oas3::OperationResponse::createShared();
mediaType->schema = generateSchemaForType(hint.second.schema, linkSchema, usedTypes);
if(hint.second.schema != nullptr) {
auto mediaType = oas3::MediaTypeObject::createShared();
mediaType->schema = generateSchemaForType(hint.second.schema, linkSchema, usedTypes);
for(auto& ex : hint.second.examples) {
mediaType->addExample(ex.first, ex.second);
}
response->content = {};
response->content[hint.second.contentType] = mediaType;
for(auto& ex : hint.second.examples) {
mediaType->addExample(ex.first, ex.second);
} }
auto response = oas3::OperationResponse::createShared();
response->description = hint.second.description.get() == nullptr ? hint.first.description : hint.second.description; response->description = hint.second.description.get() == nullptr ? hint.first.description : hint.second.description;
response->content = {};
response->content[hint.second.contentType] = mediaType;
responses[oatpp::utils::conversion::int32ToStr(hint.first.code)] = response; responses[oatpp::utils::conversion::int32ToStr(hint.first.code)] = response;
} }
} else { } else {
auto mediaType = oas3::MediaTypeObject::createShared();
mediaType->schema = generateSchemaForType(oatpp::String::Class::getType(), linkSchema, usedTypes);
auto response = oas3::OperationResponse::createShared(); auto response = oas3::OperationResponse::createShared();
response->description = "success"; response->description = "success";
response->content = {};
response->content["text/plain"] = mediaType;
responses["200"] = response; responses["200"] = response;
} }

View File

@ -252,6 +252,7 @@ public:
info->summary = "Delete User by userId"; info->summary = "Delete User by userId";
info->addResponse<String>(Status::CODE_200, "text/plain"); info->addResponse<String>(Status::CODE_200, "text/plain");
info->addResponse<String>(Status::CODE_404, "text/plain"); info->addResponse<String>(Status::CODE_404, "text/plain");
info->addResponse(Status::CODE_500);
} }
ENDPOINT("DELETE", "demo/api/users/{userId}", deleteUser, ENDPOINT("DELETE", "demo/api/users/{userId}", deleteUser,
PATH(Int32, userId)) { PATH(Int32, userId)) {