lutaml-model 0.8.196 → 0.8.197
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/_references/plan-schema-spec.adoc +308 -0
- data/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +10 -3
- data/lib/lutaml/lml/models/top_element_attribute.rb +7 -2
- data/lib/lutaml/model/serialize/annotations.rb +74 -0
- data/lib/lutaml/model/serialize.rb +2 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/mapping.rb +15 -0
- data/lib/lutaml/xml/schema/xsd/attribute.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/element.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/max_scale.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/min_scale.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +9 -0
- data/lib/lutaml/xml/schema/xsd/vc_conditional_attributes.rb +62 -0
- data/lib/lutaml/xml/schema/xsd.rb +6 -2
- data/lib/lutaml/xml/schema/xsd_schema.rb +2 -0
- data/spec/lml/lutaml/lml/format_adapter_spec.rb +24 -0
- data/spec/lml/lutaml/lml/json_transfer_spec.rb +188 -0
- data/spec/lml/lutaml/lml/property_laws_spec.rb +3 -38
- data/spec/lml/support/lml_property_support.rb +168 -0
- data/spec/lutaml/model/annotations_spec.rb +97 -0
- data/spec/lutaml/xml/schema/xsd_scale_vc_spec.rb +59 -0
- metadata +10 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 266b072f3fabe54b418f8691aba2049c5fcf24ec66072d00d4faef5cff40fca4
|
|
4
|
+
data.tar.gz: 1aa8bf7e64783e944f9ee906db6b5a6d9be3454042eb2086bed7a38a8b6803e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a84249d40f2ea758e09a1ad76b4c6af13e986cea14d392622332b2377eb4131dde4271a324930fa04e9504e9a8e89f2feb62c59b8b3360711192c25f7ddfbb3
|
|
7
|
+
data.tar.gz: 5ff6600865d03bd6dce93089b043630dd87b63191670b118fdb41dec5c8125035fd3613c6542641504d921cd5d727c8eb2f42bae65f61a7f46593b01e262128c
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
= lutaml-model-rs plan schema — requirements specification
|
|
2
|
+
|
|
3
|
+
Status: **draft 1** for review (maintainer + #1033 card owner).
|
|
4
|
+
Sources of record: the shipped machinery this spec extracts — the
|
|
5
|
+
key-value compiled plans (`lib/lutaml/key_value/transform.rb`,
|
|
6
|
+
`kv_group_plan`/`build_kv_group_plan`/`kv_group_build`), the XML plan
|
|
7
|
+
fast path (`lib/lutaml/xml/leptris/plan_compiler.rb`,
|
|
8
|
+
`plan_serializer.rb`, `native_emission.rb`, `plan_hydrator.rb`), the
|
|
9
|
+
construction seam (`lib/lutaml/model/serialize/initialization.rb`,
|
|
10
|
+
`allocate_for_walk`), and the #1033 portable declaration form
|
|
11
|
+
(`portable-exact-json-v1`).
|
|
12
|
+
|
|
13
|
+
== Endgame and purpose
|
|
14
|
+
|
|
15
|
+
The lutaml-model endgame mirrors the leptris project's multi-language
|
|
16
|
+
structure: **lutaml-model-rs**, a Rust crate carrying declarations,
|
|
17
|
+
compiled plans, and parse/hydrate/emit for the formats; and
|
|
18
|
+
**lutaml-model-rb**, the Ruby gem, which keeps the DSL, the object
|
|
19
|
+
model, and the public API, and binds to lutaml-model-rs over the
|
|
20
|
+
established native-engine seam.
|
|
21
|
+
|
|
22
|
+
The plan schema specified here is the wire surface the crate consumes:
|
|
23
|
+
a serializable, versioned per-class descriptor of how to hydrate and
|
|
24
|
+
emit documents for a model, compiled from the model's declarations.
|
|
25
|
+
The Rust engine executes plans natively; Ruby receives hydrated models
|
|
26
|
+
and hosts the API.
|
|
27
|
+
|
|
28
|
+
This spec exists because the hot-path evidence names exactly what the
|
|
29
|
+
plan must carry precomputed. On the KV lane, 61% of the per-attribute
|
|
30
|
+
hydration cost is Ruby cast-resolution machinery (measured: setter
|
|
31
|
+
chain 18.45 µs/attribute vs direct `Type.cast` 7.18 µs, 20k
|
|
32
|
+
iterations, ruby 4.0.7; see the #1158 investigation) — machinery a
|
|
33
|
+
native plan executor eliminates by carrying per-row types and casts in
|
|
34
|
+
the plan.
|
|
35
|
+
|
|
36
|
+
== Architecture ladder
|
|
37
|
+
|
|
38
|
+
----
|
|
39
|
+
Ruby DSL declarations
|
|
40
|
+
└─→ #1033 portable declarations (portable-exact-json-v1, pinned)
|
|
41
|
+
└─→ compiled plans (this schema; versioned with the portable form)
|
|
42
|
+
├─→ lutaml-model-rs (native execution: hydrate + emit)
|
|
43
|
+
├─→ TypeScript realization
|
|
44
|
+
└─→ lutaml-model-rb fallback (compiled maps over the
|
|
45
|
+
setter chain; the no-engine path, already shipped
|
|
46
|
+
as kv_group_plan + the interpretive walk)
|
|
47
|
+
----
|
|
48
|
+
|
|
49
|
+
One declaration source, three consumers. The plan format **derives
|
|
50
|
+
from the portable declaration form** and is versioned with it — it is
|
|
51
|
+
never a separately invented Ruby-side wire, which would fork the
|
|
52
|
+
declaration surface the #1033 contract pins.
|
|
53
|
+
|
|
54
|
+
== The seam (how Ruby and the crate meet)
|
|
55
|
+
|
|
56
|
+
The binding follows the shipped leptris pattern, which is the
|
|
57
|
+
compatibility contract for the whole seam:
|
|
58
|
+
|
|
59
|
+
- **Capability floor**: the Ruby gem declares a minimum engine version
|
|
60
|
+
(`MIN_LEPTRIS_VERSION` is the precedent — `lib/lutaml/xml/leptris.rb`).
|
|
61
|
+
Bundles resolving an older crate keep the Ruby path; they never see
|
|
62
|
+
plans the engine cannot parse.
|
|
63
|
+
- **Lazy plan compilation**: plans compile at first parse of a class
|
|
64
|
+
(`kv_group_plan` memoizes per `(class, format, register, context
|
|
65
|
+
generation)`); the context-generation key retires stale plans when
|
|
66
|
+
registers reset.
|
|
67
|
+
- **Compatibility gating**: a `plan_path_compatible?`-style probe per
|
|
68
|
+
lane decides engine-vs-fallback per parse. A half-initialized or
|
|
69
|
+
incapable engine must never flip lane selection with process load
|
|
70
|
+
order.
|
|
71
|
+
- **Interpretive fallback**: shapes the plan cannot express
|
|
72
|
+
(<<gates>>) ride the Ruby path unchanged. The fallback is permanent,
|
|
73
|
+
not transitional — it is also the correctness reference the engine
|
|
74
|
+
is conformance-tested against.
|
|
75
|
+
|
|
76
|
+
== Drop-in contract for existing user gems
|
|
77
|
+
|
|
78
|
+
The endgame is a **drop-in**: every existing downstream gem —
|
|
79
|
+
relaton, glossarist, metanorma, unitsml, the whole dependent matrix —
|
|
80
|
+
receives the Rust benefits with **zero changes on their side**: no
|
|
81
|
+
gemspec additions, no Gemfile edits, no configuration, no API
|
|
82
|
+
migration, no version-line changes (the `~> 0.8` floors continue).
|
|
83
|
+
Five contract lines make that true:
|
|
84
|
+
|
|
85
|
+
1. *Distribution*: lutaml-model-rs ships as precompiled platform
|
|
86
|
+
gems across the supported matrix (the leptris distribution
|
|
87
|
+
model), and lutaml-model-rb declares it as a gemspec dependency —
|
|
88
|
+
installing lutaml-model installs the engine. Checksum manifests
|
|
89
|
+
are complete for every platform (the frozen-install CHECKSUMS
|
|
90
|
+
lesson from the metanorma-docker builds). Today the native
|
|
91
|
+
engines arrive by optional probe (`Utils.safe_load`) — only
|
|
92
|
+
bundles that happen to carry them benefit; that pattern is the
|
|
93
|
+
transition state, not the endgame.
|
|
94
|
+
2. *Activation*: zero-config and default-on. Presence plus the
|
|
95
|
+
capability floor plus the per-lane plan-compatibility probe decide
|
|
96
|
+
engine-vs-fallback automatically. No environment variables, no
|
|
97
|
+
`Config` calls required by user gems (the yeptris env-var removal
|
|
98
|
+
is the precedent — lane selection is centralized, never keyed on
|
|
99
|
+
the environment).
|
|
100
|
+
3. *Failure containment*: an engine abort falls back per-parse to the
|
|
101
|
+
Ruby path with a warning — the #1243 native-emission abort
|
|
102
|
+
precedent — with a strict escape hatch for debugging only. A
|
|
103
|
+
broken engine can never break a user gem; worst case is the Ruby
|
|
104
|
+
path.
|
|
105
|
+
4. *Equivalence*: byte parity between lanes is a **release gate**.
|
|
106
|
+
The dependent-tests matrix gains an engine-on/engine-off A/B leg
|
|
107
|
+
running the downstream gems' suites; identical outputs (the
|
|
108
|
+
leptris byte-parity precedent for the dump lane). Lane parity is
|
|
109
|
+
verified per release against the real dependent corpora, not
|
|
110
|
+
asserted.
|
|
111
|
+
5. *Version surfaces*: user gems never change. Plan-format versions,
|
|
112
|
+
engine floors, and coverage growth evolve entirely inside the
|
|
113
|
+
lutaml-model-rb ↔ lutaml-model-rs pair.
|
|
114
|
+
|
|
115
|
+
== Plan wire schema
|
|
116
|
+
|
|
117
|
+
=== Envelope
|
|
118
|
+
|
|
119
|
+
----
|
|
120
|
+
{
|
|
121
|
+
"plan_version": <int>, // this schema's version
|
|
122
|
+
"format": "json" | "yaml" | "xml" | "toml" | "hash",
|
|
123
|
+
"model": <portable model id>, // the #1033 model identity
|
|
124
|
+
"register": <register id | null>,
|
|
125
|
+
"rows": [ <row>... ], // declaration order
|
|
126
|
+
"unmapped": <unmapped row | null>
|
|
127
|
+
}
|
|
128
|
+
----
|
|
129
|
+
|
|
130
|
+
`plan_version` and the crate's own minimum-version floor evolve
|
|
131
|
+
independently; the Ruby side refuses to hand a plan to an engine below
|
|
132
|
+
the floor and falls back instead.
|
|
133
|
+
|
|
134
|
+
=== Row kinds (key-value lane; extracted from `build_kv_group_plan`)
|
|
135
|
+
|
|
136
|
+
Each row is the compiled form of one mapping rule:
|
|
137
|
+
|
|
138
|
+
[cols="1,2,3"]
|
|
139
|
+
|===
|
|
140
|
+
| kind | carries | hydration duty
|
|
141
|
+
|
|
142
|
+
| `scalar` | wire name, attribute name, portable type id, collection flag | engine casts the value natively; Ruby receives the cast value
|
|
143
|
+
| `model` | wire name, attribute name, nested plan ref, child register | engine recursively hydrates through the nested plan
|
|
144
|
+
| `child_map` | wire name, attribute name, compiled child-map plan (child mappings, wire names, paths, keys-only flag, child attr type) | engine performs the compiled `translate_mappings` per child key
|
|
145
|
+
| `unmapped` | target attribute, claimed-key set | engine collects unclaimed document keys into the target (merge semantics per `kv_group_build`)
|
|
146
|
+
|===
|
|
147
|
+
|
|
148
|
+
The in-memory precedent for this tuple is the shipped row shape
|
|
149
|
+
`[rule, attr, kind, type, child_rows, child_register]`; the wire form
|
|
150
|
+
replaces the Ruby object references (rule, attr, type, class) with
|
|
151
|
+
portable identifiers.
|
|
152
|
+
|
|
153
|
+
=== Row kinds (XML lane; extracted from the shipped kinds)
|
|
154
|
+
|
|
155
|
+
The XML lane's compiled kinds are already enumerated in code
|
|
156
|
+
(`PlanSerializer::SERIALIZABLE_KINDS`): `scalar`, `collection_native`,
|
|
157
|
+
`collection_cb`, `nested`, `ordered_deferred`, `raw`, `content`,
|
|
158
|
+
`content_deferred`. The wire schema adopts this vocabulary. Shapes the
|
|
159
|
+
XML lane already routes away from the plan lane — namespaced spellings
|
|
160
|
+
that are instance-dependent, wildcard rows, raw fragments and callback
|
|
161
|
+
shapes that are not ops-expressible — are **refusal gates**
|
|
162
|
+
(<<gates>>), not wire surface.
|
|
163
|
+
|
|
164
|
+
=== Type identity and casts
|
|
165
|
+
|
|
166
|
+
- Scalar rows carry a **portable type id** drawn from the #1033
|
|
167
|
+
builtin registry (`string`, `integer`, `float`, `decimal`,
|
|
168
|
+
`boolean`, `date`, ...). The crate implements the casts natively;
|
|
169
|
+
the exact-value spellings follow the `portable-exact-json-v1` rules
|
|
170
|
+
(decimal strings for big integers/decimals, canonical float wire,
|
|
171
|
+
signed zero preserved).
|
|
172
|
+
- Custom `Type::Value` subclasses are a **refusal gate** unless the
|
|
173
|
+
caller supplies type bindings (the #1033 `Materialization`
|
|
174
|
+
`type_bindings` pattern). The engine never guesses a custom cast.
|
|
175
|
+
- The cast contract is the setter chain's semantics under the plan
|
|
176
|
+
gates (<<gates>>): for every gate-satisfying row, native
|
|
177
|
+
`type.cast(v)` is equivalent to `cast_value` — this equivalence is
|
|
178
|
+
what made the plan gates the correct cast-precondition set.
|
|
179
|
+
|
|
180
|
+
=== Absent keys and defaults
|
|
181
|
+
|
|
182
|
+
Present-key detection uses the absent-vs-nil distinction the compiled
|
|
183
|
+
walk makes (`fetch` with a sentinel; present-nil values read as nil).
|
|
184
|
+
Absent rows carry the rule forward for default application.
|
|
185
|
+
Resolution (<<open>>): the absent set returns to Ruby for the
|
|
186
|
+
interpretive default path first; engine-side default application
|
|
187
|
+
lands as a coverage card carrying defaults in the plan.
|
|
188
|
+
|
|
189
|
+
=== Emission (Ruby → engine)
|
|
190
|
+
|
|
191
|
+
Emission plans mirror the hydration rows with the serialization
|
|
192
|
+
policies attached (render policies per the `render_nil` table:
|
|
193
|
+
omit/`as_nil`/`as_empty`/`as_blank`; ordered content from
|
|
194
|
+
`element_order` with the OrderReconciler contract; content runs;
|
|
195
|
+
CDATA). The XML lane's not-ops-expressible list is a hard refusal
|
|
196
|
+
boundary: multi-spelling rows, wildcard rows, raw/callback shapes ride
|
|
197
|
+
the Ruby serializer. KV emission reuses the row kinds with the
|
|
198
|
+
`model_to_data` merge semantics (unmapped-merge on serialize).
|
|
199
|
+
|
|
200
|
+
== Hydration return contract
|
|
201
|
+
|
|
202
|
+
The engine returns, per plan: hydrated row values (cast scalars, model
|
|
203
|
+
graphs for `model`/`child_map` rows, collected unclaimed keys), the
|
|
204
|
+
absent-rule set, and child instances needing parent/root wiring. Ruby
|
|
205
|
+
performs the construction through the existing seam —
|
|
206
|
+
`allocate_for_walk` for standard classes, the real constructor for
|
|
207
|
+
custom-initialize classes (the shipped custom-initialize fallback in
|
|
208
|
+
`initialization.rb`) — then applies setters, parent/root links, and
|
|
209
|
+
unmapped merges exactly as `kv_group_build` does today. The
|
|
210
|
+
Ruby-visible object graph, validation surface, and error classes are
|
|
211
|
+
byte-for-byte the fallback's.
|
|
212
|
+
|
|
213
|
+
Parse errors: the engine raises the strict-parse contract (the
|
|
214
|
+
`strict:` kwarg lineage — malformed input is a format error, never a
|
|
215
|
+
best-effort tree), mapped to `Lutaml::Model::InvalidFormatError` at
|
|
216
|
+
the seam.
|
|
217
|
+
|
|
218
|
+
== Register and context model
|
|
219
|
+
|
|
220
|
+
- Rows carry the **child register** where the child plan was built
|
|
221
|
+
under it (`Register.resolve_for_child` — the #876 contract);
|
|
222
|
+
rebuilding the resolution per row per document is the cost the
|
|
223
|
+
shipped plan already removed (TODO.perf 14).
|
|
224
|
+
- Plan caches key on context generation; the wire schema's `register`
|
|
225
|
+
field is the resolution root. The engine is stateless between
|
|
226
|
+
calls; all per-class state lives in the plan.
|
|
227
|
+
|
|
228
|
+
[[gates]]
|
|
229
|
+
== Gates and refusal table
|
|
230
|
+
|
|
231
|
+
Every eligibility predicate in `build_kv_group_plan` is a contract
|
|
232
|
+
line: the plan covers it, or the shape refuses to the fallback. The
|
|
233
|
+
current refusal set (extracted verbatim from the shipped gates):
|
|
234
|
+
|
|
235
|
+
multiple-mapping spellings; delegate rules; custom deserialize
|
|
236
|
+
methods; raw and root mappings; `when_attribute` partitions;
|
|
237
|
+
polymorphic rows (hash or flag); declared range collections;
|
|
238
|
+
polymorphic/union/custom-collection attributes; registered type
|
|
239
|
+
substitutions; derived attributes; whole-value policy types;
|
|
240
|
+
custom-from-probe types; non-`Serialize` child types for child-map
|
|
241
|
+
rows; singular targets for child maps; unmappable child attributes;
|
|
242
|
+
non-Hash values where a Hash is required (runtime refusal, walk owns
|
|
243
|
+
the error); XML: instance-dependent namespaced spellings, wildcards,
|
|
244
|
+
raw/callback shapes, ordered models without `element_order`.
|
|
245
|
+
|
|
246
|
+
Refusal is per-model (the whole model goes interpretive, as today) —
|
|
247
|
+
never per-value silently. The refusal table is versioned with the
|
|
248
|
+
plan: a coverage card ships with its gate changes and the floor bump.
|
|
249
|
+
|
|
250
|
+
== Versioning and conformance
|
|
251
|
+
|
|
252
|
+
- `plan_version` bumps only for wire-shape changes; gate/coverage
|
|
253
|
+
growth rides the engine floor.
|
|
254
|
+
- Conformance: the crate is tested against the fallback's observable
|
|
255
|
+
behavior on the plan-eligible corpus (the #1033 conformance harness
|
|
256
|
+
extends here; the refusal corpora — `r2_refusals.json`,
|
|
257
|
+
`float_vectors.json` — are the boundary fixtures).
|
|
258
|
+
- The Ruby gem ships the golden plan fixtures for the corpus (compiled
|
|
259
|
+
plans checked in as test artifacts), so wire drift breaks CI in
|
|
260
|
+
both languages.
|
|
261
|
+
|
|
262
|
+
== Derivation from #1033 portable declarations
|
|
263
|
+
|
|
264
|
+
The plan compiler consumes the portable declaration form and emits the
|
|
265
|
+
plan; the compilation is deterministic and version-locked to the
|
|
266
|
+
portable form (the #1033 contract discipline: rebakes are deliberate
|
|
267
|
+
and changelog-named). The two coverage sets are aligned but NOT
|
|
268
|
+
identical, and neither contains the other: the portable form's
|
|
269
|
+
refusals (custom methods, delegates, unions, keyed/root mappings)
|
|
270
|
+
overlap the plan gates, and the portable form also ACCEPTS shapes the
|
|
271
|
+
plan refuses — discriminator (`when_attribute`) rules are portable
|
|
272
|
+
expression but plan-refused — so shapes portable accepts may still
|
|
273
|
+
ride the Ruby fallback. Equally, the plan accepts child-map
|
|
274
|
+
collections whose exact VALUE spelling the portable value-writer
|
|
275
|
+
refuses; that is a value-layer refusal and does not constrain plans,
|
|
276
|
+
which the engine consumes directly. The engine's coverage grows
|
|
277
|
+
toward the portable form's full expressiveness, card by card, with
|
|
278
|
+
the gates table as the ledger.
|
|
279
|
+
|
|
280
|
+
[[open]]
|
|
281
|
+
== Resolutions (decided, with rationale)
|
|
282
|
+
|
|
283
|
+
1. *Defaults placement*: Ruby-side absent-row handling first
|
|
284
|
+
(defaults apply through the interpretive absent path exactly as
|
|
285
|
+
`kv_group_build` does today); engine-side default application
|
|
286
|
+
lands as a coverage card carrying defaults in the plan.
|
|
287
|
+
Rationale: the fallback is the correctness reference — shipping
|
|
288
|
+
hydration before default relocation keeps the engine the strict
|
|
289
|
+
subset; the measured win (the 61%) is in present-key casting,
|
|
290
|
+
which this sequencing captures in full.
|
|
291
|
+
2. *Custom type bindings*: accepted. Custom `Type::Value` subclasses
|
|
292
|
+
ride the `Materialization` `type_bindings` pattern at plan level;
|
|
293
|
+
unbound subclasses refuse to the fallback. Rationale: refusing
|
|
294
|
+
them permanently would wall custom types off from the engine
|
|
295
|
+
forever, and #1033's import direction already established the
|
|
296
|
+
bindings pattern — mirroring it costs nothing and composes.
|
|
297
|
+
3. *KV emission ops*: hydration first. The plan schema covers
|
|
298
|
+
hydration initially; KV emission ops are a follow-up card only if
|
|
299
|
+
the measured emission profile justifies them. Rationale: the 61%
|
|
300
|
+
is on hydration (`from_*`); KV emission has no equivalent
|
|
301
|
+
measurement yet — build against evidence, not symmetry.
|
|
302
|
+
4. *Engine consolidation*: coexistence behind the same seam.
|
|
303
|
+
leptris and yeptris already support Rust and keep their shipping
|
|
304
|
+
lanes; lutaml-model-rs grows its lanes and consolidation happens
|
|
305
|
+
organically per lane as it matures. Rationale: the seam pattern
|
|
306
|
+
(capability floor, gating, fallback) is lane-local by design, so
|
|
307
|
+
consolidation needs no up-front decision — each lane flips when
|
|
308
|
+
its native execution is conformance-green.
|
|
@@ -405,6 +405,7 @@ require "lutaml/model/schema/renderers"
|
|
|
405
405
|
require "lutaml/model/schema/shared_methods"
|
|
406
406
|
require "lutaml/model/schema/templates"
|
|
407
407
|
require "lutaml/model/schema/yaml_schema"
|
|
408
|
+
require "lutaml/model/serialize/annotations"
|
|
408
409
|
require "lutaml/model/serialize/attribute_definition"
|
|
409
410
|
require "lutaml/model/serialize/builder"
|
|
410
411
|
require "lutaml/model/serialize/conversion_caching"
|
|
@@ -78,7 +78,7 @@ module Lutaml
|
|
|
78
78
|
|
|
79
79
|
def format_value(prefix, key, value, indent)
|
|
80
80
|
key = format_key(key)
|
|
81
|
-
return "#{prefix}#{key} = ref:(#{value
|
|
81
|
+
return "#{prefix}#{key} = ref:(#{reference_path(value)})" if reference_value?(value)
|
|
82
82
|
|
|
83
83
|
case value
|
|
84
84
|
when Array
|
|
@@ -97,7 +97,7 @@ module Lutaml
|
|
|
97
97
|
def format_array(prefix, key, items, indent)
|
|
98
98
|
elements = items.map do |item|
|
|
99
99
|
if reference_value?(item)
|
|
100
|
-
" ref:(#{item
|
|
100
|
+
" ref:(#{reference_path(item)})"
|
|
101
101
|
else
|
|
102
102
|
case item
|
|
103
103
|
when Hash
|
|
@@ -131,7 +131,14 @@ module Lutaml
|
|
|
131
131
|
# reference literal; it emits as `ref:(path)`, never as a nested
|
|
132
132
|
# instance.
|
|
133
133
|
def reference_value?(value)
|
|
134
|
-
value.is_a?(Hash) && value.
|
|
134
|
+
value.is_a?(Hash) && value.size == 1 &&
|
|
135
|
+
(value.key?(:reference) || value.key?("reference"))
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Parsed cargo has symbol keys; a document reloaded from JSON or
|
|
139
|
+
# YAML has string keys.
|
|
140
|
+
def reference_path(value)
|
|
141
|
+
value.key?(:reference) ? value[:reference] : value["reference"]
|
|
135
142
|
end
|
|
136
143
|
|
|
137
144
|
def quote_value(val)
|
|
@@ -98,9 +98,14 @@ module Lutaml
|
|
|
98
98
|
literal = value.respond_to?(:value) ? value.value : value
|
|
99
99
|
cargo = literal.is_a?(::Array) ? literal.first : literal
|
|
100
100
|
cargo = cargo.value if cargo.is_a?(LiteralValue)
|
|
101
|
-
return nil unless cargo.is_a?(::Hash)
|
|
101
|
+
return nil unless cargo.is_a?(::Hash)
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
# Parsed literals carry symbol keys; a document reloaded from a
|
|
104
|
+
# transfer syntax (JSON, YAML) carries string keys.
|
|
105
|
+
path = cargo[:reference] || cargo["reference"]
|
|
106
|
+
return nil unless path
|
|
107
|
+
|
|
108
|
+
Reference.new(path: path.to_s)
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
private
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Model
|
|
5
|
+
module Serialize
|
|
6
|
+
# Class-level annotation DSL (#288 step 1): declaration-time prose
|
|
7
|
+
# metadata for models — descriptions, examples, and keyed
|
|
8
|
+
# annotations — stored in a frozen per-class table and readable
|
|
9
|
+
# through `annotations`.
|
|
10
|
+
#
|
|
11
|
+
# Purely additive: the table is invisible to serialization, the
|
|
12
|
+
# mapping surfaces, and the #1033 exporter's declaration walk
|
|
13
|
+
# (which simply sees no annotation fields until it learns them),
|
|
14
|
+
# so models carrying annotations produce byte-identical documents.
|
|
15
|
+
module Annotations
|
|
16
|
+
# Attach a prose description to the model. Repeatable: each call
|
|
17
|
+
# appends a description.
|
|
18
|
+
#
|
|
19
|
+
# @param text [String] the description prose
|
|
20
|
+
# @return [void]
|
|
21
|
+
def description(text)
|
|
22
|
+
annotation_store[:descriptions] << text.to_s
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Attach an example to the model. Repeatable.
|
|
27
|
+
#
|
|
28
|
+
# @param snippet [String] the example snippet
|
|
29
|
+
# @param description [String, nil] optional prose for the example
|
|
30
|
+
# @return [void]
|
|
31
|
+
def example(snippet, description: nil)
|
|
32
|
+
entry = { snippet: snippet.to_s }
|
|
33
|
+
entry[:description] = description.to_s if description
|
|
34
|
+
annotation_store[:examples] << entry.freeze
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Attach a keyed annotation to the model. Repeatable per key:
|
|
39
|
+
# entries under one key keep declaration order.
|
|
40
|
+
#
|
|
41
|
+
# @param term [Symbol, String] the annotation key
|
|
42
|
+
# @param text [String] the annotation text
|
|
43
|
+
# @return [void]
|
|
44
|
+
def annotation(term, text)
|
|
45
|
+
annotation_store[:annotations][term.to_sym] << text.to_s
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The frozen annotation table for this class.
|
|
50
|
+
#
|
|
51
|
+
# @return [Hash] { descriptions: [String], examples:
|
|
52
|
+
# [{snippet:, description:}], annotations: {term: [String]} }
|
|
53
|
+
def annotations
|
|
54
|
+
store = annotation_store
|
|
55
|
+
{
|
|
56
|
+
descriptions: store[:descriptions].freeze,
|
|
57
|
+
examples: store[:examples].freeze,
|
|
58
|
+
annotations: store[:annotations].transform_values(&:freeze).freeze,
|
|
59
|
+
}.freeze
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def annotation_store
|
|
65
|
+
@annotation_store ||= {
|
|
66
|
+
descriptions: [],
|
|
67
|
+
examples: [],
|
|
68
|
+
annotations: ::Hash.new { |h, k| h[k] = [] },
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -6,6 +6,7 @@ module Lutaml
|
|
|
6
6
|
# Autoload subdirectory modules
|
|
7
7
|
autoload :Initialization, "#{__dir__}/serialize/initialization"
|
|
8
8
|
autoload :AttributeDefinition, "#{__dir__}/serialize/attribute_definition"
|
|
9
|
+
autoload :Annotations, "#{__dir__}/serialize/annotations"
|
|
9
10
|
autoload :DeserializationContext,
|
|
10
11
|
"#{__dir__}/serialize/deserialization_context"
|
|
11
12
|
autoload :EnumHandling, "#{__dir__}/serialize/enum_handling"
|
|
@@ -61,6 +62,7 @@ module Lutaml
|
|
|
61
62
|
include Lutaml::Model::Liquefiable::ClassMethods
|
|
62
63
|
include Serialize::Initialization
|
|
63
64
|
include Serialize::AttributeDefinition
|
|
65
|
+
include Serialize::Annotations
|
|
64
66
|
include Serialize::EnumHandling
|
|
65
67
|
include Serialize::ModelImport
|
|
66
68
|
include Serialize::FormatConversion
|
data/lib/lutaml/model/version.rb
CHANGED
data/lib/lutaml/xml/mapping.rb
CHANGED
|
@@ -896,6 +896,21 @@ module Lutaml
|
|
|
896
896
|
@all_attributes_rule = AllAttributesMapping.new(to, matching)
|
|
897
897
|
end
|
|
898
898
|
|
|
899
|
+
# Declare the six XML Schema Versioning conditional-inclusion
|
|
900
|
+
# attributes on this mapping (XSD 1.1 §4.2, lutaml-model#1281).
|
|
901
|
+
# The model carries the vc_* attributes and the *_from/*_to
|
|
902
|
+
# handlers via VcConditionalAttributes; this only wires the
|
|
903
|
+
# spellings, so any component model opts in with one line.
|
|
904
|
+
def map_vc_attributes
|
|
905
|
+
vc = Lutaml::Xml::Schema::Xsd::VcConditionalAttributes
|
|
906
|
+
vc::VC_ATTRIBUTES.each do |attr|
|
|
907
|
+
spelling = vc::VC_SPELLINGS[attr]
|
|
908
|
+
map_attribute spelling, to: attr,
|
|
909
|
+
with: { from: :"#{attr}_from",
|
|
910
|
+
to: :"#{attr}_to" }
|
|
911
|
+
end
|
|
912
|
+
end
|
|
913
|
+
|
|
899
914
|
def sequence(&block)
|
|
900
915
|
@element_sequence << ::Lutaml::Model::Sequence.new(self,
|
|
901
916
|
format: :xml).tap do |s|
|
|
@@ -5,6 +5,8 @@ module Lutaml
|
|
|
5
5
|
module Schema
|
|
6
6
|
module Xsd
|
|
7
7
|
class Attribute < Base
|
|
8
|
+
include VcConditionalAttributes
|
|
9
|
+
|
|
8
10
|
attribute :id, :string
|
|
9
11
|
attribute :use, :string, values: %w[required prohibited optional], default: -> {
|
|
10
12
|
"optional"
|
|
@@ -30,6 +32,7 @@ module Lutaml
|
|
|
30
32
|
map_attribute :type, to: :type
|
|
31
33
|
map_attribute :form, to: :form
|
|
32
34
|
map_attribute :fixed, to: :fixed
|
|
35
|
+
map_vc_attributes
|
|
33
36
|
map_attribute :default, to: :default
|
|
34
37
|
map_element :annotation, to: :annotation
|
|
35
38
|
map_element :simpleType, to: :simple_type
|
|
@@ -5,6 +5,8 @@ module Lutaml
|
|
|
5
5
|
module Schema
|
|
6
6
|
module Xsd
|
|
7
7
|
class Element < Base
|
|
8
|
+
include VcConditionalAttributes
|
|
9
|
+
|
|
8
10
|
attribute :id, :string
|
|
9
11
|
attribute :ref, :string
|
|
10
12
|
attribute :name, :string
|
|
@@ -49,6 +51,7 @@ module Lutaml
|
|
|
49
51
|
map_attribute :substitutionGroup, to: :substitution_group
|
|
50
52
|
map_element :complexType, to: :complex_type
|
|
51
53
|
map_element :simpleType, to: :simple_type
|
|
54
|
+
map_vc_attributes
|
|
52
55
|
map_element :annotation, to: :annotation
|
|
53
56
|
map_element :keyref, to: :keyref
|
|
54
57
|
map_element :unique, to: :unique
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
class MaxScale < Base
|
|
8
|
+
attribute :fixed, :string
|
|
9
|
+
attribute :value, :integer
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
element "maxScale"
|
|
13
|
+
mixed_content
|
|
14
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
15
|
+
|
|
16
|
+
map_attribute :value, to: :value
|
|
17
|
+
map_attribute :fixed, to: :fixed
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :max_scale)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Schema
|
|
6
|
+
module Xsd
|
|
7
|
+
class MinScale < Base
|
|
8
|
+
attribute :fixed, :string
|
|
9
|
+
attribute :value, :integer
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
element "minScale"
|
|
13
|
+
mixed_content
|
|
14
|
+
namespace Lutaml::Xml::Schema::XsdNamespace
|
|
15
|
+
|
|
16
|
+
map_attribute :value, to: :value
|
|
17
|
+
map_attribute :fixed, to: :fixed
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Lutaml::Xml::Schema::Xsd.register_model(self, :min_scale)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -5,6 +5,8 @@ module Lutaml
|
|
|
5
5
|
module Schema
|
|
6
6
|
module Xsd
|
|
7
7
|
class RestrictionSimpleType < Base
|
|
8
|
+
include VcConditionalAttributes
|
|
9
|
+
|
|
8
10
|
attribute :id, :string
|
|
9
11
|
attribute :base, :string
|
|
10
12
|
attribute :annotation, :annotation
|
|
@@ -21,6 +23,10 @@ module Lutaml
|
|
|
21
23
|
initialize_empty: true
|
|
22
24
|
attribute :total_digits, :total_digits, collection: true,
|
|
23
25
|
initialize_empty: true
|
|
26
|
+
attribute :min_scale, :min_scale, collection: true,
|
|
27
|
+
initialize_empty: true
|
|
28
|
+
attribute :max_scale, :max_scale, collection: true,
|
|
29
|
+
initialize_empty: true
|
|
24
30
|
attribute :max_exclusive, :max_exclusive, collection: true,
|
|
25
31
|
initialize_empty: true
|
|
26
32
|
attribute :min_exclusive, :min_exclusive, collection: true,
|
|
@@ -50,6 +56,9 @@ module Lutaml
|
|
|
50
56
|
map_element :simple_type, to: :simple_type
|
|
51
57
|
map_element :enumeration, to: :enumeration
|
|
52
58
|
map_element :totalDigits, to: :total_digits
|
|
59
|
+
map_vc_attributes
|
|
60
|
+
map_element :minScale, to: :min_scale
|
|
61
|
+
map_element :maxScale, to: :max_scale
|
|
53
62
|
map_element :maxExclusive, to: :max_exclusive
|
|
54
63
|
map_element :minExclusive, to: :min_exclusive
|
|
55
64
|
map_element :maxInclusive, to: :max_inclusive
|