Open steve-jansen opened 11 years ago
See commit f3bd3b6ba917 for the repro above.
Yes, we need to use only path
not the path&query
. I changed the CreateResourceApi to include a flag swaggerRoot
. if request is to generate documentation for all apis with in a controller, we need to call with swaggerRoot=true
which will trim down the querystring part. But for ControllerActions we need to provide complete path+querystring.
public static ResourceApi CreateResourceApi(ApiDescription api,bool swaggerRoot)
{
var apiRelPath = api.RelativePath;
if (swaggerRoot)
{
int queryIndex = apiRelPath.IndexOf('?');
if (queryIndex > 0)
{
apiRelPath = apiRelPath.Substring(0, queryIndex);
}
}
ResourceApi rApi = new ResourceApi()
{
path = "/" + apiRelPath,
description = api.Documentation,
operations = new List<ResourceApiOperation>()
};
return rApi;
}
Overview
Swagger.Net incorrectly uses the path to the first action in a controller as the top level name of the API. We should just use the name of the controller (or shortest URL path without the querystring for non-default routes.)
Steps To Reproduce
Actual Results The first api for the "Pet" controller is listed as
path: "/api/docs/Pet?page={page}&size={size}"
Note that the
{}
chars in the name breaks the version of Swagger UI packaged with Swagger.Net when trying to load the details for the controller viahttp://localhost:65358/api/docs/Pet?page={page}&size={size}
. The ideal URL would behttp://localhost:65358/api/docs/Pet
, which currently works.Expected Results The api for the "Pet" controller should be
path: "/api/docs/Pet"