vue-storefront-api icon indicating copy to clipboard operation
vue-storefront-api copied to clipboard

Validation - Order schema validation is broken

Open nh-mdev opened this issue 4 years ago • 0 comments

Version

vue-storefront-api 1.12.3

Scope

Checkout process > creating/submitting order via endpoint "/api/order" Entry point: "src/api/order.ts"

Affacted files

  • "src/api/order.ts"
  • "src/platform/magento2/o2m.js"

Description

Expected behaviour

The received order json object should be validated according to the json schemas: "src/models/order.schema.js" "src/models/order.schema.extension.json" (optional)

Actual behaviour

The received order json object is not properly validated against the "order.schema.js" schema.
In fact, the validation always returns true, regardless of the properties composition and values the order json object contains.

Any additional rules in "order.schema.extension.json" are correctly triggered and can lead to a failed or successful validation result.

Reproduction steps

  1. Send an empty json object to the endpoint "/api/order/" via POST request (.e.g. via POSTMAN or INSOMNIA)
  2. It will not fail due to validation errors but rather further along in the code (see picture)

image

Possible resolutions

  1. Change all occurrences of "require('../../models/order.schema.js')" to "require('../../models/order.schema.js').default"

or

  1. Change the file name of "src/order.schema.js" to "src/order.schema.json" and remove "exports.default =" from line 1.

Impact of change

  1. Most likely a breaking change and might cause widespread failure of the route endpoint, since user implementations never had to pay attention to their order json object structure.
  2. Most likely the validation rules inside "order.schema" would have to be re-tested and possibly rewritten.

nh-mdev avatar Oct 27 '20 14:10 nh-mdev