serby / schemata

Define, create, and validate your business objects based on specified schema.
45 stars 16 forks source link

Progress on dealing with schemata.Array(<PrimitiveType>) #37

Closed bengourley closed 8 years ago

bengourley commented 8 years ago

:rotating_light: :warning: Work in progress :warning: :rotating_light:

There is currently a feature gap with casting for arrays of simple/primitive types.

Given the following schema:

{ name: { type: String }, scores: { type: schemata.Array(Number) } }

schemata.cast(obj) will not cast…

{ name: 'Ben', scores: [ '6', '3', '6' ] }

…into…

{ name: 'Ben', scores: [ 6, 3, 6 ] }

Not only would I expect this behaviour, it's also rather difficult to fix from outside schemata. It's quite common to be receiving numerical input as strings from HTML form values. If schemata won't cast these types then type information must leak out from the schema into somewhere else in the application.

As mentioned, this is a work in progress so please do not merge (I actually rediscovered this work as uncommitted changes the other day when fixing a different issue).

Things outstanding:

With these changes so far, the current test suite still passes, but the code coverage has fallen below the threshold.

bengourley commented 8 years ago

cc @balaclark. This is dedicated to you and #26.

serby commented 8 years ago

Just started reviewing :)

:octocat: Sent from GH.

serby commented 8 years ago

Thank you, pull request merged! See changes here.

:octocat: Sent from GH.

bengourley commented 8 years ago

@serby you picked a bad PR to try that GH module out on… see the title ^^^

serby commented 8 years ago

DOH! I picked the wrong number