widdershins icon indicating copy to clipboard operation
widdershins copied to clipboard

Request Body Missing from Code Samples

Open bmwynne opened this issue 4 years ago • 1 comments

Describe the bug A clear and concise description of what the bug is. Reports containing a full reproduction recipe (command-line and input file gist) will get a much faster response.

Request bodies are missing from some examples; using request addPet from Petstore v1.0.0 as an example. addPet has a parameter body Pet that is required. The schema for the parameter is correctly displayed, however the generated code examples for both; Shell (curl) and Javascript (Ajax), have the body missing. Is this intended?

  • [X] - I have checked that my input document is valid OpenAPI 2.0/3.0.x or AsyncAPI 1.x

To Reproduce Steps to reproduce the behavior:

  1. Reference https://mermade.github.io/shins/?javascript#addpet
  2. See addPet Shell, Javascript, and Node.JS examples as reference to this question/bug.

Expected behavior I would expect curl example to have a body parameter;

curl -X POST http://petstore.swagger.io/v2/pet \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer {access-token} \
  -d 'const inputBody = '{"id": 0,"category": {"id": 0,
 "name": "string"},"name": "doggie","photoUrls": ["string"],"tags": [{"id": 0,"name": "string"}],"status": "available"}';'

and the same as with the Javascript example with Ajax.

var headers = {
  'Content-Type':'application/json',
  'Authorization':'Bearer {access-token}'
};

const inputBody = '{
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}';

$.ajax({
  url: 'http://petstore.swagger.io/v2/pet',
  method: 'post',
  data: inputBody,
  headers: headers,

  success: function(data) {
    console.log(JSON.stringify(data));
  }
})

It looks like the Node.js example using fetch is correctly generated (see screenshots).

Screenshots Petstore addPet Shell Screen Shot 2019-12-09 at 10 38 46 AM Petstore addPet Javascript with Ajax Screen Shot 2019-12-09 at 10 39 48 AM

Petstore addPet Javascript with Node and Fetch Screen Shot 2019-12-09 at 10 55 44 AM

Versions:

  • Node.js (note only LTS versions are supported):

Additional context Add any other context about the problem here.

bmwynne avatar Dec 09 '19 19:12 bmwynne

Hi, if you take a look at the code_... templates you will see that this behaviour is expected, even if not ideal.

The javascript template could probably easily be extended to have a JSON request body (though I haven't checked this would be the correct format for a jquery ajax call), but the format used by the curl command is probably a bit too specific to support in the main code.

Have you tried the --httpsnippet option? This should provide more detailed code samples.

MikeRalphson avatar Dec 23 '19 10:12 MikeRalphson