Spec fragments & dependencies
7 min · 55 XP · Read → Check → Complete
Factor out what repeats
A spec fragment is a reusable piece of a specification published to Exchange as its own asset — a data type, a trait, a security scheme, a library. Other specs declare it as a dependency and pull it in.
RAML example — a shared library consumed via uses
#%RAML 1.0
title: Orders API
uses:
common: exchange_modules/com.acme/common-types/1.0.0/common-types.raml
/orders:
post:
body:
application/json:
type: common.OrderWhy it matters
- One definition of
Order,Error, orPaginationacross every API. - Fix a shared type once; dependents adopt the new version deliberately.
- Smaller, cleaner specs that are easier to review and govern.
Dependencies are versioned
When you add a fragment, Exchange records the exact version as a dependency. Upgrading is an explicit act — you bump the dependency, you do not get silently changed underneath.
Coaching note
Start fragments with the obvious shared shapes — common error envelope, pagination, standard headers. Over-fragmenting early creates ceremony; let reuse emerge from real repetition.
1. What is a spec fragment?
2. How does a spec adopt a new version of a fragment it depends on?
3. What is the benefit of factoring common shapes into fragments?
4. In RAML, how are fragment dependencies declared?
5. What should you coach about starting with fragments?
6. What makes specs that use fragments easier to work with?