GithubHelp home page GithubHelp logo

Comments (6)

tstackhouse avatar tstackhouse commented on May 27, 2024 1

Checked my config, this is actually the way to make offline and apigw work simultaneously with a schema in serverless.yml:

    events:
      - http:
          path: my/endpoint
          method: post
          request:
            schema:
              application/json: ${
                file(src/my-endpoint/post.request.schema.json),
                file(apps/my-app/src/my-endpoint/post.request.schema.json)}

using 2 file() declarations inside the ${} substitution separated by a comma provides failover should one file fail to be found.

I've actually taken to doing both validations you mention though, doing a basic validation at the APIGW level and then doing more complex schema validations deeper in my code, just before my business logic at the API layer. Partly due to the fact that the implementation of schemas on APIGW leave something to be desired in comparison with e.g. AJV. things like oneOf rules don't work as expected and lots of little gotchas in complex schemas that I don't recall off the top of my head.

from nx-plugins.

brian-weasner avatar brian-weasner commented on May 27, 2024

Note: Not the same as dherault/serverless-offline#894, as I am expecting serverless to find the schema, and at least use it when deployed.

from nx-plugins.

tstackhouse avatar tstackhouse commented on May 27, 2024

I've ran into this, I don't have the code in front of me, but the workaround is to do something like this in your serverless.yml

functions:
  location:
    handler: src/controllers/location.saveLocation
    events:
      - http:
          path: location
          method: post
          request:
            schemas:
              application/json:
                - ${file(src/schemas/location.json)}
                - ${file(apps/my-app/src/schemas/location.json)}

The syntax might be different, I'd have to look at my config at $WORK, but that's the gist, you need to define the path twice, once for offline and once for APIGW, because of path resolution differrences. You might also need to make sure that the packaging step is including your schema in the generated zip file.

from nx-plugins.

brian-weasner avatar brian-weasner commented on May 27, 2024

I decided against this approach as I couldn't get it to work, and we want validation working locally with serverless-offline, so we decided to do request body validation in our lambda functions.

Thank you for the pointers though in case anyone else runs across this. Gonna keep this issue open, as it is an issue, just no longer an issue for me as I am not using this functionality.

from nx-plugins.

wickstargazer avatar wickstargazer commented on May 27, 2024

can we close this?

from nx-plugins.

brian-weasner avatar brian-weasner commented on May 27, 2024

Yeah, I think so. there is a workaround in place and honestly I decided to just use the latest version of AJS within my code so I could handle the response body to send back to the calling client.

from nx-plugins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.