I’m trying to use NSwag to generate a client for the Azure DevOps REST API but I’ve hit a problem with deserializing the response.
I am using an OpenAPI document taken from here: https://github.com/MicrosoftDocs/vsts-rest-api-specs/tree/master
Specifically the document for git: https://github.com/MicrosoftDocs/vsts-rest-api-specs/blob/master/specification/git/7.2/git.json
The problem seems to me to stem from the difference in what the specification claims is returned verses what’s actually returned.
The spec states that the GetRepositories
method returns an array of GitRepository
. But when invoked, it actually returns a single object with one value
property that then contains the array.
{
"value":[{
"id":"1234",
"name":"bla blah"
}]
}
So the code that NSwag generates is failing to deserialize it because it’s not an array.
Could not deserialize the response body string as System.Collections.Generic.ICollection`1[[RestClients.GitRepository, GeneratedRestClients, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Why would the specification document differ from what’s actually returned?
And is there a way to tweak the NSwag settings so that it deserializes correctly?