Base solution for your next web application
Open Closed

Swagger return object #8000


User avatar
0
p.j.keukens created

Hi,

I'm using Aspnetzero 6.9 for .NET Core + JQuery.

In my application I've enabled Swagger which is working fine. The only problem is that for the return object it shows the actual object that is returned from the method but aspnet zero encapsulates the object in a default response.

For example if we have simple get operation that returns a list of cars like

public List<Car> GetCars()

Then in Swagger the response message will look like:

{
    "cars": [
        { "name": "Tesla Model 3" },
        { "name": "Opel Empera-E"}
    ]
}

But the actual response is:

{
    "result": {
        "cars": [
            {
                "name": "Telsa Model 3"
            },
            {
                "name": "Opel Ampera-E",
            },
        ]
    },
    "targetUrl": null,
    "success": true,
    "error": null,
    "unAuthorizedRequest": false,
    "__abp": true
}

So is there a way to add the default return object to the response in swagger ui so that it corresponds to the actual returned result?

Best regards,

Patrick


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Why are you doing this?


    You can try using ProducesResponseType on the method.

    [ProducesResponseType(typeof(AjaxResponse<List<Car>>)]
    
  • User Avatar
    0
    p.j.keukens created

    That was what I was looking for, thanks!