vuestorefront / vue-storefront-api

Vue.js storefront for Magento2 (and not only) - data backend
https://www.vuestorefront.io
MIT License
348 stars 338 forks source link

Validation - Order schema validation is broken #532

Open nh-mdev opened 3 years ago

nh-mdev commented 3 years ago

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

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

2) 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.