Skip to content
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

404s when using Api Versioning #52

Open
joemcbride opened this issue Jul 3, 2018 · 0 comments
Open

404s when using Api Versioning #52

joemcbride opened this issue Jul 3, 2018 · 0 comments

Comments

@joemcbride
Copy link
Contributor

If you setup your ASP.NET Core project with Api Versioning, Alba will give 404s for nearly all routes.

I tracked this down to the following line of code from this sample:

app.UseSwaggerUI(
  options =>
  {
      // build a swagger endpoint for each discovered API version
      foreach ( var description in provider.ApiVersionDescriptions )
      {
          options.SwaggerEndpoint( $"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant() );
      }
  } );

IApiVersionDescriptionProvider implementation appears to lazy-load the route/action information. When that code is run in Alba, it does appear to have the correct versioning information. However, doing a get request through Alba you get a 404. If you comment out the foreach then Alba works fine.

This seems to be some sort of timing issue. My only other guess is that the route versioning information is somehow not loaded properly when that class is initialized. The versioning appears to use an IStartupFilter to register route information, as shown here. Think that could possibly be related?

sealed class InjectApiVersionRoutePolicy : IStartupFilter
{
    readonly IApiVersionRoutePolicy routePolicy;

    public InjectApiVersionRoutePolicy( IApiVersionRoutePolicy routePolicy ) => this.routePolicy = routePolicy;

    public Action<IApplicationBuilder> Configure( Action<IApplicationBuilder> next )
    {
        Contract.Requires( next != null );
        Contract.Ensures( Contract.Result<Action<IApplicationBuilder>>() != null );

        return app =>
        {
            next( app );
            app.UseRouter( builder => builder.Routes.Add( routePolicy ) );
        };
    }
}

IStartupFilter's do appear to be called (I wrote a custom one to see that it did). Any ideas @jeremydmiller ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant