1
votes

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.

enter image description here

1

1 Answers

3
votes

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.