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

Request validation is not working with sls offline, but it is working in API Gateway #894

Closed
qds-bhanwarlal opened this issue Feb 13, 2020 · 4 comments

Comments

@qds-bhanwarlal
Copy link

qds-bhanwarlal commented Feb 13, 2020

Request validation is not working with severless-offline but it is working in API Gateway after deployment

Serverless Framework Version

Framework Core: 1.63.0
Plugin: 3.3.0
SDK: 2.3.0
Components Core: 1.1.2
Components CLI: 1.4.0

Packages Version

"serverless-reqvalidator-plugin": "^1.0.3"
"serverless-aws-documentation": "^1.1.0",
"serverless-offline": "^5.12.1",

serverless.yml

service:
  name: my-service

plugins:
  - serverless-reqvalidator-plugin
  - serverless-aws-documentation
  - serverless-offline

provider:
  name: aws
  runtime: nodejs12.x
  stage: dev
  region: us-east-1
  memorySize: 128
  environment:
    NODE_ENV: development

custom:
  documentation:
    api:
      info:
        version: '1.0.0'
        title: My API
        description: This is my API
      tags:
        -
          name: User
          description: User Management
    models:
      - name: MessageResponse
        contentType: "application/json"
        schema:
          type: object
          properties:
            message:
              type: string
      - name: RegisterUserRequest
        contentType: "application/json"
        schema:
          required: 
            - email
            - password
          properties:
            email:
              type: string
            password:
              type: string
      - name: RegisterUserResponse
        contentType: "application/json"
        schema:
          type: object
          properties:
            result:
              type: string
      - name: 400JsonResponse
        contentType: "application/json"
        schema:
          type: object
          properties:
            message:
              type: string
            statusCode:
              type: number
  commonModelSchemaFragments:
    MethodResponse400Json:
      statusCode: '400'
      responseModels:
        "application/json": 400JsonResponse

functions:
  signUp:
    handler: handle.singup
    events:
      - http:
          documentation:
            summary: "Register user"
            description: "Registers new user"
            tags:
              - User
            requestModels:
              "application/json": RegisterUserRequest
          method: post
          path: signup
          reqValidatorName: onlyBody
          methodResponses:
            - statusCode: '200'
              responseModels:
                "application/json": RegisterUserResponse
            - ${self:custom.commonModelSchemaFragments.MethodResponse400Json}

package:
  include:
    api/users.js

resources:
  Resources:
    onlyBody:  
      Type: "AWS::ApiGateway::RequestValidator"
      Properties:
        Name: 'only-body'
        RestApiId: 
          Ref: ApiGatewayRestApi
        ValidateRequestBody: true
        ValidateRequestParameters: false

Followed the same example mentioned in serverless-requestvalidator-plugin
Ref: https://stackoverflow.com/a/49143822/11141189

Also tried validation without serverless-requestvalidator-plugin used https://serverless.com/framework/docs/providers/aws/events/apigateway#request-schema-validators but it did worked with serverless-offline.

@ItayElgazar
Copy link

Any news with this one?

@qds-bhanwarlal
Copy link
Author

No, did research but didn't got anything, if you get please share with me also.
Thank you.

@dherault
Copy link
Owner

What about serverless-offline v6, does it solve your issue?

@sthuber90
Copy link

Isn't it related to #734 and wasn't with the removal of PR #589 also the request validation removed?

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

4 participants