Skip to content

In action

The output below is printed by the tool, not written by hand: a checkout service that consumes the catalog service in two versions, run on three small spec sheets. It is the output of valerify 0.4.0, the release that the pipeline of this site runs on the sheets and compares with what is shown. The sheets are written in the state valerify/v1 of the format; 0.5.0 changes the state to valerify/v0.1 and refuses the old one, so this page is regenerated with that release. The findings and the exit status are what matters.

The consumer states what it relies on. expected fields must be there, accepted fields are used when they are there.

// checkout.json, needs from shop/catalog, document Product
"sku":   { "classification": "expected", "type": { "scalar": "string" },  "nullable": false }
"price": { "classification": "expected", "type": { "scalar": "float64" }, "nullable": false }
"tags":  { "classification": "accepted", "type": { "array": ... }, "nullable": false }

The provider at 3.0.1: it fits

The provider sends price as a float32, the consumer reads a float64. Every value survives, so this is a warning, not an error.

$ valerify check checkout.json --upstream shop/catalog=catalog-3.json
valerify check shop/checkout 2.3.0
configuration: the built-in defaults

exchange 1, checked as the consumer: shop/checkout 2.3.0 (consumer) needs shop/catalog 3.0.1 (provider)
  the other spec sheet is catalog-3.json
  mode: gate, an error fails the run

  warning[numeric-widening] document Product, field price
    the provider does not satisfy the consumer: the provider sends `float32`, the consumer receives `float64`: every value arrives unchanged, but the types differ

  0 errors, 1 warning, 0 infos

result: fits

Exit status 0.

The provider at 4.0.0: it does not

Between the two versions the provider turned price into text, let sku become null and dropped tags.

$ valerify check checkout.json --upstream shop/catalog=catalog-4.json
valerify check shop/checkout 2.3.0
configuration: the built-in defaults

exchange 1, checked as the consumer: shop/checkout 2.3.0 (consumer) needs shop/catalog 4.0.0 (provider)
  the other spec sheet is catalog-4.json
  mode: gate, an error fails the run

  error[type-changed] document Product, field price
    the provider does not satisfy the consumer: the provider sends `string`, the consumer receives `float64`

  error[null-not-accepted] document Product, field sku
    the provider does not satisfy the consumer: the provider may send `null`, the consumer doesn't accept it

  warning[field-removed] document Product, field tags
    the provider does not satisfy the consumer: the field is not offered, the consumer uses it when it is there

  2 errors, 1 warning, 0 infos

result: does not fit (1 exchange fails)

Exit status 1. The dropped tags field is only a warning because the consumer classified it as accepted; removing sku, which is expected, gives an error[field-removed].

Spec sheets are read strictly

A document that is not exactly what the format says is rejected with its position, instead of being interpreted generously.

$ valerify validate invalid.json
invalid.json: line 11, column 17, `offers.documents`: an empty value is not allowed, omit the key instead

Exit status 1.