mirror of
https://github.com/oatpp/oatpp-swagger.git
synced 2024-12-15 07:30:01 +08:00
Add support for responses with no message-body
This commit is contained in:
parent
b0bf4c0e71
commit
150b469fbc
@ -31,6 +31,7 @@ ENDPOINT_INFO(createUser) {
|
||||
info->summary = "Create new User";
|
||||
info->addConsumes<UserDto>("application/json");
|
||||
info->addResponse<UserDto>(Status::CODE_200, "application/json");
|
||||
info->addResponse(Status::CODE_500);
|
||||
}
|
||||
ENDPOINT("POST", "demo/api/users", createUser,
|
||||
BODY_DTO(UserDto, userDto)) {
|
||||
|
@ -340,30 +340,31 @@ oatpp::Fields<Object<oas3::OperationResponse>> Generator::generateResponses(cons
|
||||
|
||||
for(auto& hint : endpointInfo.responses) {
|
||||
|
||||
auto mediaType = oas3::MediaTypeObject::createShared();
|
||||
mediaType->schema = generateSchemaForType(hint.second.schema, linkSchema, usedTypes);
|
||||
auto response = oas3::OperationResponse::createShared();
|
||||
|
||||
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->content = {};
|
||||
response->content[hint.second.contentType] = mediaType;
|
||||
responses[oatpp::utils::conversion::int32ToStr(hint.first.code)] = response;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
auto mediaType = oas3::MediaTypeObject::createShared();
|
||||
mediaType->schema = generateSchemaForType(oatpp::String::Class::getType(), linkSchema, usedTypes);
|
||||
|
||||
auto response = oas3::OperationResponse::createShared();
|
||||
response->description = "success";
|
||||
response->content = {};
|
||||
response->content["text/plain"] = mediaType;
|
||||
responses["200"] = response;
|
||||
|
||||
}
|
||||
|
@ -252,6 +252,7 @@ public:
|
||||
info->summary = "Delete User by userId";
|
||||
info->addResponse<String>(Status::CODE_200, "text/plain");
|
||||
info->addResponse<String>(Status::CODE_404, "text/plain");
|
||||
info->addResponse(Status::CODE_500);
|
||||
}
|
||||
ENDPOINT("DELETE", "demo/api/users/{userId}", deleteUser,
|
||||
PATH(Int32, userId)) {
|
||||
|
Loading…
Reference in New Issue
Block a user