Hey,
When I convert a swagger.json document to SwaggerDocument object in C#, it ignores the basePath variable and sets it to null. I am using swagger 2.0, in which it should not ignore that property. I suspect it has to do with the following annotation:
[Newtonsoft.Json.JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, Order = 6, PropertyName = "basePath")]
My example swagger.json file:
{
"swagger": "2.0",
"info": {
"description": "",
"version": "2.15.250",
"title": "Test Service",
"contact": {
"name": "HelpDesk",
"email": "[email protected]"
},
"license": {
"name": "All rights reserved",
"url": ""
}
},
"basePath": "/api/example/v1"
}
Here's what I use to deserialize json to SwaggerDocument object:
class Program
{
static void Main(string[] args)
{
string json = System.IO.File.ReadAllText(@"c:/desktop/swagger.json");
SwaggerDocument doc = JsonConvert.DeserializeObject<SwaggerDocument>(json);
Console.WriteLine(doc.BasePath);
var name = Console.ReadLine();
Console.WriteLine(doc.ToJson());
Console.ReadLine();
}
}
and the output is:
{
"swagger": "2.0",
"info": {
"title": "Test Service",
"description": "",
"contact": {
"name": "HelpDesk",
"email": "[email protected]"
},
"license": {
"name": "All rights reserved",
"url": ""
},
"version": "2.15.250"
}
}

You cant serialize/deserialize a document with JsonConvert. Use ToJson() (or FromJsonAsync)
Thanks Rico! that worked.
SwaggerDocument.FromJsonAsync(json)