Metadata and Views
Your coffee machine model is built. It has structure, behavior, states, constraints, requirements, and verification cases. But models do not exist in isolation. People need to review them, approve them, and understand them – and different people care about different things.
This chapter covers two features that serve that human side of modeling: metadata for attaching governance information to model elements, and views for presenting the right slice of the model to the right stakeholder.
Comments vs. doc vs. Metadata
You have already used // comments throughout the model. Comments are notes in the source text. A tool ignores them during analysis. They are for the person reading the .sysml file, not for the model itself.
SysML v2 provides two more layers for human-oriented information, and the distinction matters.
doc is a model-level documentation string. Unlike a comment, doc is part of the model. A tool can extract it, display it in a hover tooltip, or include it in a generated report. You place it inside the element it describes:
part def Brewer {
doc /* Heats water and forces it through ground coffee
under controlled pressure and temperature. */
attribute waterTemp : Real;
attribute brewPressure : Real;
}
Metadata is structured, queryable data attached to model elements. Review status, maturity level, safety classification, responsible team – these are not free text. They have known fields and known values, and you need to filter or report on them. Metadata is the right tool for that job.
The rule of thumb: if it must be queried, filtered, or enforced by tooling, make it metadata. If it explains intent to a human reader, use doc. If it is a local note to yourself, use a comment.
Defining Metadata
A metadata definition looks like any other definition in SysML v2. You declare it with metadata def, and it can have attributes:
package CoffeeMachineGovernance {
private import ScalarValues::*;
metadata def ReviewStatus {
attribute status : String;
attribute reviewer : String;
}
metadata def SafetyClass {
attribute level : String;
}
}
ReviewStatus is now a reusable type. It says: anything that carries a review status has a status string and a reviewer string. You define it once, in one package, and every team uses the same structure.
This is important. If one team invents ReviewInfo with a state field and another invents ApprovalStatus with a currentStatus field, you end up with incompatible schemas that no tool can query uniformly. Centralize your metadata definitions early.
Annotating Elements with Metadata
To attach metadata to a model element, you use the @ annotation syntax. Use about when the annotation is declared alongside its target:
package CoffeeMachineStructure {
private import ScalarValues::*;
private import CoffeeMachineGovernance::*;
@ReviewStatus about CoffeeMachine {
:>> status = "approved";
:>> reviewer = "Systems Team";
}
part def CoffeeMachine {
doc /* Top-level system definition for the Smart Coffee Machine. */
part grinder : Grinder;
part brewer : Brewer;
part waterTank : WaterTank;
attribute serialNumber : String;
}
}
The @ReviewStatus about CoffeeMachine { ... } block annotates the CoffeeMachine definition. The :>> syntax redefines the metadata attributes with specific values. After this annotation, any tool that queries the model can determine that CoffeeMachine has been approved by the Systems Team.
You can annotate any element – definitions, usages, requirements, actions, states. The about clause explicitly identifies the target; inside the element you can instead omit it:
@SafetyClass about SafetyInterlockReq { :>> level = "SIL-2"; }
requirement def SafetyInterlockReq {
doc /* The machine shall disable the heater if water
temperature exceeds 100 degrees Celsius. */
}
Now the safety interlock requirement carries its safety integrity level as structured data, not as a note buried in a comment.
Multiple Annotations
An element can carry more than one annotation. Stack them:
@ReviewStatus about Brewer {
:>> status = "in-review";
:>> reviewer = "Safety Board";
}
@SafetyClass about Brewer { :>> level = "SIL-2"; }
part def Brewer {
doc /* Heating subsystem. Under safety review. */
attribute waterTemp : Real;
attribute brewPressure : Real;
}
The Brewer now carries both governance metadata and safety classification. A review dashboard could show all elements where status is "in-review", or all elements classified as SIL-2.
A Maturity Tracking Example
Metadata is especially useful for tracking model maturity across a project lifecycle. Here is a pattern that covers the typical progression:
package CoffeeMachineGovernance {
private import ScalarValues::*;
metadata def ReviewStatus {
attribute status : String;
attribute reviewer : String;
}
metadata def SafetyClass {
attribute level : String;
}
metadata def MaturityLevel {
attribute level : String;
}
}
Then, as the model evolves, annotations track where each element stands:
@MaturityLevel about BrewCycle { :>> level = "preliminary"; }
action def BrewCycle;
@MaturityLevel about WaterTank { :>> level = "baselined"; }
part def WaterTank;
@MaturityLevel about BrewTempReq { :>> level = "verified"; }
requirement def BrewTempReq;
A project manager does not need to understand the brew cycle control flow to know that the action definition is still preliminary. The metadata tells them directly.
From Metadata to Views
Metadata tells tools about the status of individual elements. But stakeholders do not review individual elements. They review slices of the model that are relevant to their concerns. A safety engineer cares about hazards, interlocks, and safety-classified requirements. An architect cares about structural decomposition and interfaces. Showing either of them the entire model is counterproductive.
SysML v2 formalizes this with two concepts: viewpoints and views.
Viewpoints: Defining Stakeholder Concerns
A viewpoint declares what a particular stakeholder cares about. It does not select specific model elements – it describes the kind of information that matters for a particular review purpose.
package CoffeeMachineViews {
viewpoint def SafetyViewpoint {
doc /* Concerns: hazard mitigations, safety interlocks,
and safety-classified requirements. */
}
viewpoint def ArchitectureViewpoint {
doc /* Concerns: structural decomposition, subsystem
interfaces, and key part definitions. */
}
}
Think of a viewpoint as a lens. SafetyViewpoint says: when you look through this lens, you want to see safety-related elements. ArchitectureViewpoint says: through this lens, you want to see structure.
A viewpoint can also specify stakeholder to name who uses it, and purpose to explain why:
viewpoint def VerificationViewpoint {
doc /* Requirement-to-test traceability for verification closure. */
}
Views: Selecting Model Content
A view usage is the concrete selection. It is typed by a view def, can satisfy one or more viewpoints, and uses expose to pull specific elements into the view.
Before getting into stakeholder-specific views, it helps to see the simplest possible case: one view definition, one usage, one expose. This is the running anchor we will refine through the rest of the chapter.
package CoffeeMachineViews {
private import CoffeeMachineStructure::*;
view def CoffeeOverview;
view overview : CoffeeOverview {
expose CoffeeMachine;
}
}
That’s a complete, valid view: a definition that names the kind of view, and a usage that picks up the definition and exposes the top-level part. Anything that walks the model can ask “what does the overview view contain?” and get back the CoffeeMachine element and – by transitive containment – everything inside it.
The definition supplies a reusable recipe (filter, render); the usage selects concrete content with expose. An exposed element remains owned by its original namespace.
Now, the more interesting case. A view usage can satisfy one or more viewpoints, and can expose more than one element. satisfy reaches a viewpoint because a ViewpointDefinition is a RequirementDefinition in the abstract syntax – satisfying a viewpoint and satisfying a requirement are the same relationship:
package CoffeeMachineViews {
private import CoffeeMachineStructure::*;
private import CoffeeMachineRequirements::*;
viewpoint def SafetyViewpoint {
doc /* Concerns: hazard mitigations and safety interlocks. */
}
viewpoint def ArchitectureViewpoint {
doc /* Concerns: structural decomposition and interfaces. */
}
view def SafetyReviewView;
view def ArchitectureReviewView;
view safetyReview : SafetyReviewView {
viewpoint perspective : SafetyViewpoint;
expose CoffeeMachineRequirements::SafetyInterlockReq;
expose CoffeeMachineRequirements::BrewTempReq;
}
view architectureReview : ArchitectureReviewView {
viewpoint perspective : ArchitectureViewpoint;
expose CoffeeMachineStructure::CoffeeMachine;
expose CoffeeMachineStructure::Brewer;
expose CoffeeMachineStructure::Grinder;
expose CoffeeMachineStructure::WaterTank;
}
}
expose is the key operation. It does not copy the element into the view. It references it. The safetyReview view usage satisfies SafetyViewpoint and exposes two requirements. The architectureReview view usage satisfies ArchitectureViewpoint and exposes four structural definitions. A tool rendering the safety review shows only the safety requirements – the grinder and its grind settings are nowhere in sight.
This is the critical difference between a view and a package. A package owns its members. A view exposes references to members that live elsewhere. The underlying model is unchanged. Views are projections, not copies.
Two flavours of expose: member and namespace
expose comes in two forms, and the choice is more than syntactic sugar.
view interfaceReview : ArchitectureReviewView {
expose CoffeeMachineStructure::Brewer; // member expose
expose CoffeeMachineStructure::*; // namespace expose
}
The first form is a member expose: it pulls one named element into the view. The second is a namespace expose: it pulls every member of the named namespace into the view. The trailing ::* is the cue.
Member expose is precise; namespace expose is sweeping. You reach for namespace expose when the natural unit of review is a whole package – the safety package, the requirements package, the API surface – and you do not want the view to drift behind the package as new elements are added. Once CoffeeMachineStructure::* is exposed, anything new you drop into that package is automatically visible in the view.
Both forms are subject to the same qualified-name resolution. If you misspell the qname, the view exposes nothing for that line. There is no error – the line is parsed, the qname does not resolve, and tools simply have nothing to show. That silent failure mode is one of the more common authoring mistakes; we return to it in Common Mistakes below.
Anonymous view usages
A view usage does not have to be named. When you want a one-off slice of the model – to share a screenshot in a review, to drop a quick visualization into a diagram, to test what a particular expose would surface – you can write the usage inline without giving it a name:
view scratch { expose CoffeeMachine; }
That is a complete view usage. There is no view def, no satisfaction, no rendering – just a name and a body. Tools treat it like any other view usage: they resolve the expose, project the element, and render the result. Anonymous views are the modeling equivalent of a scratch buffer. Reach for them when you want a slice now and have not yet decided whether the slice deserves a definition.
Combining Metadata and Views
Metadata and views work well together. You can use metadata annotations to mark which elements belong in which review, and then build views that surface exactly those elements:
package CoffeeMachineReview {
private import ScalarValues::*;
private import CoffeeMachineGovernance::*;
private import CoffeeMachineStructure::*;
private import CoffeeMachineRequirements::*;
viewpoint def SafetyViewpoint {
doc /* All elements classified SIL-2 or above,
plus their associated requirements. */
}
view def SafetyReviewView;
// The safety review exposes only safety-relevant elements
view safetyReview : SafetyReviewView {
viewpoint perspective : SafetyViewpoint;
expose CoffeeMachineRequirements::SafetyInterlockReq;
expose CoffeeMachineRequirements::BrewTempReq;
expose CoffeeMachineStructure::Brewer;
}
viewpoint def ArchitectureViewpoint {
doc /* System decomposition for architecture board review. */
}
view def ArchitectureReviewView;
// The architecture review exposes structural elements
view architectureReview : ArchitectureReviewView {
viewpoint perspective : ArchitectureViewpoint;
expose CoffeeMachineStructure::CoffeeMachine;
expose CoffeeMachineStructure::Grinder;
expose CoffeeMachineStructure::Brewer;
expose CoffeeMachineStructure::WaterTank;
}
}
Notice that Brewer appears in both views. The safety engineer sees it because it contains the heater that is safety-classified. The architect sees it because it is a major subsystem. Same element, different reasons, different context. The model does not duplicate anything.
Filtering a View with filter
expose says “pull this element (or namespace) in”. Sometimes you want the opposite shape: pull a whole namespace in, then filter out the parts that do not belong in this particular view. That is what filter is for.
Note where each half lives: expose sits in the view usage, while filter typically sits in the view definition, where it becomes part of the reusable recipe and screens whatever any usage of that definition exposes. (A usage body may carry its own filter too, for one-off narrowing.)
A filter clause is a Boolean expression evaluated once per element that the view exposes. If the expression is true, the element stays in the view; if it is false, the element is dropped.
The spec’s own filter idiom is a classification test: the @ operator asks whether the current element is classified by a metaclass or a metadata definition. That is the portable form, and it is what the standard library’s own filtered packages use:
view def PartsOnlyPortable {
filter @SysML::PartUsage; // metaclass test
}
view partsOnly : PartsOnlyPortable {
expose CoffeeMachineStructure::*;
}
view def MandatorySafety {
filter @SIL2;
}
view mandatorySafety : MandatorySafety {
expose CoffeeMachineStructure::*;
}
The second view tests for a more specific annotation. In the shared vocabulary, metadata def SIL2 :> SafetyClassification { :>> level = "SIL-2"; } captures the value that the review is interested in. Apply @SIL2 to the relevant elements, then select them with filter @SIL2;. This avoids a qualified reference to a feature of the metadata type outside its featuring context.
The simplest filters are literal:
view def AllOfIt { filter true; } // accept everything
view def NoneOfIt { filter false; } // accept nothing
filter true and filter false are useful as scaffolding – a starting point you can sharpen.
Use metaclasses rather than comparing a private renderer’s strings. The filter below recognizes a part usage even if the user renames it. For a review of one specific definition it is simpler to expose that definition directly:
view def PartsOnly { filter @SysML::PartUsage; }
view structureParts : PartsOnly { expose CoffeeMachineStructure::**; }
view brewerOnly { expose CoffeeMachineStructure::Brewer; }
You can stack filters. Multiple filter clauses on the same view compose as logical AND: an element passes only if every filter accepts it.
view def SafetyParts {
filter @SysML::PartUsage;
filter @SafetyClassification;
}
view safetyParts : SafetyParts { expose CoffeeMachineStructure::**; }
Only a part usage carrying the specified metadata meets both filters. If an expected member is missing, check the exposed scope first, then test each predicate. sysml -explain filter-not-evaluated explains the difference between a valid filter the tool does not evaluate and a misspelled reference, which is a diagnostic. Do not rely on either as a selection rule.
Renderings
A view says what to show. A rendering says how to show it. They are separate concepts because the same slice of the model can sensibly appear as a table, a tree, a diagram, or a matrix depending on who is reading it.
The spec gives you a small kit:
rendering def Foo;declares a rendering by name.- A
renderclause can reference a rendering usage (render Views::asTreeDiagram;) or declare a typed rendering inline (render rendering presentation : StandardRendering;). - A view usage can override its definition’s rendering by writing its own
renderclause in the usage body.
Here is the running coffee-machine example with a rendering attached:
package CoffeeMachineViews {
private import CoffeeMachineStructure::*;
private import CoffeeMachineRequirements::*;
rendering def StandardRendering;
view def SafetyReviewView {
render rendering presentation : StandardRendering;
}
view safetyReview : SafetyReviewView {
viewpoint perspective : SafetyViewpoint;
expose CoffeeMachineRequirements::SafetyInterlockReq;
expose CoffeeMachineRequirements::BrewTempReq;
}
}
The render rendering presentation : StandardRendering; line is a ViewRenderingMembership: it declares a rendering usage inside the view and types it by the rendering definition. The view uses the rendering by owning a usage of it.
A rendering definition can carry attributes – things like layout direction, paper size, page break preferences – but most authors start with an empty rendering def and let the tool’s defaults take over. The point of the rendering is the binding: the view declares its intent, and the tool that consumes the view picks up the matching rendering and presents the slice accordingly.
What Kind of Diagram Does a View Become?
You have written view def SafetyReviewView and view def CoffeeOverview. When a tool renders one of these, what shape does it choose? A flat list? A tree? A diagram with boxes and lines? The standard view definition describes the intended content. The producing tool interprets the rendering member, including an inherited rendering.
The standard library package StandardViewDefinitions defines exactly eight standard view definitions, each corresponding to a recognizable diagram shape. When you write view def Foo :> InterconnectionView, you are saying “this view should be presented as an interconnection diagram”. When you write view def Foo :> ActionFlowView, you are saying “this view should be presented as an action-flow diagram”. The supertype is the contract.
The eight standard view definitions are:
| Supertype | What it shows |
|---|---|
GeneralView | Any exposed elements, as a general graph of nodes and edges |
InterconnectionView | Features as (nested) nodes and the connections between them as edges |
ActionFlowView | Actions, their parameters, and the flows between them |
StateTransitionView | States and the transitions between them |
SequenceView | Time-ordered event occurrences and messages on lifelines |
GeometryView | Spatial items visualized in two or three dimensions |
GridView | Elements and relationships in a rectangular grid (tables, matrices) |
BrowserView | The hierarchical membership structure (containment tree) |
Pick the supertype that matches the question the view is answering. “Show me how the parts connect” → InterconnectionView. “Show me the order of actions in the brew cycle” → ActionFlowView. “Show me the state machine” → StateTransitionView. The supertype is the difference between a view that lands as a useful diagram and one that lands as a generic table.
Two diagram kinds you might expect are deliberately not on the list. There is no UseCaseView and no RequirementView in the standard library. For those, the library’s own documentation on GeneralView gives the recipe: specialize GeneralView and narrow it with a filter. A requirement view, for example, is a GeneralView filtered to requirement elements:
view def RequirementOverview :> GeneralView {
filter @SysML::RequirementDefinition or @SysML::RequirementUsage
or @SysML::SatisfyRequirementUsage;
}
The same pattern gives you a package view, a definition-and-usage view, or any other slice-by-kind: GeneralView plus the metaclass filter naming the kinds you want.
view def CoffeeStructure :> InterconnectionView;
view def BrewSequence :> ActionFlowView;
view def HeaterStateMachine :> StateTransitionView {
filter @SysML::StateUsage or @SysML::TransitionUsage;
}
view structure : CoffeeStructure { expose CoffeeMachine; }
view brewOrder : BrewSequence { expose BrewCycle; }
view heaterStates : HeaterStateMachine { expose Brewer; }
Each of those views asks for model elements wrapped in a different presentation contract. The tool consuming them picks the appropriate diagram engine based on the supertype. Choose the intended view kind explicitly. A view def Foo with no supertype is treated as the most general kind of view – GeneralView is the root of the family – and renders as a generic projection; the renderer does not infer a kind from the view’s name.
The Stakeholder → Viewpoint → View → Rendering Chain
Everything in this chapter so far has been one element at a time. Pulling them together: SysML v2’s view model is a single chain that runs from a person’s concern at one end to a rendered artifact at the other.
Stakeholder a person or role with a question
│
│ has
▼
Viewpoint the question, captured as a requirement
│ (`viewpoint def` is a kind of `requirement def`)
│ satisfied by
▼
View Usage the concrete view — exposes the content and declares
│ which viewpoints it satisfies
│ (typed by a View Definition: the reusable recipe —
│ supertype + filters + rendering;
│ `view def` is a kind of `part def`)
│ rendered through
▼
Rendering Usage the visual style applied
│
│ produces
▼
View artifact what a human sees
Here is the full chain in 25 lines:
package SafetyReview {
private import CoffeeMachineStructure::*;
// Stakeholder — a role
part def SafetyEngineer;
// Viewpoint — the concern, expressed as a requirement
viewpoint def SafetyConcernViewpoint {
subject selectedView : Views::View;
stakeholder reviewer : SafetyEngineer;
doc /* Reviewers must see all SIL-2-classified parts. */
}
// Rendering — the style
rendering def DarkInterconnection;
// View Definition — the recipe
view def SafetySIL2View :> InterconnectionView {
render rendering dark : DarkInterconnection;
filter @SIL2;
}
// View Usage — the concrete instance
view sil2Diagram : SafetySIL2View {
viewpoint perspective : SafetyConcernViewpoint;
expose CoffeeMachine;
}
}
Reading top to bottom: a SafetyEngineer is the stakeholder; the SafetyConcernViewpoint captures their concern; the DarkInterconnection is a reusable rendering style; the SafetySIL2View is the recipe that filters to SIL-2 parts only and applies the dark rendering; the sil2Diagram is the concrete view a tool actually renders – it exposes the content and declares that it satisfies the viewpoint.
(Strictly, a satisfy declaration may target a named viewpoint usage; a nested composite viewpoint usage is itself asserted satisfied. A satisfy declaration is an ordinary usage member, so the grammar admits it inside a view def body as well – the standard library’s own abstract View definition carries one. But the satisfaction claim reads most naturally on the concrete view, and that is where this book puts it.)
You do not have to use every link in the chain. Most authors start at the View end (view def + view usage) and add viewpoints + stakeholders only when traceability becomes a requirement. But when you do need traceability, every link is queryable: “which views satisfy this viewpoint”, “which viewpoints concern this stakeholder”, “what is the rendering for this view”. The chain is the trace.
Finding and rendering a view
An editor outline shows what a file declares. A view selects elements for a stakeholder; it may expose elements from several files. To discover the published selections and render one, load the project rather than just the file declaring the view:
sysml -list views src/examples/coffee-machine
sysml -render BookViews::connectionOverview -render-form dot -o connections.dot src/examples/coffee-machine
dot -Tsvg connections.dot -o connections.svg
DOT is the rendering description; Graphviz lays it out as a static SVG. For a one-off exploration OpenSysML also has pseudo-views. A named view usage, unlike a shell command, travels with the model and can be reviewed along with it.
When to Add Metadata and Views
You do not need metadata or views from day one. They become valuable when the model is shared beyond the original author:
- Add
docearly. As soon as someone else will read your definitions, document intent. It costs almost nothing and saves review time. - Add metadata when governance starts. When the project has formal reviews, maturity gates, or safety classifications, metadata ensures that status is tracked in the model, not in a spreadsheet that drifts out of sync.
- Add views when stakeholders diverge. When different reviewers need different slices, views prevent the “here is the entire model, find what you need” problem.
If you are working alone on a small model, comments and doc may be all you need. If you are on a team with safety reviews, architecture boards, and verification milestones, metadata and views are essential governance infrastructure.
Visualizing Views and Metadata
Views
Metadata
Common Mistakes
Storing review status only in comments. A comment like // approved by safety board 2024-03-15 is invisible to tooling. If you need to query which elements are approved, that information must be metadata. Use @ReviewStatus { :>> status = "approved"; } instead.
Creating one giant view for all stakeholders. A view that exposes everything is just the model again. The value of a view is in what it leaves out. Keep views small and purpose-driven. If a stakeholder does not need to see the grinder to make their decision, do not expose it.
Duplicating model content in views. Views reference elements with expose. They do not redefine them. If you find yourself copying attribute lists or requirement text into a view, you are doing it wrong. Expose the original element and let the tool present it.
Proliferating metadata definitions. If the safety team defines SafetyLevel and the quality team defines SafetyRating with the same fields, you have a schema drift problem. Agree on shared metadata definitions early and put them in a governance package that everyone imports.
Treating an unevaluated filter as evidence. A syntax error, an unresolved name and a valid predicate the renderer cannot evaluate are different diagnoses. Check -strict -validate and the actual output before accepting a filtered view.
Treating render as a styling hook. render rendering presentation : StandardRendering; selects a RenderingDefinition. It does not set fonts, colours, or themes. If you want a view to look a particular way, the visual style is a property of the tool that consumes the view, not of the view itself. Use render to declare presentation intent (“table”, “diagram”, “matrix”) and let the tool’s visual style apply.
Confusing a file outline with a view. A file outline follows the source tree. A view selects content with expose and can draw from more than one namespace.
Forgetting the supertype on view def. A bare view def Foo; is legal but renders as a generic projection – the most general view, GeneralView. For an interconnection, action-flow, or state-transition diagram, you must specialize from the matching standard definition: view def Foo :> InterconnectionView { ... }. There is no name-based fallback — a view called FooInterconnection without an explicit :> InterconnectionView still renders as a general view.
Putting expose in a view definition. Define the reusable selection criteria there, but put expose in the view usage (SysML §7.26).
What You Have Built
The model can now describe itself and present itself.
Metadata attaches structured facts about elements – maturity, owner, safety
classification – distinct from doc, which carries prose for a human, and from
comments, which are not in the model at all.
Views turn that into something a reader can use. The chain runs
stakeholder → viewpoint → view → rendering: someone has a concern, a viewpoint
states it, a view selects the elements that answer it, and a rendering says what
form the answer takes. expose (in the usage) chooses content, filter (in the
definition) narrows it, and the definition’s supertype decides what kind of
diagram you get.
The thing most worth remembering is that a view is part of the model. It is not a diagram someone drew and saved – it is a declaration of what a particular reader needs, which is why it can be reviewed, versioned, and regenerated when the model changes.
Chapter 14 turns outward to what you did not write: the standard library, and how much of the language is defined in it.
Model context: chapter listings and shared vocabulary. From the edition root: sysml -strict -validate src/examples/lessons/vocabulary.sysml src/examples/lessons/ch13.sysml.