How to Process the Result Returned by NSwagStudio Generated c# Client

Context:

  • OpenAPI v2 endpoints implemented using Swagger
  • C# client generated using NSwagStudio. Using .NET dll framework

Basically, we'll need to cast the result to JArray and then cast it to the desired object type.

var result = (JArray) bookingClient.GetV1BookingSearchByDateRangeAsync(SearchStartDate, SearchEndDate, 10, 1, "", null).Result;
var bookings = result.ToObject<List<BookingViewModel>>();

Please take note that the above only needed if there's no response type declared.

For those endpoints with the response type declared, the generated response will not be in JArray. For example, the same code above can be done with the below code which the result is in type IList<BookingViewModel>

var result = bookingClient.GetV1BookingSearchByDateRangeAsync(SearchStartDate, SearchEndDate, 10, 1, "", null).Result;

Yea, Softinn is developing our API endpoints. This will open up more opportunities moving forward. IF you're a developer and keep to tap into the hotel's data (e.g. bookings from Agoda, guest check-ins etc). Ping us [email protected] to obtain your key.

Softinn API Staging Endpoint (not for production usage)

Popular posts from this blog

How to Host ClickOnce Installer on GitHub

How to Remove Certain URL Page from Google Analytics View