Swagger.ObjectModel.Builders.RequiredFieldException: 'Paths' 是必需的

Swagger.ObjectModel.Builders.RequiredFieldException: 'Paths' is required

使用 Nancy v 1.4.1 和 Nancy.Swagger v 2.1.1(最后一个支持 Nancy v1),导航到 /api-docs 路径时出现上述错误。有任何想法吗?我所见过的任何设置步骤都没有说明 'Paths' 字段。

我的模块:

public class General : NancyModule
{
    public General()
    {


        Get["/","Home"] = parameters =>
        {
            try
            {
                return "home";// View["view/index.html"];
            }
            catch (Exception ex)
            {
                return ExceptionHelper.ExceptionResponse(Negotiate, ex);
            }
        };

        Get["/test/", "Test"] = parameters => {
            return "testie";
        };
    }
}

我的模块元数据:

public class GeneralMetadataModule : MetadataModule<PathItem>
{
    public GeneralMetadataModule(ISwaggerModelCatalog modelCatalog)
    {
        Describe["Test"] = description => description.AsSwagger(
            with => with.Operation(
                op => op.OperationId("Test")
                        .Tag("Users")
                        .Summary("The list of users")
                        .Description("This returns a list of users from our awesome app")));
    }
}

堆栈跟踪:

Nancy.RequestExecutionException: Oh noes! ---> Swagger.ObjectModel.Builders.RequiredFieldException: 'Paths' is required. at Swagger.ObjectModel.Builders.SwaggerRootBuilder.Build() in C:\projects\nancy-swagger\src\Swagger.ObjectModel\Builders\SwaggerRootBuilder.cs:line 123 at Nancy.Swagger.Services.SwaggerMetadataProvider.GetSwaggerJson() in C:\projects\nancy-swagger\src\Nancy.Swagger\Services\SwaggerMetadataProvider.cs:line 91 at Nancy.Swagger.Modules.SwaggerModule.<>c__DisplayClass0_0.<.ctor>b__0(Object _) in C:\projects\nancy-swagger\src\Nancy.Swagger\Modules\SwaggerModule.cs:line 11 at CallSite.Target(Closure , CallSite , Func`2 , Object ) at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context) --- End of inner exception stack trace --- at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)

好吧,不管怎样,事实证明你需要这样做:

public class General : NancyModule
{
    public General() : base("/v1/general/")//this part
    {
        ...
    {
}

尽管示例 nancy.swagger 项目实际上并没有这样做,但由于某种原因仍然可以运行。无论如何,继承 base(path) 为我整理好了。

您输入的顺序错误 - 名称应该在第一位,然后是路径

Get["Home", "/"] = parameters =>  //this is right
{
    try
    {
        return "home";// View["view/index.html"];
    }
    catch (Exception ex)
    {
        return ExceptionHelper.ExceptionResponse(Negotiate, ex);
    }
};

Get["Test", "/test/"] = parameters => {  //and this is right
    return "testie";
};