You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/001-macro-alignment-adr.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ The GTS specification (v0.8) provides clear guidance that contradicts several as
102
102
103
103
### 3.1 Identity fields are not universally required
104
104
105
-
The spec defines five categories of JSON documents (spec section 11.1, Rule C):
105
+
The spec defines five categories of JSON documents ([spec §11.1, Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)):
106
106
107
107
1.**GTS entity schemas** — have `$schema` and `$id` starting with `gts://`
108
108
2.**Non-GTS schemas** — have `$schema` but no GTS `$id`
@@ -173,15 +173,15 @@ The spec shows multiple patterns:
173
173
|`orders.order.v1.0~`| UUID | (none) | Plain data entity |
174
174
|`idp.contact.v1.0~`| UUID | (none) | Plain data entity |
175
175
176
-
**Conclusion**: There is no single "correct" identity pattern. The choice is domain-specific and implementation-defined (spec section 11.1). The macro should support these patterns, not mandate one.
176
+
**Conclusion**: There is no single "correct" identity pattern. The choice is domain-specific and implementation-defined ([spec §11.1](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)). The macro should support these patterns, not mandate one.
177
177
178
178
### 3.4 Field names are implementation-defined
179
179
180
-
From spec section 11.1:
180
+
From [spec §11.1](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories):
181
181
182
182
> *"The exact field names used for instance IDs and instance types are **implementation-defined** and may be **configuration-driven** (different systems may look for identifiers in different fields)."*
183
183
184
-
And spec section 9.1:
184
+
And [spec §9.1](https://github.com/GlobalTypeSystem/gts-spec#91---identifier-reference-in-json-and-json-schema):
185
185
186
186
> *"Field naming: typically `id` (alternatives: `gtsId`, `gts_id`)"*
- In the generated JSON Schema, annotates the property with `"x-gts-ref": "/$id"` per spec section 9.6
289
+
- In the generated JSON Schema, annotates the property with `"x-gts-ref": "/$id"` per [spec §9.6](https://github.com/GlobalTypeSystem/gts-spec#96---x-gts-ref-support)
290
290
- Can only appear once per struct, and is mutually exclusive with `#[gts(instance_id)]`
291
291
292
292
**`#[gts(instance_id)]`:**
293
293
- Validates that the field type is `GtsInstanceId`
294
-
- In the generated JSON Schema, annotates the property with `"x-gts-ref": "/$id"` per spec section 9.6
294
+
- In the generated JSON Schema, annotates the property with `"x-gts-ref": "/$id"` per [spec §9.6](https://github.com/GlobalTypeSystem/gts-spec#96---x-gts-ref-support)
295
295
- Can only appear once per struct, and is mutually exclusive with `#[gts(type_field)]`
296
296
297
297
**`#[gts(skip)]`:**
@@ -581,7 +581,7 @@ The current macro generates all `GtsSchemaId` fields with a generic `x-gts-ref`:
But the GTS spec examples (section 9.6) use a more precise self-reference annotation on identity fields — `"x-gts-ref": "/$id"` — meaning "this field's value must equal the current schema's `$id`":
584
+
But the GTS spec examples ([§9.6](https://github.com/GlobalTypeSystem/gts-spec#96---x-gts-ref-support)) use a more precise self-reference annotation on identity fields — `"x-gts-ref": "/$id"` — meaning "this field's value must equal the current schema's `$id`":
585
585
586
586
```json
587
587
"type": { "type": "string", "x-gts-ref": "/$id" }
@@ -667,7 +667,7 @@ The current macro has 31 compile-fail tests. The redesign affects their status:
667
667
668
668
2.**`GTS_SCHEMA_PROPERTIES` constant**: ~~The current macro generates `GTS_SCHEMA_PROPERTIES: &'static str` as a comma-separated string derived from the `properties` parameter. With `properties` removed, this constant could either be auto-generated from struct fields or removed entirely.~~**Resolved**: The derive macro will auto-generate this constant from the struct's field names, excluding fields with `#[gts(skip)]` or `#[serde(skip)]`. The struct fields are already available to the macro at compile time — no user input needed.
669
669
670
-
3.**Schema traits (`x-gts-traits-schema` / `x-gts-traits`)**: The GTS spec (section 9.7) defines a trait system for schema-level metadata — semantic annotations like retention rules, topic associations, and processing directives that are not part of the instance data model. The current macro does not generate these, and this ADR does not address them. Examples from the spec:
670
+
3.**Schema traits (`x-gts-traits-schema` / `x-gts-traits`)**: The GTS spec ([§9.7](https://github.com/GlobalTypeSystem/gts-spec#97---schema-traits-x-gts-traits-schema--x-gts-traits)) defines a trait system for schema-level metadata — semantic annotations like retention rules, topic associations, and processing directives that are not part of the instance data model. The current macro does not generate these, and this ADR does not address them. Examples from the spec:
Copy file name to clipboardExpand all lines: docs/001-macro-alignment-implementation-plan.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This plan implements the redesign specified in [ADR-001](./001-macro-alignment-adr.md). The work is structured in phases that can each be independently tested and merged.
4
4
5
-
Each phase references the GTS specification sections that justify the design choices. Spec references use the format `[Spec §X.Y]` pointing to [`.gts-spec/README.md`](/.gts-spec/README.md).
5
+
Each phase references the GTS specification sections that justify the design choices. Spec references link to the [GTS Specification](https://github.com/GlobalTypeSystem/gts-spec).
6
6
7
7
---
8
8
@@ -35,23 +35,23 @@ enum GtsFieldAttr {
35
35
```
36
36
37
37
**Spec justification:**
38
-
-`schema_id` — maps to the `$id` in JSON Schema documents [Spec §9.1, §11.1 Rule C category 1]
-`type_field` / `instance_id` — optional, maps to anonymous instance `type` field [Spec §3.7, §11.1 Rule C categories 4-5] or well-known instance `id` field. Made optional because not all GTS schemas require instance-level identity (e.g., `order.v1.0~`, `contact.v1.0~` have plain UUID `id` fields with no GTS semantics) [Spec §11.1 Rule C category 3]. **This is the fix for Issue #72.**
41
-
- Field names are implementation-defined [Spec §11.1: "field names are implementation-defined and may be configuration-driven"]
38
+
-`schema_id` — maps to the `$id` in JSON Schema documents [[Spec §9.1](https://github.com/GlobalTypeSystem/gts-spec#91---identifier-reference-in-json-and-json-schema), [§11.1 Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)]
-`type_field` / `instance_id` — optional, maps to anonymous instance `type` field [[Spec §3.7](https://github.com/GlobalTypeSystem/gts-spec#37-well-known-and-anonymous-instances), [§11.1 Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)] or well-known instance `id` field. Made optional because not all GTS schemas require instance-level identity (e.g., `order.v1.0~`, `contact.v1.0~` have plain UUID `id` fields with no GTS semantics) [[Spec §11.1 Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)]. **This is the fix for Issue #72.**
41
+
- Field names are implementation-defined [[Spec §11.1](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)]
42
42
43
43
### 1.2 Validation (carried over from current macro)
44
44
45
45
Implement all validations that apply to the new design:
46
46
47
-
-`schema_id` format validation via `gts_id::validate_gts_id()`[Spec §2.1, §2.3, §8.1]
48
-
- Version match between struct name suffix and schema ID [Spec §4]
49
-
- Segment count: no `extends` → single segment; `extends` → multi-segment [Spec §2.2: chainedidentifiers express type derivation]
47
+
-`schema_id` format validation via `gts_id::validate_gts_id()`[Spec §2.1, §2.3, §8.1](https://github.com/GlobalTypeSystem/gts-spec)
48
+
- Version match between struct name suffix and schema ID [Spec §4](https://github.com/GlobalTypeSystem/gts-spec#4-versioning)
49
+
- Segment count: no `extends` → single segment; `extends` → multi-segment [[Spec §2.2](https://github.com/GlobalTypeSystem/gts-spec#22-chained-identifiers)]
50
50
- Only named structs (no tuple structs, enums)
51
-
- Max 1 generic type parameter (GTS inheritance is single-chain, not multi-branch) [Spec §3.2]
52
-
-`#[gts(type_field)]` must be on a `GtsSchemaId` field — the `type` field value is a GTS type identifier (ending with `~`) [Spec §3.7: anonymousinstances, §11.1 Rule C category 5]
53
-
-`#[gts(instance_id)]` must be on a `GtsInstanceId` field — the `id` field value is a GTS instance identifier (no trailing `~`) [Spec §3.7: well-knowninstances, §11.1 Rule C category 4]
54
-
-`#[gts(type_field)]` and `#[gts(instance_id)]` are mutually exclusive — a schema's instances follow either the well-known or anonymous pattern [Spec §3.7: "well-known" vs "anonymous" are distinct categories]
51
+
- Max 1 generic type parameter (GTS inheritance is single-chain, not multi-branch) [[Spec §3.2](https://github.com/GlobalTypeSystem/gts-spec#32-gts-types-inheritance)]
52
+
-`#[gts(type_field)]` must be on a `GtsSchemaId` field — the `type` field value is a GTS type identifier (ending with `~`) [[Spec §3.7](https://github.com/GlobalTypeSystem/gts-spec#37-well-known-and-anonymous-instances), [§11.1 Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)]
53
+
-`#[gts(instance_id)]` must be on a `GtsInstanceId` field — the `id` field value is a GTS instance identifier (no trailing `~`) [[Spec §3.7](https://github.com/GlobalTypeSystem/gts-spec#37-well-known-and-anonymous-instances), [§11.1 Rule C](https://github.com/GlobalTypeSystem/gts-spec#111-global-rules-schema-vs-instance-normalization-and-document-categories)]
54
+
-`#[gts(type_field)]` and `#[gts(instance_id)]` are mutually exclusive — a schema's instances follow either the well-known or anonymous pattern [[Spec §3.7](https://github.com/GlobalTypeSystem/gts-spec#37-well-known-and-anonymous-instances)]
55
55
- At most one `#[gts(type_field)]` and one `#[gts(instance_id)]` per struct
@@ -94,23 +94,23 @@ If the struct does not already derive `schemars::JsonSchema`, inject it. This is
94
94
### 2.2 GtsSchema trait implementation
95
95
96
96
Generate the `GtsSchema` trait impl with:
97
-
-`SCHEMA_ID` — from `schema_id` attribute [Spec §9.1 — maps to `$id` in JSON Schema]
97
+
-`SCHEMA_ID` — from `schema_id` attribute [[Spec §9.1](https://github.com/GlobalTypeSystem/gts-spec#91---identifier-reference-in-json-and-json-schema)]
98
98
-`GENERIC_FIELD` — detected from struct fields (field whose type matches the generic param)
99
99
-`gts_schema_with_refs()` / `gts_schema_with_refs_allof()` — runtime schema generation using `schemars::schema_for!(Self)`, resolving `$ref` for `GtsSchemaId`/`GtsInstanceId`
100
-
-`innermost_schema_id()`, `innermost_schema()`, `collect_nesting_path()` — for generic base structs [Spec §3.2 — left-to-right inheritance chain traversal]
100
+
-`innermost_schema_id()`, `innermost_schema()`, `collect_nesting_path()` — for generic base structs [[Spec §3.2](https://github.com/GlobalTypeSystem/gts-spec#32-gts-types-inheritance)]
101
101
-`wrap_in_nesting_path()` — inherited from trait default
102
102
103
103
For `extends` structs:
104
-
-`allOf` + `$ref` schema composition [Spec §9.1 — `$ref` must use `gts://` prefix; Spec §3.2 — derived types use `allOf` to reference base]
-`gts_instance_json(&self) -> Value` — with `where Self: Serialize` bound
@@ -131,7 +131,7 @@ The `gts_schema_with_refs_allof()` method should include `"description"` in the
131
131
132
132
When generating the runtime schema, if a field has `#[gts(type_field)]` or `#[gts(instance_id)]`, override its schema property to use `"x-gts-ref": "/$id"` instead of the default `"x-gts-ref": "gts.*"` from `json_schema_value()`.
-`"x-gts-ref": "/$id"` — relative self-reference; field value must equal the current schema's `$id`. Used on identity fields that identify *this* entity (e.g., `type` on events, `id` on topics).
136
136
-`"x-gts-ref": "gts.*"` — generic reference; field must be any valid GTS identifier. Used on fields that reference *other* entities (e.g., `subjectType` referencing an order schema).
0 commit comments