Servicestack object parameter not getting passed to service with Swagger-UI

烂漫一生 提交于 2019-12-24 09:08:10

问题


My service model:

[Route("/customer/{CustomerId}/creditcardtoken/{CanLookup}", "POST")]
public class CreditCardToken : IReturn<CreditCardTokenResponse>
{
    [ApiMember(ParameterType = "path", DataType = "string", IsRequired = true, Verb = "POST")]
    public string CustomerId { get; set; }
    [ApiMember(ParameterType = "path", DataType = "boolean", IsRequired = true, Verb = "POST")]
    public bool CanLookup { get; set; }
    [ApiMember(ParameterType = "body", DataType = "CreditCard", IsRequired = true, Verb = "POST")]
    public CreditCard CreditCard { get; set; }
}

public class CreditCard
{
    public short CreditCardTypeId { get; set; }
    public string NameOnCard { get; set; }
    public string CardNumber { get; set; }
    public string Expiration { get; set; }
    public string PostalCode { get; set; }
}

The service interface has nothing to it (I set a break point on the return null):

public class CreditCardTokenService : Service
{
    public CreditCardTokenResponse Post(CreditCardToken request)
    {
        return null;
    }
}

Using the latest version of servicestack as of the writing of this question (not .Net Core) for .Net 4.6.2.

When I populate the fields in Swagger-UI, the CreditCard object doesn't come through, its just null. Not sure what I'm missing, CustomerId, and CanLookup do come through. I tried setting DataContract / DataMember on the CreditCard class.


回答1:


Your Request DTO doesn't match the declared Swagger schema, CreditCard isn't the body it's just a parameter that has a complex type value. The entire CreditCardToken Request DTO is expected to be POST'ed as the JSON Body of the HTTP POST request whereas this definition only posts a CreditCard JSON body. The other parameters are coming through because they're sent on the path info of the request, i.e. they're not sent in the body.



来源:https://stackoverflow.com/questions/40684031/servicestack-object-parameter-not-getting-passed-to-service-with-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!