-
Notifications
You must be signed in to change notification settings - Fork 711
Unable to integrate Odata versioned apis with swagger for Asp.net web application #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I haven't seen this issue nor had anyone else report it. Using OWIN shouldn't matter, at least, not in this context. I mostly use OWIN for examples so that the Web API and ASP.NET Core examples have close parity. I can't rule out a bug - yet. My cursory examination suggests that this might be an external. Are you by chance modifying the route collection in any way? Do you happen to have a repro handy? I can certainly create one, but working from something simple you already have is faster and an par with your expected setup. |
Chris, config.Services.Replace(typeof(IApiExplorer), new IntegrationServicesApiExplorer()); I have attached sample code the comment below. |
Please find attached sample code where the issue is reproduced System.NotSupportedException was unhandled by user code |
Hi Chris,
I have added sample application on #302 yesterday.
Please have a look at it.
The exact issue is reproduced in the sample app.
This has become quite urgent for us as we want to roll out client side OData apis for version 1.
Looking forward for your quick reply.
|
Chris,
Any updates on this? Did you get chance to debug sample application?
|
Sorry for the delayed response, I've been really overloaded lately. Thanks for your patience. I tried downloading your sample application, but it seems it's no longer there. I don't think GitHub expires this content. Can you try adding it again? I noticed you said you're using:
Is
This ultimately calls |
Thanks for your reply. In tha sample application we are not replacing IApiExplorer. Attaching the zip file again. Let me know if you can see this |
I think I see the problem. You're replacing the IHttpControllerSelector, but I don't know why. That's likely going to break API versioning, the API Explorer, or both. It appears that you started trying to build your own API versioning library and then switched. The IHttpControllerSelector is one of the core services that API versioning changes. You can see the implementation here. You can certainly extend and/or customize things, but if you go down that path, you will not want to use I've provided a number of OData samples - with and without Swagger. I think you're facing issues from customizations that may no longer be needed (on your side). If there is some customization or configuration you need that isn't supported, I'm happy to help you sort that out. If there's gap in design, then I want to hear about that too. Thanks |
Yureka! I see what the problem is. You are trying to follow and use code from the Swashbuckle + OData project. I just noticed something that caught my eye and made me double-check. That project is completely different, unrelated, and not compatible with the API versioning libraries. This is the first time I've seen this confusion, but I should probably mention something about that on the wiki. This project provides an implementation for IApiExplorer. It actually has no dependencies on Swashbuckle or Swagger in any way. Swashbuckle uses the IApiExplorer for the Web API implementation to support Swagger. For an end-to-end working solution with API versioning, OData, and Swagger (a la Swashbuckle), please review the sample I provide. You should be able fork it and get it running for your project in no time. I hope that helps. I'm happy to answer any other questions. |
Thanks for quick reply. |
I was able to repro the problem. Honestly, this is a bug and flaw in the way that the Web API support over IIS was written, but it's unlikely to get fixed any time soon - if ever. The issue is that RouteCollection in System.Web.dll doesn't expose the names of routes that it registers. The HostedHttpRouteCollection that maps over RouteCollection could have mapped these keys during add/remove to the underlying RouteCollection, but didn't. Instead, it just throw NotSupportedException. These types of runtime integration failures are difficult to detect and/or account for. I have the fix for this, but it involves very nasty Reflection under the hood. It looks like this scenario is only hit for OData with Web API and hosted on IIS. As much as I wish I could test every permutation of hosting combinations, I'm only one person. Regardless, the fix is relatively small. I should have something out momentarily. |
Version 1.2.2 of the package with the fix has been published. It may take a few minutes to get through the full NuGet vetting process. Feel free to re-open this, if you continue to have an issue. Thanks. |
Thanks a ton Chris for your efforts and making this so quick. you have saved us from implementing workaround for versioning on OData apis. |
We are facing some issue. The properties of json are in camel case whereas it should have been the way they are defined in the entity. We did following setting for Default PropertyNames Convension still it displays Entity Propertis in Camel Case in API responce. Issue No 2: Package Required : Swashbuckle.OData We are using Swashbuckle.OData package to display Odata Query option on Swagger document. Following configuration is done. configuration.EnableSwagger(SwaggerDocsRoute, swagger => After Odata Versiong ODataSwaggerProvider throws Exception - Issue No -3 |
There are 3 new issues we found, let me know if I need to create new issue |
Issue 1OData doesn't use the default JSON MediaTypeFormatter; it uses its own. Camelcase is very common for JSON. I suspect you are using the configuration in the examples I provide, which enable this. Simply remove this configuration. For example: var modelBuilder = new VersionedODataModelBuilder( configuration )
{
// configuration shown in example using camelcase
// ModelBuilderFactory = () => new ODataConventionModelBuilder().EnableLowerCamelCase(),
// default configuration using source case, which usually Pascalcase
ModelBuilderFactory = () => new ODataConventionModelBuilder(),
// remaining configuration ...
}; Issue 2I really know very little about the Swashbuckle.OData library or project. I don't use it or support it. You should have everything you need with the OData API versioning, OData API Explorer, and vanilla Swashbuckle. If there is something not supported that you need, I'd be interested in hearing about it to determine if a new feature is required. My recommendation would be to remove Swashbuckle.OData all together. It shouldn't be needed. Issue 3I'm not sure what this is. Does it repro in the example that you previously provided? If you can provide a copy of the most version of that sample where the scenario repros, I'll take a look. It's possible there's a bug. |
Uh oh!
There was an error while loading. Please reload this page.
We are using VersionedODataModelBuilder in Http application ( Asp.net web application)
Its does not have Owin startup hence we pass GlobalConfiguration.Configuration to VersionedODataModelBuilder constructor
Versiong of OData uri works fine as shown in the SwaggerODataWebApiSample
But while integrating this with swagger gives problems:
we create exploere as
var apiExplorer = configuration.AddODataApiExplorer(
options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
The exception comes at
foreach (var group in apiExplorer.ApiDescriptions)
here apiExplorer.ApiDescriptions throws excpetion Invalid Operation exception
HttpConfiguration.Services.GetApiExplorer "This operation is not supported by 'HostedHttpRouteCollection'."
apiExplorer.ApiDescriptions: This operation is not supported by 'HostedHttpRouteCollection'.
The reasons could be : GlobalConfiguration.Configuration.Routes is a collection of HostedHttpRoutes
whereas in sample application we create new HttpConfigutation
Routes = {System.Web.Http.HttpRouteCollection}
vs
Routes = {System.Web.Http.WebHost.Routing.HostedHttpRouteCollection}
We also have normal ( non-odata) web apis as well
Swagger documentation is configured for them too.
Do you have any such example where odata versioning integrated with swagger and its not Owin
The text was updated successfully, but these errors were encountered: