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

how to "deny" extra elements on request through the schema #12

Open
sloncho opened this issue May 9, 2016 · 1 comment
Open

how to "deny" extra elements on request through the schema #12

sloncho opened this issue May 9, 2016 · 1 comment

Comments

@sloncho
Copy link

sloncho commented May 9, 2016

using swagger-express-mw, and having a following yaml:

 /api/applications:
    x-swagger-router-controller: "applications"
    post:
      operationId: "create"
      consumes:
        - "application/json;"
      produces:
       - "application/json"
      parameters:
      - name: "body"
        in: "body"
        description: "initial application data"
        schema:
          title: NewApp
          type: object
          required:
            - "email"
            - "phoneNumber"
          properties:
            phoneNumber:
              type: "string"
            email:
              type: "string"

How do I define that additional elements are not allowed. I.e. I want to prevent posting of:

{
   "email":"bla",
   "phoneNumber":"otherbla",
   "dont": {"want":"this to pass validation"}
}

In general, I'd like to be able to enforce this for some paths, but not for others.

Cheers

@whitlockjc
Copy link
Member

In your response schema you can set additionalProperties: false and that will disallow any properties not explicitly defined in the properties section.

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