Skip to content

Embedded schema does not distinguish flags from enums #296

Description

@naegelejd

Problem

The schema string that Yardl embeds in every binary/NDJSON file does not record whether an enum-like type is a !flags type. As a result, a !flags definition and an !enum definition are byte-for-byte identical in the embedded schema. Any consumer that works purely from the embedded schema (e.g. a dynamic/schema-only reader, or a third-party tool) cannot reproduce Yardl's own flags semantics, and cannot even reproduce Yardl's own NDJSON output for affected protocols.

Concrete differences between Yardl's SDK output and a schema-only reader on the models/test/unittests.yml protocols:

Protocol Yardl SDK Schema-only reader
FlagsMONDAY+WEDNESDAY+FRIDAY ["monday","wednesday","friday"] 21
FlagsSUNDAY ["sunday"]` "sunday"
EnumsRecordWithEnums.flags [] 0
Unions[null, Fruits, DaysOfWeek] holding Fruits.APPLE "apple" (simple) {"T1":"apple"} (tagged)

These are the only fidelity differences observed across all 29 protocols in unittests.yml; everything else round-trips byte-for-byte. (Discovered while prototyping a dynamic, schema-only binary reader.)

Proposed fix

Emit the flags marker in the protocol schema. Simplest is to give EnumDefinition a custom MarshalJSON (or add an isFlags field) so the embedded types[] carries it — mirroring the existing enum/flags distinction in TypeDefinitions.MarshalJSON.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions