Skip to main content

Import a FlatBuffers or Cap'n Proto schema

The FlatBuffers (flatbuffers) and Cap'n Proto (capnproto) importers read zero-copy binary schemas into the Catalog. Tables, structs, unions and enums become types, and a Cap'n Proto interface becomes a service with one operation per method. You can then search, version, diff, lint and convert them like any other catalog item.

Import it​

Import the schema like any other catalog format: in the import wizard (Import to catalog → FlatBuffers or Cap'n Proto), over the REST API (see Import a specification), or from the CLI:

apiome import flatbuffers ./monsters.fbs
apiome import capnproto ./addressbook.capnp

Upload a .zip, .tar.gz or .tar when the schema includes or imports other files. The CLI's test fixtures, in apiome-cli/tests/fixtures/, are a quick way to try either format: monsters-flatbuffers.fbs and addressbook-capnproto.capnp.

Breaking changes between versions​

Both formats identify a field on the wire by a number, not its name, so a new version of the catalog item is compared by that number.

FlatBuffers​

A table field's number is its (id: N), or its position among the table's fields when the table writes no ids (a union field takes two). A field is never removed: it is marked (deprecated), so its id stays taken. A struct is a fixed layout with no ids.

ChangeSeverityRule
A field renamed, id and type unchangedDangerous: binary buffers still read; JSON and generated code do notfbs.field-renamed
A field id reused for a field of another typeBreakingfbs.field-id-reused
A field moved to another id, for example because a field was inserted before itBreakingfbs.field-id-changed
A field marked (deprecated)Safefbs.field-deprecated
A field removed without (deprecated)Breakingfbs.field-removed
A field added at a new idSafefbs.field-added
A field's default changedDangerous: buffers that omit the field now read another valuefbs.default-changed
Any change to a struct fieldBreakingfbs.struct-changed
An enum value renumbered or removedBreakingfbs.enum-value-changed, fbs.enum-value-removed
A union member removed or reorderedBreakingfbs.union-member-removed

Cap'n Proto​

Every struct field, interface method and enumerant has an @N ordinal, and names never reach the wire. A member can be renamed freely and added at the next ordinal, but never removed or renumbered: keep an obsolete member and rename it instead.

ChangeSeverityRule
A field or method renamed, ordinal and type unchangedSafecapnp.field-renamed, capnp.method-renamed
An ordinal reused for a member of another type or signatureBreakingcapnp.ordinal-reused
A member moved to another ordinalBreakingcapnp.ordinal-changed
A field or method removedBreakingcapnp.field-removed, capnp.method-removed
A field or method added at a new ordinalSafecapnp.field-added, capnp.method-added
An enumerant renumbered or removedBreakingcapnp.enum-value-changed, capnp.enum-value-removed

Every other change (a removed type, a changed method result) is graded by the standard rules.

Lint rules​

On top of the common rules, every FlatBuffers item is checked by the flatbuffers pack and every Cap'n Proto item by the capnproto pack:

RuleSeverityChecks
flatbuffers.root-type-declaredInfoA schema with tables declares its root_type.
flatbuffers.namespace-declaredInfoThe schema declares a namespace.
flatbuffers.unique-field-idsErrorNo two fields of a table, or a field and a deprecated slot, share an id.
flatbuffers.explicit-ids-all-or-noneErrorA table declares (id: N) on every field or on none.
capnproto.file-id-declaredErrorThe file declares its @0x…; id (capnp id generates one).
capnproto.unique-ordinalsErrorNo two members of a struct, interface or enum share an ordinal.
capnproto.contiguous-ordinalsErrorOrdinals run from @0 without a gap.

The error rules are the ones flatc and the Cap'n Proto compiler enforce, so a schema they flag does not compile.