Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

How to define body param as required? #187

Closed
royts opened this issue Jan 11, 2015 · 2 comments
Closed

How to define body param as required? #187

royts opened this issue Jan 11, 2015 · 2 comments

Comments

@royts
Copy link

royts commented Jan 11, 2015

hi,
in my resources definition I have a POST endpoint to create an entity.
I didn't saw any documentation about body params, but i tried swagger.bodyParam and it worked.

I wonder, how can I define some properties as required and return 404 if they are not sent?

here is my endpoint definition:

createNew: {
    'spec': {
      "description": "Operations about swimmer",
      "path": "/swimmer",
      "notes": "",
      "summary": "Create a new swimmer",
      "method": "POST",
      "parameters": [
        swagger.bodyParam("swimmer", "", "Swimmer")

      ],
      "type": "Swimmer",
      "errorResponses": [swagger.errors.invalid('id'), swagger.errors.notFound('swimmer')],
      "nickname": "createSwimmer",
      produces: ["application/json"]
    },
    'action': function (req, res, next) {
    // do something - don't arrive here is some properties are not sent
      res.sendStatus(200);
    }
  }
@fehguy
Copy link
Contributor

fehguy commented Jan 12, 2015

Hi, you can make a parameter required, and the UI will not allow you to submit without it being passed. The server, however, is up to you to throw the 404 (or more appropriately 400) if it's not passed outside of swagger ui.

@fehguy
Copy link
Contributor

fehguy commented Jun 3, 2015

This is handled in #209 The spec is the source of truth

@fehguy fehguy closed this as completed Jun 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants