Skip to content

📝 [Proposal]: Add options for active DisallowUnknownFields in the function BodyParser #2858

Description

@solrac97gr

Feature Proposal Description

Add options object for active the DisallowUnknownFields in the BodyParser for more strict parsing to a struct in cases where is required.

Alignment with Express API

BodyParser middleware for JSON in express permit you to add different options that affect the parsing

HTTP RFC Standards Compliance

Confirmed

API Stability

DisallowUnknownFields is a native functions of the Decoder from native Go package json

Feature Examples

type Cat struct {
     Name
}


POST /cats
{
  “Name”: “lasagna”
   “Age”: 3
}

Response:
Error the request body not match exactly the struct of Cat
p := new(Person)
if err := c.BodyParser(p,Options{DisallowUnknownFields:true}); err != nil {
   return err
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions