← Schemas Academy

Build the solution · 3 / 5

Require useful package measurements

Describe a delivery with at least one positive package weight.

YOUR TASK

Make this happen

3 steps
  1. Add required packages: a nonempty array of objects, each requiring positive numeric weightKg and rejecting extra fields.

  2. Keep the working capabilities from the previous lesson and connect the new pieces to the same solution.

  3. Check the complete solution, then inspect any unmet requirements.

This step starts with the earlier solution and one new challenge. Each lesson keeps its own draft.

Read the starter files

main.cococo

external_schema "supplier" {
  name = "Supplier delivery contract"
  format = "JSON_SCHEMA"
  sourceText = file("contract.json")
}

contract.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Supplier delivery",
  "type": "object",
  "properties": {
    "trackingId": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "type": "string",
      "enum": [
        "dispatched",
        "delivered"
      ],
      "default": "dispatched"
    }
  },
  "required": [
    "trackingId"
  ],
  "additionalProperties": false
}

Reference: schemas · authoringschemas · external-schemas