domaindrivendev / swashbuckle.webapi Goto Github PK
View Code? Open in Web Editor NEWSeamlessly adds a swagger to WebApi projects!
License: BSD 3-Clause "New" or "Revised" License
Seamlessly adds a swagger to WebApi projects!
License: BSD 3-Clause "New" or "Revised" License
Branching out from issue#25,
What we have are some classes with index-properties of a certain type, with the an integer or string or culture based index.
public class SomeRandomClass
{
private LocalizedValue [] _values = null;
public LocalizedValue this[int index]
{
get { return _values[index]; }
}
public LocalizedValue this[string cultureID]
{
get
{
for (int i = 0; i < _values.Length; i++)
{
if (_values[i].CultureID.Equals(cultureID))
return _values[i];
}
return null;
}
}
public LocalizedValue this[CultureInfo culture]
{
get
{
return this[culture.Name];
}
}
}
The propertyType - ModelSpec dictionary that you create while reflecting upon the class, considers just the return type of the properties as the key for the dictionary, which in the above case is "LocalizedValue" for all the three index based properties, and hence throws a duplicate key exception.
When swashbuckle generates a model-spec for such a class, it throws the same exception as in Issue#25.
I think you can get rid of index properties all together while reflecting, since they mean nothing in javascript.
var propInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
.Where(propInfo => propInfo.GetIndexParameters().Length == 0);
Regards,
Venkat Renuka Prasad.
It seems that there is no way to specify the ApiVersion
I have a number of API controllers that are being documented by Swagger/Swashbuckle. I'm finding that, for one of these controllers (named DataController i.e. my Web API route prefix is api/data), Swagger seems to refuse to generate documentation for the controller:
The error in loading this particular Swagger definition means that it is not possible to generate Swagger UI for the remaining controllers either, even though the Swagger JSON definitions are successfully being loaded for these controllers.
On the server side, I can see that the following error occurs whenever a GET request is made to the failing URL:
An exception occurred while processing an API request: GET http://localhost/Framework/swagger/api-docs/Data
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
Thanks in advance for any guidance that you can offer!
Hi there,
Absolutely love the work you have done with this. I have evaluated both this and swagger.net, and I just had more success with this project.
Can I suggest the following modificaition. When we return HttpResponseMessage from the action, could Swashbuckle treat that as a "void" swagger datatype.
Thanks again for the hard work
I just found Swashbuckle and was trying to use it out of the box to improve my API documentation. First thing I noticed is there is a JS error when trying to find a signature for a type. The issue is when you have a Model that is of SomeObject in WebApi. This causes issues in mapping because the isListType function in Swagger.js searches for "[" to determine if it is a list and then tries to find the that was used in the list of models. However in the list of Models, SomeObject[String] is listed so the mapping fails.
Hi I am very new and trying to learn how swashbuckle works. I started running the project 'Swashbuckle.Dummy.SelfHost' by downloading swash buckle. Then I went to the browser and checked the url that is given in main function of program.cs class. There after I get below error when I type the url in browser something linke 'http:/localhost:8090/swagger'. Can any one please guide me the step by step process to run the swash buckle solution and test it. If I want to host this application on IIS and run. Which folder do I need to host on IIS?
An error has occurred. Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) System.IO.FileLoadException at Swashbuckle.Application.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.HttpServer.<>n__FabricatedMethod9(HttpRequestMessage , CancellationToken ) at System.Web.Http.HttpServer.d__0.MoveNext()If a parameter that is from the uri has a name that is anywhere in the path, that parameter is marked as "path" even if it should really come from "query". For instance, if the apiPath is "api/v1/Swashbuckle" the parameter "wash" would be marked as "path" since it is found in the word Swashbuckle. When the parameter does come from the path, the parameter is surrounded by {} ({ParamName}). I think it would make sense to make this change to OperartionSpecGenerator.CreateParameterSpec(...)
case ApiParameterSource.FromUri:
paramType = apiPath.Contains(apiParamDesc.Name) ? "path" : "query";
break;
To be
case ApiParameterSource.FromUri:
//Path parameters are surrounded by {} like this: {Param}
paramType = apiPath.Contains(String.Concat('{',apiParamDesc.Name,'}')) ? "path" : "query";
break;
Hi, First of all, brilliant work. I'm new to Swagger and Swashbuckle made life very easy for us to integrate into our API, a few well written comments later and we're good.
We are facing one minor issue in which our models assume default values which don't look that appealing. See the image attached.
Is there a way to specify a default value for model properties? I have had no luck using default value attributes so far e.g.
[System.ComponentModel.DefaultValue("My Default String Value")]
public string Value { get; set; }
Thanks for this interesting project, I've tried to integrate your plugin with this web API 2 https://github.com/tjoudeh/AngularJSAuthentication/tree/master/AngularJSAuthentication.API which is IIS hosted and uses owin middleware but It didn't work out correctly.
What I've done is the following:
Once I Moved Swashbuckle.Bootstrapper.Init(config); to owin Startup class and commented out the implementation in SwaggerConfig file the url http://localhost:26264/swagger/api-docs returned list of the API but there was no UI (it returns 404).
Once I kept calling Swashbuckle.Bootstrapper.Init(config) from 2 places (Startup & SwaggerConfig) classes it worked correctly but I believe it is not correct to fire up the init method twice.
It will be great if you were able to check my API and tell me what is the right to integrate it using Web API 2 with own middle ware.
Hello, we are currently building out our web api in VS 2012. Your project looks very interesting. I downloaded Swashbuckle.TestApp and I can't seem to get it to work. After fixing the Nuget warnings, it doesn't seem to resolve the index.html properly.
System.IO.FileNotFoundException: index.html
Swashbuckle-master\Swashbuckle\Handlers\EmbeddedResourceHttpHandler.cs Line: 33
I had to adjust the port number, but that shouldn't matter.
http://localhost:60888/swagger
Is there something I am missing? Or is this project still getting off the ground?
If I create a new mvc4 project and add in the latest published nuget package, any regular mvc controller with a RedirectToAction call is sending me to /swagger?controller=&action=
I'm using a stock VS 2012 MVC4 template, without change to any routes, etc.
If I comment out the AreaRegistration.RegisterAllAreas(); call in app startup, the problem disappears. Something is odd about the routing, but I can't find it.
private static string MediaTypeFor(string path)
{
var extension = path.Split('.').Last();
switch (extension)
{
case "css":
return "text/css";
case "js":
return "text/javascript";
case "gif":
return "image/gif";
case "png":
return "image/png";
default:
return "text/html";
}
}
I have trouble with getting Swashbuckle working with latest web-api template. I created a new WebAPI project using VS2013 ASP.Net-WebAPI template...added the Swashbuckle nuget package to it. When i navigate to \swagger\ui\index.html I get a broken Swagger UI with few elements rendered but without the API methods. The same thing with VS2012 - MVC4-WebAPI template works fine.
Am i missing any config setting? I did check everything in the troubleshoot section. Any help is appreciated.
I've tried adding this now a few times to my API project and it adds the .dll but no corresponding UI. I've tried copying in the UI files from the swagger site, but can't figure out how the routes are supposed to work. Any suggestions?
Hello,
First of all, thank you for this project. Love it! I tried installing this with a Web API project that doesn't use Attribute routing and everything works great. However, upon installing this package on a Web API project that uses Attribute Routing throws an error like so:
Unable to read api 'AffiliatesV1' from path http://localhost:56251/swagger/api-docs/AffiliatesV1 (server returned undefined)
Where Affiliates is just the name of my controller. Going down the error, I see the error message as shown below. If I look at the RAW option on each API, I can see the correct items, however, this error is preventing me from viewing any operations etc.
Could you assist? Thanks!
message: "An error has occurred.",
exceptionMessage: "Object reference not set to an instance of an object.",
exceptionType: "System.NullReferenceException",
stackTrace: " at Swashbuckle.Swagger.OperationGenerator.CreateParameter(ApiParameterDescription apiParamDesc, String apiPath)
at Swashbuckle.Swagger.OperationGenerator.<>c__DisplayClass2.b__1(ApiParameterDescription paramDesc)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
Hello,
I understand that Swagger allows you to customize the API Key change event to allow adding the key as a part of the Header instead of the Query string parameter by changing the default code shown here:
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
log("key: " + key);
if(key && key.trim() != "") {
log("added key " + key);
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
I know the solution but I don't know how I can change this using Swashbuckle because the template is embedded. I noticed that you have a way to embed Javascript by creating Embedded resource files.
Can you please explain how we could go about doing this? I literally need to make the following change:
$('#input_apiKey').change(function () {
var key = $('#input_apiKey')[0].value;
if (key && key.trim() != "") {
key = "Bearer " + key;
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", key, "header"));
}
})
I would highly appreciate it if you could guide me here.
Thanks in advance for your consideration.
Would be great to have this in the Swashbuckle Nuget package:
swagger-api/swagger-ui#460
Thanks.
A few months back, a change was made so that only declared properties are included in the ModelSpec. Now several of my classes that inherit from a base class no longer show all their properties in the swagger description.
The change was in this commit: a8e84cc
Is there any way of adding basic authentication header beside modifying index.html from swagger-ui directly?
I have a somewhat unique setup due to numerous teams developing Web APIs on the same server. We have one main project that runs our web app (and contains the App_Start), sets up routing rules, configuration, etc. There are also a number of MVC and Web API projects that each contain one or more controllers. Example:
Solution 'WebProjects'
If I want the project "TeamAWebAPI" to be documented with Swagger using Swashbuckle, where should I install the Nuget package so that it starts Swashbuckle properly in the web app, but can also detect my web api project as an API that needs swagger documentation?
When I have installed Swashbuckle in the past, I could only ever access it on localhost. My web api has a domain constraint that limits it "api.MYDOMAIN.com." How do I route the raw data to the domain in the domain constraint?
Thanks!
I'm using the JsonProperty("PropertyName") attribute to change my JSON property names, and the JsonIgnore attribute to ignore certain properties.
However Swashbuckle seems to be ignoring these when generating documentation.
Would it be a big job to implement this?
Hi @domaindrivendev,
When the developers mess up the XML comments (like no closing tag, or using different case for closing or opening, etc), is there a way Swashbuckle can pinpoint where the XML comments are broken (instead of throwing a 500-error)? I ask this because we have hundreds of controllers already and there are going to be even more, we often encounter this problem.
Thank you!
It would be helpful for me if I knew which commit corresponded to https://www.nuget.org/packages/Swashbuckle.Core/4.0.0 and a git tag like v4.0.0
makes perfect sense.
I'd appreciate if the current and future nuget releases were tagged.
Thanks!
Using Swashbuckle, I'm getting a NullRef when its trying to describe one of my ApiControllers:
{"message":"An error has occurred.","exceptionMessage":"Object reference not set to an instance of an object.","exceptionType":"System.NullReferenceException","stackTrace":" at Swashbuckle.Swagger.OperationGenerator.CreateParameter(ApiParameterDescription apiParamDesc, String apiPath)\r\n at Swashbuckle.Swagger.OperationGenerator.<>c__DisplayClass2.b__1(ApiParameterDescription paramDesc)\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Swashbuckle.Swagger.OperationGenerator.ApiDescriptionToOperation(ApiDescription apiDescription)\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n at System.Linq.OrderedEnumerable`1.d__0.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Swashbuckle.Swagger.ApiExplorerAdapter.CreateApi(IGrouping`2 apiDescriptionGroup, OperationGenerator operationGenerator)\r\n at Swashbuckle.Swagger.ApiExplorerAdapter.<>c__DisplayClassb.b__7(IGrouping`2 apiDescGrp)\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n at System.Linq.OrderedEnumerable`1.d__0.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Swashbuckle.Swagger.ApiExplorerAdapter.GetDeclaration(String basePath, String version, String resourceName)\r\n at Swashbuckle.Application.CachingSwaggerProvider.<>c__DisplayClass4.b__3(String k)\r\n at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)\r\n at Swashbuckle.Application.CachingSwaggerProvider.GetDeclaration(String basePath, String version, String resourceName)\r\n at Swashbuckle.Application.SwaggerSpecHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.HttpServer.<>n__FabricatedMethod9(HttpRequestMessage , CancellationToken )\r\n at System.Web.Http.HttpServer.d__0.MoveNext()"}
Hi @domaindrivendev,
We have a pretty large project with a large number of ApiControllers, that could go as high as 500 or more, which are spread across various areas.
Would it be too much work to group ApiDescriptionGroups by the namespace of the ApiController and render some kind of a tree view explorer in the ui?
Hi @domaindrivendev,
Swashbuckle threw a 500 - internal server error. I debugged and found, the error is while generating ModelSpec for certain classes.
Tracing it:
ModelSpecGenerator.TypeToModelSpec for a few particular types, when looping through to generate Complex-Spec for contained types, calls CreateSpecFor(..)
which in turn calls CreateComplexSpecFor()
private ModelSpec CreateComplexSpecFor(Type type, IDictionary<Type, ModelSpec> complexTypes)
{
var propInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
//This line throws the error: "An item with the same key has already been added"
var propSpecs = propInfos
.ToDictionary(propInfo => propInfo.Name, propInfo => CreateSpecFor(propInfo.PropertyType, true, complexTypes));
//.........
//.........
}
type {Name = "ApplicationTrustCollection" FullName = "System.Security.Policy.ApplicationTrustCollection"}
Thank you.
I'm working with the Swashbuckle.Core 4.0-beta package in an OWIN-hosted WebAPI project and it works pretty well.
One of the challenges, though, is that while I can inject scripts and CSS, I can't actually change the index.html file that easily. For example, I might want to put my own icon/buttons with their own destinations at the top of the page, or add some additional page content in there.
While I could probably retroactively "poke" it in with jQuery or something, it'd be nice to just be able to swap out the index.html entirely. Or make use of some sort of pseudo "master page" sort of thing where the page is actually built up from smaller templates for the header and footer that I could affect.
disclaimer: i'm still new to dot-net land so bear with me for just a minute... :-)
so the default path to swagger(which i beautifully have fully up and running and integrated with my api's) is ~/swagger/ui/index.html
. What i have thus far done is created a Controller
that just spits back View()
. This view has an iframe in it that contains the path to swagger-ui... the problem there being that now i've got nested scrollbars and, well, it's an iframe and that's no fun. what i would like to do is have swagger-ui as the source of the Controller
and drop the iframe garbage. would this be feasible?
so far i've had two ideas as to how this would be accomplished and not sure if they're doable so figured the experts over here might have a good idea of how to proceed...
swagger/ui/index.html
to something in more of a proper path of what the Controller
would be able to automatically pick up...swagger/ui/index.html
instead of the index.cshtml
that it automatically looks for in its respective folderwould either of these be ideal or even work? i figured an issue was an appropriate place since this would be an awesome readme topic... :-)
thanks for the awesome library!
Hello,
I have realized that in many cases, we use Inheritance hierarchy for certain items. For e.g. we have a base Field class that has a Title and a Key property. Then we have a TextField which derives from a Field class and adds a Description property. When swagger shows documentation for the TextField, it only shows Description as the property and doesn't recognize the underlying Title or Key as properties.
would you be able to look into this and guide me if I'm doing something incorrectly?
Thank You so much!
In order for swagger to allow me to call a GET with a complex type specified as my parameter, I had to do some custom modification using the OperationFilter.
Here is what the WebAPI controller action method looks like:
The URL should look like the following examples:
/api/blah?Id=1&secondaryid=blah
or
/api/blah?id=1&secondaryid=blah&fieldone=blah&fieldtwo=blah
Here's what happens without the operation filter:
Here's what I need it to do (or something similar):
And Here's how I got it to do that:
I don't want to have to do this for every single method that I have this sort of issue on. I did get this to work using that operation filter, but I already know there will be other methods similar to this same one. Is this a bug, or is there a better way to do this?
Thanks,
Alex
Any chance the UI bits (and corresponding HTTP handler) can be pulled out into a separate NuGet package? We tend to host the docs in a separate site which points at the Swashbuckle endpoint. It also allows us to version swagger-ui without having to re-deploy our main app.
Hi @domaindrivendev,
We're signing all our assemblies used in our project. Swashbuckle doesn't seem to be signed. Can you please release a signed version of Swashbuckle?
Thanks,
Venkat.
Hi,
I've encountered really strange bug.
I've included swashbuckle to our azure project. After deploy, the web role kept recycling.
After couple of hours of experimenting we've found the issue.
Just mere existence of AddStandardResponseCodes
class in the project was the problem.
After removing this class, everything was ok.
Yes, even after commenting out line c.OperationFilter<AddStandardResponseCodes>);
web role kept recycling. We had to remove the file from project.
If it will be any helpful this is the exception
[00000017] [06/05/2014 13:54:15.19] [WARN] PutMachineHealth() failed, will retry later. Exception: Microsoft.ServiceModel.Web.WebProtocolException: Server Error: Internal Server Error (InternalServerError)
Server stack trace:
at Microsoft.ServiceModel.Dispatcher.WebHttpClientMessageFormatterEx.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at Microsoft.ServiceModel.Web.WebHttpChannelProxy`1.Invoke(IMessage msg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.WindowsAzure.RoleContainer.Protocol.IControlSystem.PutMachineHealth(Health health)
at Microsoft.WindowsAzure.RoleContainer.Protocol.ControlSystemExtensions.PutMachineHealth(IControlSystem channel, Health health, Nullable`1& latestGoalStateIncarnationNumber)
at Microsoft.WindowsAzure.RoleContainer.Protocol.ControlSystem.ReportHealth(Health health, Nullable`1& latestIncarnation).
If we wrap our actual return object in IHttpActionResult as a recommended practice in ASP.NET WebAPI 2, the Swagger Spec rather shows the Response Class as the top level interface for the IHttpActionResult.
Instead of that, I would like to describe the underlying class which, I plan to pick from the < returns > tag in the XML descriptive comments..
Any suggestions on where I could get started would be greatly appreciated.
Hi,
I implemented in web api 2 versioning based on namespaces,based on http://blogs.msdn.com/b/webdev/archive/2013/03/08/using-namespaces-to-version-web-apis.aspx implementations.
Documentation now generated in root/swwagger.
Is any way to generate documentation in root/v1/swagger? If so, how can i do it?
Also, my web api accessible by root/api/, but your implementation access root/swagger. Is any way to access it by going root/api/swagger?
Thank you
Hi,
Is it possible to turn on relative path resolver for Swagger UI request URL-s or can it be implemented ?
I have a server that uses many load balancers. And because of it I can get swagger UI index page work well, but when trying to call any method, request are made to wrong base path and port.
For example, using load balancer, index page can be found from:
http://localhost:8401/swagger/ui/index.html
But when making any query, following path is used:
http://localhost:8450/api/Status
Can you please support the chance to use relative paths that can be used instead of configured path (automatically or manually) on App_start register ?
I have updated from version 2.2.1 to 3.0.1 and this version doesn't work.
Swagger can't load some data from site.
URL
http://localhost/WebAPI/swagger/api-docs
RESPONSE
An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: An item with the same key has already been added.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: An item with the same key has already been added.]
System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) +10695474 System.Linq.Enumerable.ToDictionary(IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector, IEqualityComparer1 comparer) +247 Swashbuckle.Models.SwaggerGenerator.GenerateDeclaration(IGrouping
2 apiDescriptionGroup) +515
System.Linq.Enumerable.ToDictionary(IEnumerable1 source, Func
2 keySelector, Func2 elementSelector, IEqualityComparer
1 comparer) +235
Swashbuckle.Models.SwaggerGenerator.GenerateDeclarations(IEnumerable`1 apiDescriptionGroups) +134
Swashbuckle.Models.SwaggerGenerator.Generate(IApiExplorer apiExplorer) +227
Swashbuckle.Controllers.ApiDocsController..ctor() +117
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
[InvalidOperationException: An error occurred when trying to create a controller of type 'Swashbuckle.Controllers.ApiDocsController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +179
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +197
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
We have an API that returns 2 representations of the same data - Basic and Verbose. Basic returning fewer fields. The classes behind these are named the same, but are in different namespaces.
When the Unique ID is created using the name it is not unique though as it is just using the class name and not the fully qualified name with the namespace.
We have managed to work around this but feel the full name would be more appropriate for a unique ID.
Hi, would it be possible to eliminate dependency on the MVC framework?
I was trying to use Swashbuckle on a project that has Aspnet Webforms Web Application + Aspnet Webapi (A legacy project that we are adding a REST api). The problem is that the path /swagger and /swagger/ui/index.html they both return 404.
Aspnet Webapi can be used on the top of MVC or ASPNet form. So it would be great if Swashbuckle could be used the same way.
Great job by the way!
Regads,
Victor
I tried integrating Swashbuckle into a Web API 2 project and I can't seem to get the swagger UI to render correctly. I was optimistic since I thought the XML doc should be similar, but I notice that version 4.0 WebAPI assemblies are being referenced instead of the version 5.0 Web API 2 ones.
Not sure if branch remove_mvc_dependency would do anything to address this. I did try to drop in the dlls from that branch and started getting 404 errors where before I at least had the swagger headers. (I was guessing at the integration, so I may have blotched that one)
first of all... AWESOME library. thanks for all your work here... :-)
so I'm getting started with swashbuckle and i'm fully up and running but i'm still admittedly a bit of a newbie here. My question now revolves around front end GUI population.
if you look here: http://petstore.swagger.wordnik.com/#!/pet/updatePet you'll see some fancy populated stuff like the Response Messages
fields on the bottom... My question to you is if you can you point me to a full list of xml tags that will be presented at the swagger-ui level?
On a side note, I'm not sure if it's a bug or not, but only one of my response objects is being mapped out at the swagger-ui level. all other response object class models are just being presented in swagger as:
classname {
}
and they're all defined in the same exact ways in my code so that's a little weird. they also are fully populated in the webapi help docs as i would expect these models to be displayed in swagger-ui.
sorry for the general questions, but thanks in advance for any and all help :-)
I have an asp.net webapi running (.net 4.5) with Help pages loading all my xml comments via the ApiExplorer. I want to now add swagger via swashbuckle. So I installed the swashbuckle nuget but when I browse to my endpoint I get an error as suggested by swashbuckle documentation..
endpoint: localhost:1234/api/company/swagger error: {"Message":"Unauthorized request"} or endpoint: localhost:1234/api/company/swagger/apidocs error: 404 - Not Found
Am I missing a step or what am I doing wrong??
Hi @domaindrivendev,
I am not sure, if this is an issue with swagger-ui or Swashbuckle. The Model-Schema does not do a second level description of contained models.
Eg:- For a model like this
{
"PolicyKey": 0,
"Revision": 0,
"UpdatedInstances": [
"PolicyInstanceBaseData"
]
}
I think it should instead show something like the following:
{
"PolicyKey": "integer",
"Revision": "integer",
"UpdatedInstances": "PolicyInstanceBaseData" [
{
"key": "integer",
"id": "string",
"enabled": "boolean",
"mappingsComplete": "boolean"
}
]
}
I tried to understand how model-schema is being generated, with little success. Can you please let me know how I can proceed with this?
Thank you!
Hey! We've had a great time with swashbuckle but we're having some trouble setting up custom auth headers that are unique to every call. We'll need to hash the request path, method and an API key. Ideally we'd like to just override the SwaggerHttp.prototype.execute
(swagger.js line ~1137) which has all the information we need. Is there an easy way to monkeypatch that call from the custom script injection that swashbuckle uses?
Hi - great lib.
Did you ever try to print the swagger-ui HTML view? The layout gets messed up, entirely ;)
Any idea what is wrong?
Thanks.
I have the following signature in an API Controller:
[System.Web.Http.AcceptVerbs("PUT")]
public HttpResponseMessage Reorder(int itemid,
int parentid,
[FromBody] JObject jobject)
{
//...
}
It looks like the SwaggerGenerator goes into an infinite loop when it tries to reflect that method:
var modelSpec = modelSpecMap.FindOrCreateFor(parameterDescription.ParameterDescriptor.ParameterType);
That calls CreateContainerSpec, which calls CreateModelSpec, which calls CreateContainerSpec ad infinitum. The System.Type it's getting is a JToken:
if (type.IsEnumerable(out enumerableTypeArgument))
return CreateContainerSpec(enumerableTypeArgument);
This is probably below the scope of your project, but it interested me and since I'm trying to broaden my horizons as a programmer, I figured it wouldn't hurt to ask. I'm in the process of trying to create my own MVC Web API project (something that I am still getting my feet wet with) and I wanted to utilize your project to create a swagger compliant spec from my code, but I don't want the JSON to go to a swagger-ui webpage. I want to output directly to a file. Is this possible?
Also, for various reasons, I am unable to use nuget to install your project. How would I go about installing this manually?
Thank you for your time, I appreciate any help you can provide!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.