2

我有一个简单的会话对象,看起来像这样

[Route("/Session", Summary = "Creates a security session", Notes = "Some session related notes here")]
public class Session : IReturn<SessionResponse>
{
    [ApiMember(Name = "DomainName", Description = "The Security Domain", ParameterType = "path", DataType = "string", IsRequired = true)]
    public string DomainName { get; set; }

    [ApiMember(Name = "UserName", Description = "The User Name", ParameterType = "path", DataType = "string", IsRequired = true)]
    public string UserName { get; set; }

    [ApiMember(Name = "Password", Description = "The password", ParameterType = "path", DataType = "string", IsRequired = true)]
    public string Password { get; set; }
}

当我去大摇大摆的 UI 时,我可以看到元素

但是,当我输入元素并按 Try it now 时,我看到请求内容没有发送到服务器。

我是否使用 parameterType="path" 正确配置了我的 poco,还是应该在这里做其他事情?请指教。

4

4 回答 4

2

在没有在主体参数定义中看到您的路径参数的情况下,是否有任何更新让它工作?

[Route("/users/{UserId}/races", "POST", Summary = "Associates a race with a user")]
public class AddUserRace : IReturnVoid
{
    [ApiMember(Description = "User Id to associate a race with to", ParameterType = "path", Verb="POST", DataType = "int", IsRequired = true)]
    public int UserId { get; set; }
    [Description("Race Id of race to associate with user")]
    public int RaceId { get; set; }
}

招摇用户界面结果

理想情况下,由于 UserId 是一个路径参数,我希望它从 DTO 正文中隐藏。

于 2013-11-13T18:39:56.823 回答
1

To support sending data in the request body with the current implementation of Swagger in ServiceStack, you should have exactly one ApiMember with ParameterType = "body" (you can still have other ApiMember attributes with other other ParameterType values, if you have variables in your URL for example).

The ApiMember with ParameterType = "body" will represent the entire content of your request body. It doesn't really matter which property of your request DTO you decorate with this attribute. We do something like this to make it clear in the Swagger UI that the textarea generated for this ApiMember should be used to populate the entire request body:

[ApiMember(Name = "RequestBody", ParameterType = "body", IsRequired = true,
    Description = SomeLongStringConstantThatDescribesTheEntireDTO]

In the Swagger UI, this will display a textarea, you will need to enter the entire DTO as JSON in this text area. In your case, it would be something like:

{"DomainName": "...", "UserName": "...", "Password": "..."}
于 2013-04-26T03:06:40.650 回答
1

我得到了这个工作,这是我必须做的

[Route("/Session", "POST", Summary = "Creates a security session", Notes = "Some session related notes here")]
public class Session : IReturn<SessionResponse>
{
    [ApiMember(Name = "SessionData", Description = "The Session Data", ParameterType = "body", DataType = "SessionData", IsRequired = true)]
    public string DomainName { get; set; }

    //[ApiMember(Name = "UserName", Description = "The User Name", ParameterType = "path", DataType = "string", IsRequired = true)]
    public string UserName { get; set; }

    //[ApiMember(Name = "Password", Description = "The password", ParameterType = "path", DataType = "string", IsRequired = true)]
    public string Password { get; set; }
}

所以现在我得到一个文本区域框,我需要为整个会话对象输入 JSON,以便传输域名、用户名和密码,但不知何故这似乎不正确。

于 2013-03-22T21:25:28.853 回答
1

我是否使用 parameterType="path" 正确配置了我的 poco,还是应该在这里做其他事情?

我不这么认为。将每个 Session 属性配置为ParameterType='path'建议您希望每个属性成为具有路径/url 的变量/字段(此处的文档)。因此,如果您想使用“路径”,您可能希望您的 ServiceStack 路由看起来像这样。

[Route("/Session/{DomainName}/{UserName}/{Password}"]

对我来说,“查询”或“正文”会是更好的选择。此外,这也可能包含有用的信息

于 2013-03-21T06:01:57.607 回答