Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

PUT displays as POST on Swagger UI? #3871


User avatar
0
fguo created

I create a service "EditCustomer", which is very similar as "EditPerson" in PhoneBook example. It works fine, but the API shows on Swagger UI as POST (green bar), instead of PUT (brown bar). What did I miss?

The only thing different is that, the "Person" entity inherent from FullAuditedEntity and IMustHaveTenant, but my "Customer" entity inherent from Entiy only. Is that the reason? If so, how do I work around it?

Thanks,


6 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ fguo,

    Can you try to change your metod name to UpdateCustomer and see if it is displayed as PUT ?

  • User Avatar
    0
    fguo created

    It does the trick! Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)

  • User Avatar
    0
    alexanderpilhar created

    Is there a way to make swagger map actions/methods that start with "Edit" to PUT? Some configuration option maybe? I can't find any information on that.

    I started working with AspNetZero by following your step-by-step-guide using "Edit" all the time. I just encountered the fact that swaggers maps them all to POST. Changing every action/method to start with "Update" is quite some task at the point where i am now ...

  • User Avatar
    0
    aaron created
    Support Team

    From the ASP.NET Core documentation's Application Services as Controllers section:

    You can use any ASP.NET Core attributes to change the HTTP methods or routes of the actions. This requires you to add a reference to the Microsoft.AspNetCore.Mvc.Core package.

    [HttpPut]
    public async Task EditCustomer(EditCustomerDto input)
    

    Or you can do it by convention: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2939

  • User Avatar
    0
    alexanderpilhar created

    Thanks aaron :D I did try to use the attributes but couldn't figure out which reference I was missing - thank you very much for pointing it out!