Skip to main content

Exporting annotated diagrams

Stateway's differentiator is using BPMN as an auditability bridge between technical teams and business stakeholders. However, generic modelers like bpmn.io or Camunda Modeler silently ignore stateway: extensions in the XML — an auditor who opens the file sees a "clean" diagram that hides exactly the decisions that need to be audited.

The ?annotations=true parameter solves this: it derives canonical BPMN visualization elements (<bpmn:textAnnotation> linked via <bpmn:association>) from stateway: extensions and relevant canonical attributes, injecting them into the exported XML.

info

Annotations are always derived on-demand. The definition's source stored in Stateway is never altered.

Endpoint

GET /v1/definitions/:key/xml?annotations=true
GET /v1/definitions/:key/xml?annotations=true&layout=true
GET /v1/definitions/:key/xml?annotations=true&layout=true&version=2

Query parameters

ParameterTypeDefaultDescription
annotationsbooleanfalseEnables textAnnotation/association generation
annotationTypesCSV stringallFilters categories: type,validation,datastore,assignment,service,decision,gateway,timer
layoutbooleanfalseApplies auto-layout (recommended together with annotations)
versionintegerlatest activeSpecific definition version

annotations × layout combination matrix

annotationslayoutResult
falsefalseRaw XML, identical to what's stored
falsetrueXML with auto-layout only
truefalseAnnotations injected; annotation DI computed via heuristic offset
truetrueElements auto-laid-out; annotations injected afterward with heuristic-offset DI

Example call

curl -G https://api.stateway.io/v1/definitions/loan-approval/xml \
-H "X-API-Key: sw_live_your_key" \
--data-urlencode "annotations=true" \
--data-urlencode "layout=true" \
--output loan-approval-annotated.bpmn

Annotation categories

Each category reads an extension or canonical attribute and produces a text box linked to the corresponding element.

CategoryElementSourceExample generated text
serviceserviceTasktaskDefinition type="http" + taskHeaders + ioMappingHTTP GET https://credit-bureau.example.com/score
mode: sync · timeout: 5000
← cnpj
→ creditReportScore
decisionbusinessRuleTasktaskDefinition type="decision" + decisionKey + ioMappingDMN: credit-score-decision
← cnpj, score
→ creditScore, approved, creditLimit
assignmentuserTaskassignmentDefinitionAssignment:
assignee: {{variables.managerEmail}}
groups: credit-managers, compliance
gatewaysequenceFlowconditionExpression / default flowif: {{variables.approved == true}} or else
timerevents with timerEventDefinitiontimeDuration / timeDate / timeCycleTimer: duration PT48H
datastoredataStoreReferencestoreAccessDataStore: customerStore
key: =variables.cnpj
mode: snapshot
projection: creditHistory, previousLoans
typedataObject / Activity with ioSpecificationitemDefinition with stateway:schemaType: Application Data
companyName: string
cnpj: string
validationdataObject / Activity with ioSpecificationJSON Schema constraintsValidation:
Application Data required: companyName, cnpj
Application Data.companyName length: 2..∞
Application Data.cnpj pattern: ^[0-9]{14}$
note

For type/validation on a bpmn:DataObject, the annotation is generated on the DataObject, but the association points to the visual DataObjectReference when one exists in the same process. This avoids modeler warnings, since modelers render the reference, not the underlying object.

Filtering categories

To export only service and decision annotations:

GET /v1/definitions/:key/xml?annotations=true&layout=true&annotationTypes=service,decision

Invalid values in annotationTypes return 400 VALIDATION_ERROR.

Deterministic IDs

Generated annotations use namespaced, deterministic IDs, so that two exports of the same process produce identical XML:

  • textAnnotation: sw_ann_<elementId>_<category>
  • association: sw_assoc_<elementId>_<category>
  • DI shapes/edges: _di suffix

Common errors

CodeCondition
404 NOT_FOUNDDefinition not found in the tenant
422 PROCESS_ERRORThe definition is not of type BPMN (JSON/YAML don't export XML)
400 VALIDATION_ERRORannotationTypes contains an invalid value
401 UNAUTHORIZEDAPI key missing or invalid