【问题标题】:ServiceStack metadata descriptions missing缺少 ServiceStack 元数据描述
【发布时间】:2014-07-25 16:39:24
【问题描述】:

在下面的给定示例代码中,元数据页面永远不会获得

中指定的描述
[Description("GET account, all or by list of groups or by list of logins")] 

是否需要设置特殊配置才能在元数据页面中显示描述?

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ServiceStack.ServiceHost;
using System.Runtime.Serialization;
using ServiceStack.WebHost.Endpoints;

namespace ConsoleApplication2
{
    public class User
    {
        public User()
        {

        }
        public int login;
        public string group;
        public string name;
    }

    [Description("GET account, all or by list of groups or by list of logins")]
    [Route("/accounts")]
    public class Accounts : IReturn<List<User>>
    {
        public string[] groups { set; get; }
        public int[] logins { set; get; }

        public Accounts() { }

        public Accounts(params int[] logins)
        {
            this.logins = logins;
        }

        public Accounts(params string[] groups)
        {
            this.groups = groups;
        }
    }

    public class Host : AppHostHttpListenerBase
    {
        public Host() : base("Test", 
                            typeof(Accounts).Assembly)
        {

        }

        public override void Configure(Funq.Container container)
        {
            SetConfig(new EndpointHostConfig { 
                EnableFeatures = Feature.All

            });
        }
    }

    public class Servce : IService
    {
        public object Get(Accounts request)
        {
            return new List<User>(){new User()};
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            var host = new Host();
            host.Init();
            host.Start("http://+:12345/");

            Console.ReadLine();

        }
    }
}

导航到http://localhost:12345/json/metadata?op=Accounts 产生

<body>
    <a id="logo" href="http://www.servicestack.net" title="servicestack"></a>
    <h1>Test</h1>

    <form>
    <div>
        <p><a href="/metadata">&lt;back to all web services</a></p>
        <h2>Accounts</h2>



        <div class="example">
        <!-- REST Examples -->
        ...

【问题讨论】:

    标签: servicestack


    【解决方案1】:

    recent release of ServiceStack 中,[Description] 已被弃用,取而代之的是 [Api][ApiMember],它们也在 ServiceStack's Swagger support 中使用。

    现在这是一个完全注释服务的示例:

    [Api("Service Description")]
    [Route("/swagger/{Name}", "GET", Summary = @"GET Summary", Notes = "GET Notes")]
    [Route("/swagger/{Name}", "POST", Summary = @"POST Summary", Notes = "POST Notes")]
    public class MyRequestDto
    {
        [ApiMember(Name="Name", Description = "Name Description", 
                   ParameterType = "path", DataType = "string", IsRequired = true)]
        public string Name { get; set; }
    }
    

    【讨论】:

    • 再次感谢 快速跟进问题:ApiMember 注释有什么作用?因为我在使用元数据时没有看到任何差异。只有 Api 属性似乎添加到 html 中,与 Api 上的摘要和注释相同
    • 它已在 Swagger 中使用,但尚未在 /metadata 页面中使用 - 即将推出。
    • @mythz 出于兴趣,如果您想将其作为更复杂的类型发布,参数type="body" 和 datatype="MyrequestDTO" 会不会?
    • 这只是 Swagger 的元数据(即它不会影响 servicestack)。请参阅Swagger Parameters wiki 了解不同的选项。
    猜你喜欢
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 2012-02-10
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多