oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
91 stars 51 forks source link

[Swagger-ui] Request body is not declared as required #33

Closed oben01 closed 3 years ago

oben01 commented 3 years ago

Hello,

I declared a body as :

  ENDPOINT_INFO(getKeywordListInfo)
   {
      info->addTag("Keyword List info");
      info->description = "Get the last acquisition info for a list of keywords and list of info passed as a body. If the List of info is empty, the response will be the the list of keywords with empty values ";
      info->addResponse<Object<KeywordsListInfoResponse>>(
         Status::CODE_200,
         "application/json"
      );
   }

   ENDPOINT("PUT", "/acquisition/keyword/info", getKeywordListInfo,
         BODY_DTO(Object<KeywordsListInfoBody>, keywords))
   {
      return createResponse(Status::CODE_200, "OK");
   }

The swagger UI does not display my keywords body as required. Am I doing something wrong ? This issue may be related to https://github.com/oatpp/oatpp/issues/235#issue-613100782 Thank you.

lganzzzo commented 3 years ago

Fixed in #34

bamkrs commented 3 years ago

You mixed up response and consumes. You want to receive the DTO, and not respond with it:

ENDPOINT_INFO(getKeywordListInfo)
   {
      info->addTag("Keyword List info");
      info->description = "Get the last acquisition info for a list of keywords and list of info passed as a body. If the List of info is empty, the response will be the the list of keywords with empty values ";
      info->addConsumes<Object<KeywordsListInfoResponse>>(
         "application/json",
         "Your description"
      );
   }

   ENDPOINT("PUT", "/acquisition/keyword/info", getKeywordListInfo,
         BODY_DTO(Object<KeywordsListInfoBody>, keywords))
   {
      return createResponse(Status::CODE_200, "OK");
   }

Note info->addConsumes instead of info->addResponse

oben01 commented 3 years ago

hello @lganzzzo @bamkrs I confirm that the body is defined as required. @bamkrs do you mean something like that ?

  ENDPOINT_INFO(getKeywordListLastData)
   {
      info->addTag("Keyword List Last data");
      info->description = "Get the last acquisition for a list of keywords passed as a body";
      info->addConsumes<Object<KeywordsLastDataBody>>(
         "application/json",
         "Your description"
         );
      info->addResponse<Object<KeywordsLastDataResponse>>(
         Status::CODE_200,
         "application/json"
      );
   }

   ENDPOINT("PUT", "/acquisition/keyword/lastdata", getKeywordListLastData)//,
            //BODY_DTO(Object<KeywordsLastDataBody>, keywords))
   {
      return createResponse(Status::CODE_200, "OK");
   }

No need to declare BODY_DTO in my ENDPOINT ? (Am using Oatp++ only to generate swagger contract, no need to catch those values)

lganzzzo commented 3 years ago

@oben01 ,

Your original example looks correct. I think @bamkrs , confused the naming KeywordsListInfoResponse and KeywordsListInfoBody which look pretty similar.

I'm closing this issue