3

I have the following API, defined using ServiceStack, for which the documentation is not generating correctly.

public class User
{
    public string Name { get; set; }
    public int Id { get; set; }
}

[Route("/users", "PUT")]
public class UpdateUsersRequest : IReturn<List<User>>
{
    [ApiMember(DataType = "array", Description = "Users to be updated", ParameterType = "body", IsRequired = true)]
    public List<User> UsersToUpdate { get; set; }
}

public class UsersService : Service
{
    public List<User> Put(UpdateUsersRequest request)
    {
        return new List<User>();
    }
}

If I specify the ApiMember attribute (as shown above), I get the following documentation, where the description is shown correctly, but the example value is incorrect. Documentation with ApiMember attribute

Also, ServiceStack is never able to parse the body (see examples below) and I always get a SerializationException with a message:

Type definitions should start with a '{', expecting serialized type 'UpdateUsersRequest', got string starting with: ["{","
\"UpdateUsersRequest\": {"," \"Us"*.

Example 1: only the array.

[ { "Name": "string", "Id": 0 } ]

Example 2: the property.

{ "UsersToUpdate": [ { "Name": "string", "Id": 0 } ] }

Example 3: complete object.

{ 
  "UpdateUsersRequest": { 
    "UsersToUpdate": [ 
      { 
        "Name": "string", 
        "Id": 0
      }
    ]
  } 
}

I also tried not adding the ApiMember attribute, as mentioned here. This generates the example correctly, and I can use it to send values to my request. However, there is no description shown, and I get an extra row for the UsersToUpdate property.

Documentation without ApiMember attribute

If I specify any value here, it again results in a SerializationException.

My question: How can I generate the documentation correctly, such that the description and examples are shown correctly, and I do not end up with an extra useless row?

Note: I also tried creating a wrapper object around the list, but that doesn't work either and again results in a SerializationException. This will likely not be an acceptable solution as it will end up changing the existing customer scripts to execute the APIs, but mentioning it here anyway.

2
  • 1
    The error suggests that you are passing a collection rather than an object when you try to call the service. Commented Nov 21, 2023 at 14:42
  • @tomredfern I've tried all combinations, end up getting the same error unfortunately. Commented Nov 22, 2023 at 17:07

0

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.