Translations:NPM module - izara-middleware/32/en: Difference between revisions

From Izara Wiki
Jump to navigation Jump to search
(Importing a new version from external source)
 
(No difference)

Latest revision as of 04:33, 4 October 2022

Information about message (contribute)
This message has no documentation. If you know where or how this message is used, you can help other translators by adding documentation to this message.
Message definition (NPM module - izara-middleware)
We use the validator middleware to:
# validate input is the correct type etc..
# define defaults for optional properties
# strip out unexpected properties using <syntaxhighlight lang="JavaScript" inline>ajvOptions: { removeAdditional: true }</syntaxhighlight> option and <syntaxhighlight lang="JavaScript" inline>"additionalProperties: false"</syntaxhighlight> in the schema
# juggle the location of properties in the request, eg for API requests the current userId will be placed in the requestContext.authorizer.principalId property, we move it to the event.userId location. After moving the userId property we also remove the requestContext property as we have no other use for it in our code.

We use the validator middleware to:

  1. validate input is the correct type etc..
  2. define defaults for optional properties
  3. strip out unexpected properties using ajvOptions: { removeAdditional: true } option and "additionalProperties: false" in the schema
  4. juggle the location of properties in the request, eg for API requests the current userId will be placed in the requestContext.authorizer.principalId property, we move it to the event.userId location. After moving the userId property we also remove the requestContext property as we have no other use for it in our code.