Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attemping to parse body when using formData #82

Open
ninemind opened this issue Oct 23, 2015 · 1 comment
Open

Attemping to parse body when using formData #82

ninemind opened this issue Oct 23, 2015 · 1 comment

Comments

@ninemind
Copy link

When creating my swagger.yaml I have decided to use formData for creating users. So /users POST would contain the following parameters.

  parameters:
    -
      name: first_name
      in: formData
      description: First name
      required: true
      type: string
      x-example: Jane
    -
      name: last_name
      in: formData
      description: Last name
      required: true
      type: string
      x-example: Doe
    -
      name: username
      in: formData
      description: Username
      required: true
      type: string
      x-example: janedoe
    -
      name: password
      in: formData
      description: Password
      required: true
      type: string
      x-example: abc123

According to the swagger spec and all the examples I've seen this is how you're supposed to do this, however I get an "invalid json" error because it's trying to parse the body, which doesn't exist. I have gotten the in: body type to work by including body-parser in my project. Without it even the in: body type fails saying that "body is required".

var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(swaggerize({
    api: './app/docs/swagger.yml',
    docspath: '/',
    handlers: path.resolve('./app/handlers')
}));

Is body-parser causing the conflict? If so, how can I remove body parser and have both in: body and in: formData work?

@tlivings
Copy link
Contributor

You must include any parsing middleware before swaggerize - which is only handling routing & validation, not parsing.

Does form data not work with the body parser for urlencoded? It isnt clear from the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants