swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.36k stars 8.92k forks source link

swagger post won't work #2559

Closed livia1411 closed 7 years ago

livia1411 commented 7 years ago

I am new to swagger and trying to figure out how to post things to the API. I do a get request to the API for originalName=Walmart and get the following format when I press "Try it out":

[
  {
    "authorId": 1,
    "originalName": "Walmart",
    "englishName": "Walmart",
    "location": null,
    "authorContacts": [],
    "authorTags": [],
    "authorLanguages": [],
    "authorSites": [],
    "authorChatGroups": [],
    "authorNames": []
  }
]

Next, I try to post something similar. So I copy the text above into the "post" box in the UI, change the authorId to 2, and press "Try it out". However, I get this:

Response Body

no content

Response Code

0

Response Headers

{ "error": "no response from server" } Any idea what could be going on? Thanks.

webron commented 7 years ago

Hard to tell without the spec itself. You can check the console and network tabs for more details.

fehguy commented 7 years ago

Need more info to help

PvAsh commented 7 years ago

Hi @fehguy I am experiencing the same problem is it possible tp open this issue please. I have major issue as another developer has done this and left. so I need to check why POST is not working as expected!

When swagger is posting the object is always null. IF I change the content-type to content-type application/x-www-form-urlencoded I get the object parameters with null values still. Any helo would be good. I an working on ASP.net , ASP webapi.

fehguy commented 7 years ago

please share the specification so we can help, without it there's nothing we can do. Many, many people use POST successfully so this is something specific to your situation, and that can only be guided with the json or yaml specification.

PvAsh commented 7 years ago

@fehguy Thanks you for the reply. I have webapicontroller method

public HttpResponseMessage Post([FromUri] long partnerId, [FromUri] long companyId, [FromBody] AddDriver driver) { ... }

the swagger works well for FromURI parameters but driver is always null and its a FromBody parameter. As I Said this is developed by some one and just left so I need to work with no much info. attached the api document screen shot.

swagger_1

I have tried changing the contentType to /x-www-form-urlencoded then the object Driver is recognized but all its properties are still null. I am using Fiddler to test this. Let me know if you need further info please.

webron commented 7 years ago

@PvAsh we need the spec, not your code.

PvAsh commented 7 years ago

ok. the spec is I want to add a new car - driver to the system. created an object adddriver its a complex type. but when I post method and pass the parameters the Frombody parameter is always null. It should be what I have posted. Am I missing something here? Does that help.. :(