Developer forum

Forum » Dynamicweb 10 » /dwapi/docs - Failed to load API definition

/dwapi/docs - Failed to load API definition

Rene Poulsen
Rene Poulsen
Reply

When running a solution through VS on localhost, I get this error on /dwapi/docs.

Do I need to do something for this to work when running on localhost through VS Code (running it as a website)

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I think you need to find out what that 500 error is. What happens if you request /dwapi/api.json directly? That would give you the exception message - or you can have a look in network tools of your browser - or the event viewer on your box.

I only run DW10 locally in vs or vs-code....

 
Rene Poulsen
Rene Poulsen
Reply

@Nicolai

I get this error at the json file:

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Do you have any iWebApi implementations in your custom project?

And if so - how does it look?

 
Rene Poulsen
Rene Poulsen
Reply

Got a "WebApiEnabler.cs" that looks like this:

using Dynamicweb.Host.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Application.Pipelines
{
    public sealed class ApiPipeline : IPipeline
    {
        public int Rank { get; }

        public void RegisterApplicationComponents(IApplicationBuilder app)
        {
            app.UseRouting();
            app.UseAuthorization();
            app.MapWhen(context =>
                context.Request.Path.StartsWithSegments("/api"),
                appBranch =>
                {
                    appBranch.UseEndpoints(options =>
                    {
                        options.MapControllerRoute("api", "api/{controller}/{action}");
                    });
                }
            );
        }

        public void RegisterServices(IServiceCollection services, IMvcCoreBuilder mvcBuilder)
        {
        }

        public void RunInitializers()
        {
        }
    }
}

And an EventController:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Namotion.Reflection;
using Lucene.Net.Search;
using Microsoft.Graph.Models.Security;
using Newtonsoft.Json.Linq;
using System.Reflection;

namespace Application.WebApi
{
    [Route("/api/[controller]/[action]")]
    public class EventController : ControllerBase
    {
        [HttpGet]
        public IActionResult GetEvents()
        {
            // Code here...
        }
    }
}
 
Rene Poulsen
Rene Poulsen
Reply

@Nicolai when the above is deployed to our test server the /dwapi/docs and /dwapi/api.json works just fine. So I guess it must be something related to running it locally?

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Rene,

I've been trying to figure out what's going on here, and I've come to the same conclusion. Something happens during the processing of the OpenAPI document, but only when the pipeline is used in a custom host. Running it in a native host, like the ones in DynamicWeb Cloud, does not cause the issue.

It's not been possible for me to conclusively determine what the issue is but I have an idea. I have an incoming change that will hopefully make the document processing logic more robust. If all goes according to plan, this will be released into Ring 0 soon and Ring 1 by the end of November.

- Jeppe

 
Rene Poulsen
Rene Poulsen
Reply

Hi Jeppe,

Sounds great if there's a fix. It's actually possible to fetch data from the API locally - so it's just the swagger docs that are broken - and I can see them on our testserver where the site is setup as well.

 

You must be logged in to post in the forum