7

I'm having issues with displaying the correct notes in swagger using ServiceStack.

Given this structure:

    [Route("/Widget/{WidgetId}", Summary = "Updates a widget by id", Verbs = "POST",
    Notes = "Updates a widget by id.")]
    public class UpdateReqWidget : IReturnVoid
    {
        [ApiMember(Name = "WidgetId", Description = "The id of widget to delete.")]
        public int WidgetId { get; set; }
    }

    public class WidgetService 
    {
        public void Put(UpdateReqWidget req)
        {
             //do code here
        }
    }

It's producing: Swagger UI Error

I would expect the parameters list only to have WidgetId, but it's displaying WidgetId and UpdageReqWidget, the class name for the request. any ideas what I'm doing wrong?

EDIT: I'm using versions 3.9.55 for both ServiceStack and ServiceStack.API.Swagger. I've changed the templates to better suit our needs.

2
  • What version of ServiceStack and ServiceStack.Api.Swagger do you have installed? The behavior you describe sounds like a recent version, but the screen shot shows an older version of the Swagger UI elements. Commented Jul 26, 2013 at 12:27
  • using 3.9.55 on both. I changed the templates for swagger to make the data type behavior so that when there's a type body, it allows you to "click for details" and that will give you the data structure. Commented Jul 26, 2013 at 13:02

1 Answer 1

6

There is a recent addition to ServiceStack.Api.Swagger to automatically generate a request body parameter in the Swagger UI. I think there's an edge case in which the request DTO has no properties that aren't designated as path or query parameters, as in your case here, the code will still generate that UpdateReqWidget request body parameter, but it will be an empty object in Swagger.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your reply. Normally for update requests, I probably wouldn't pass in just an int, nor return void. This also happens on the DELETE verb as well (which is where I discovered the problem) which I don't think would necessarily be an edge case... you would delete a record based on a unique id. Is there an easy fix to this?
You are correct that this would happen with the DELETE verb with the current ServiceStack code. Looks like there could be some improvements to this.
So in short, are you saying that I can't really fix this out of the box? If that's true, I can try and figure out a workaround.
Correct, I think ServiceStack will need a pull request to suppress this request body param in certain cases. As a workaround, since you're already customizing the Swagger UI code, you could make a JS change to hide request body parameters when their associated Models have no properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.