Hello,
I am using ServiceStack 5.1.0 with Visual Studio 2017, .NET Framework 4.7.1.
I tested the OpenAPI plugin to get some Metadata, with which we can build REST clients for other programming languages.
I think I found a bug in this plugin. Unfortunately, I cannot upload a demo project, so I try to show the relevant code here.
In some cases, I am using classes in the response, which are derived from a generic List. In this cases, the OpenAPI plugin produces wrong output.
Type A:
public class TypeA
{
public int MyPropertyA { get; set; }
}
public class ResponseA
{
public List<TypeA> ListA { get; set; }
}
[Route("/typeA", "GET")]
public class GetTypeA : IGet, IReturn<ResponseA>
{
}
Type B:
public class TypeB
{
public int MyPropertyB { get; set; }
}
public class TypeBList : List<TypeB>
{
// Some other helper functions, e.g. Get max MyPropertyB of all items
}
public class ResponseB
{
public TypeBList ListB { get; set; }
}
[Route("/typeB", "GET")]
public class GetTypeB : IGet, IReturn<ResponseB>
{
}
Service:
public class MyServices : Service
{
public object Get(GetTypeA request)
{
var result = new ResponseA();
result.ListA = new List<TypeA>();
result.ListA.Add(new TypeA() { MyPropertyA = 1 });
result.ListA.Add(new TypeA() { MyPropertyA = 2 });
return result;
}
public object Get(GetTypeB request)
{
var result = new ResponseB();
result.ListB = new TypeBList();
result.ListB.Add(new TypeB() { MyPropertyB = 1 });
result.ListB.Add(new TypeB() { MyPropertyB = 2 });
return result;
}
}
When running the example and calling
http://localhost:8080/typeA?format=json
and
http://localhost:8080/typeB?format=json
produces the same JSON output - as expected:
{"ListA":[{"MyPropertyA":1},{"MyPropertyA":2}]}
{"ListB":[{"MyPropertyB":1},{"MyPropertyB":2}]}
But when I look at the OpenAPI output at
http://localhost:8080/swagger-ui/
it produces different models for TypeA and TypeB. In TypeB, it shows some properties “Capacity”, “Count” and “Item”, which are members of the List class.
On the other hand, I cannot see, that TypeB contains any kind of List or Array of elements.
So I think the model of TypeB is incorrect, as it does not match to the generated JSON.
By the way: The same happens, when I use the Swagger plugin instead of OpenAPI.
Best regards,
Daniel