0

My Swagger document defines a long data type expected to be sent in request like:

    size:
      type: integer
      format: int64
      description: 'Some size'

I create request using following code in C++:

web::json::value postData = web::json::value::object();

If I pass a hardcoded value (i.e 50 or so) in the body as below, I get 200 OK response, so that is good

postData[L"size"] = web::json::value::number(50);

However, if I pass this value as a long or int64_t data type variable like below, I get 400 Bad Request

long size = 50;   //or int64_t, it results with same error
postData[L"size"] = web::json::value::number(size);
pixel
  • 9,653
  • 16
  • 82
  • 149
  • Do you not have a way to see the messages that are sent to see what the difference is? – Jerry Jeremiah Sep 30 '20 at 21:40
  • Looking at the source for json::value, it only accepts double, int32_t, uint32_t, int64_t, and uint64_t so passing in a long or a hardcoded value would run the same function So I'm not sure that is the problem. – Jerry Jeremiah Sep 30 '20 at 21:47
  • @JerryJeremiah Thanks for your reply. I have tried both long and int64_t variable type and in both cases I get 400 response. If I pass just hardcoded number like 50, I get 200 response. My initial question contained some confusing comments, so I updated it to be clear, sorry about that and thanks. And to answer your question, no I dont have a way to look at the sent message to see what is the diference? I use PostMan but that way, the values are hardcoded, I have no way to pass in actual variable like from C++ code. – pixel Oct 01 '20 at 15:31

1 Answers1

0

The problem was that I use MockLabs to create mock calls. So, in there I had POST request body defined to be like:

{ "size":1 }

So, if my incoming POST request had a value different than 1 (i.e 50), I would get 400 Bad Request; otherwise, I would get 200 OK. If you keep this POST request body, then you can only send size=1, all other will return 400 Bad Request.

Since I was hardcoding 1, I was getting 200 OK But when I used a variable in my code (which is different than 1), I would get 400 Bad Request.

The solution: Simply remove POST request body definition in your mock server (I use MockLabs) and leave it blank. Then it will accept any POST request with body (i.e { "size":1 } or { "size":450 }, or { "size":8 }, or whatever other integer you want) and will response with 200 OK.

pixel
  • 9,653
  • 16
  • 82
  • 149