Chapter 3 · Part I — The application model

Give values a precise meaning

A measured offset is more than a number. It has a unit, a permitted range, an origin, and a time at which it becomes part of a reviewed record. A type declaration supplies part of that meaning. The rest belongs in the model and its explanation.

The calibration example stores offsetMicrounits as an integer. The name carries the unit into API responses, tests, and code reviews. This avoids introducing floating-point rounding into the teaching example. It does not establish that every instrument can be represented in these units or that converting a physical measurement to this integer is correct.

Required, defaulted, and immutable

These field properties solve different problems. required says a value must be present under the applicable validation rules. A default supplies a value when the creation path applies defaults. immutable constrains later changes. None makes a client-supplied value truthful.

The following fragment binds three values into a saved candidate:

instrumentId: { type: uuid, required: true, immutable: true }
revision: { type: integer, required: true, min: 1, default: 1, immutable: true }
offsetMicrounits: { type: integer, required: true, immutable: true }

A missing revision can become 1 on create. Once saved, the reading’s identity and measured content are stable under the supported mutation paths. A technician who discovers an error creates another candidate. This choice makes review binding easier to explain than a mutable record with several independent version counters.

An immutable field can be ignored rather than rejected on a particular write path. In the inspected transition handler, body values for immutable fields are excluded from the values written. A transition response can therefore succeed while an attempted measurement replacement has no effect. A correct test reads the resulting record. HTTP refusal is only one possible way to preserve a value.

Enumerations describe a vocabulary

The example declares CalibrationStatus with draft, submitted, certified, and rejected values. The field refers to that enumeration through $ref: "#/enums/CalibrationStatus". A named enumeration collects vocabulary in one place and gives interface consumers labels to show.

The enumeration does not define the transition graph. An enum value being valid does not mean a caller may assign it directly, and an enum member marked final does not replace the state-machine rules. The state machine in Chapter 7 defines the permitted movement; permissions protect the operations that could otherwise write the field.

This distinction prevents a common modeling shortcut. If a form shows only valid status choices, it is still a client. A caller can submit a value without using that form. The server must enforce the operation contract.

Null is not a default and absence is not authority

A missing property, an explicit null, an empty string, and a false boolean can follow different paths through validation and expression evaluation. Test the specific boundary you intend to rely on. Do not infer that required also rejects every semantically empty value in every type.

Similarly, submittedBy being absent in a draft is sensible; its absence after submission is a model failure. The application records it through transition sets, using the authenticated actor. Requiredness on the field alone would either reject valid drafts or force the client to supply provenance it should not control.

Keep storage representation in the investigation

An API may accept a numeric literal and still store or return it differently. Exact monetary values, large integers, time zones, and decimal scale deserve round-trip tests on each supported store. A schema export shows an intended representation; an inserted and retrieved value shows what the configured path actually did.

The example uses moderate integer values to keep this question bounded. It is not a general endorsement of integer microunits for every scientific domain. Select the representation from the required precision and range, then test the complete ingestion and retrieval path.

ADL 10 owns field types and constraints; ADL 11 owns enumerations. The current enum-diagnostic fix is discussed in Chapter 17 as a lesson in retaining descriptive metadata without treating it as a field restriction.

Workshop

Choose a measurement whose range exceeds the handbook’s example. State its unit, maximum magnitude, and required precision. Propose a representation, then list the round trips you would test before calling that representation reliable.