Giter Site home page Giter Site logo

wgrisa / express-yup-middleware Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 2.0 374 KB

express-yup-middleware is an express middleware that uses Yup schemas to validate a request and return a response with errors.

License: MIT License

TypeScript 100.00%
hacktoberfest yup express middleware validation rest restful

express-yup-middleware's Issues

Unnecessary production dependencies

I have found this dependencies in your project, most of them are unnecessary:

  "dependencies": {
    "@types/express": "^4.17.3",
    "@types/yup": "^0.26.33",
    "express": "^4.17.1",
    "http-status-codes": "^1.4.0",
    "ts-node": "^8.8.1",
    "typescript": "^3.8.3",
    "yup": "^0.28.3"
  },

typescript + @types/* + ts-node - should be located in "devDepencdencies"
express + yup - are required only for "typescript types". Maybe this dependencies should be located in "peerDependecies"? or "devDependencies" also?

Access to validated results

Hi,

Thank you for writing this great module! I have a suggestion about how to improve it.

I think it would be useful to have access to the validated and typed object after validation is performed in the request handler. Right now it seems this module will perform validation but the validated objects are lost and not presented to the request handler.

By not passing the typed objects, it forces that my code works with the untyped req.body, or I can call yup.validate<DataType>(req.body) again to get a validated result that is the same type as the schema.

Rusty

Question/Bug: Response should include all the error messages but it only returns one

First, your library is very useful so thanks for putting it out there. I was thinking of writing one myself, but since I found yours I'm planning to use it.

One thing I found out while evaluating the library, and not sure if it's a bug or missing feature.

Essentially the validation seems to only be returning the first error. It looks like the response is of type Array so I'm thinking that the plan was to return all the errors?

For example with the following Yup schema:

export const SignUpSchema = Yup.object().shape({
  email: Yup.string()
    .email('Invalid email address')
    .required('An email address is required'),
  firstName: Yup.string().required(
    'In order for us to get acquainted we need to know your first name'
  ),
  lastName: Yup.string().required(
    'In order for us to get acquainted we need to know your last name'
  ),
});

When I perform a request with an empty body, the response is:

{
    "errors": {
        "body": [
            {
                "message": "In order for us to get acquainted we need to know your last name",
                "propertyPath": "lastName"
            }
        ]
    }
}

And I believe the desired outcome should be:

{
    "errors": {
        "body": [
            {
                "message": "An email address is required",
                "propertyPath": "email"
            },
            {
                "message": "In order for us to get acquainted we need to know your last name",
                "propertyPath": "firstName"
            },
            {
                "message": "In order for us to get acquainted we need to know your last name",
                "propertyPath": "lastName"
            },
        ]
    }
}

abortEarly

I'm not able to pass the {abortEarly: false} property, to list all errors at once

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.