Skip to content

Commit 5376ad5

Browse files
author
Andre Smith
committed
add links to specification in proposal and adr
1 parent b6fa2fa commit 5376ad5

3 files changed

Lines changed: 56 additions & 56 deletions

File tree

docs/001-macro-alignment-adr.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The GTS specification (v0.8) provides clear guidance that contradicts several as
102102

103103
### 3.1 Identity fields are not universally required
104104

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)):
106106

107107
1. **GTS entity schemas** — have `$schema` and `$id` starting with `gts://`
108108
2. **Non-GTS schemas** — have `$schema` but no GTS `$id`
@@ -173,15 +173,15 @@ The spec shows multiple patterns:
173173
| `orders.order.v1.0~` | UUID | (none) | Plain data entity |
174174
| `idp.contact.v1.0~` | UUID | (none) | Plain data entity |
175175

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.
177177

178178
### 3.4 Field names are implementation-defined
179179

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):
181181

182182
> *"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)."*
183183
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):
185185

186186
> *"Field naming: typically `id` (alternatives: `gtsId`, `gts_id`)"*
187187
> *"Field naming: `type` (alternatives: `gtsType`, `gts_type`)"*
@@ -286,12 +286,12 @@ pub internal_cache: HashMap<String, String>,
286286

287287
**`#[gts(type_field)]`:**
288288
- Validates that the field type is `GtsSchemaId`
289-
- 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)
290290
- Can only appear once per struct, and is mutually exclusive with `#[gts(instance_id)]`
291291

292292
**`#[gts(instance_id)]`:**
293293
- 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)
295295
- Can only appear once per struct, and is mutually exclusive with `#[gts(type_field)]`
296296

297297
**`#[gts(skip)]`:**
@@ -581,7 +581,7 @@ The current macro generates all `GtsSchemaId` fields with a generic `x-gts-ref`:
581581
"type": { "type": "string", "format": "gts-schema-id", "x-gts-ref": "gts.*" }
582582
```
583583

584-
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`":
585585

586586
```json
587587
"type": { "type": "string", "x-gts-ref": "/$id" }
@@ -667,7 +667,7 @@ The current macro has 31 compile-fail tests. The redesign affects their status:
667667

668668
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.
669669

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:
671671

672672
- Base event schema defines a trait schema:
673673
```json

docs/001-macro-alignment-implementation-plan.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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.
44

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).
66

77
---
88

@@ -35,23 +35,23 @@ enum GtsFieldAttr {
3535
```
3636

3737
**Spec justification:**
38-
- `schema_id` — maps to the `$id` in JSON Schema documents [Spec §9.1, §11.1 Rule C category 1]
39-
- `extends` — models left-to-right inheritance via chained identifiers [Spec §2.2, §3.2]
40-
- `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)]
39+
- `extends` — models left-to-right inheritance via chained identifiers [[Spec §2.2](https://github.com/GlobalTypeSystem/gts-spec#22-chained-identifiers), [§3.2](https://github.com/GlobalTypeSystem/gts-spec#32-gts-types-inheritance)]
40+
- `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)]
4242

4343
### 1.2 Validation (carried over from current macro)
4444

4545
Implement all validations that apply to the new design:
4646

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: chained identifiers 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)]
5050
- 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: anonymous instances, §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-known instances, §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)]
5555
- At most one `#[gts(type_field)]` and one `#[gts(instance_id)]` per struct
5656
- Unknown `#[gts(...)]` attributes emit clear errors
5757

@@ -94,23 +94,23 @@ If the struct does not already derive `schemars::JsonSchema`, inject it. This is
9494
### 2.2 GtsSchema trait implementation
9595

9696
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)]
9898
- `GENERIC_FIELD` — detected from struct fields (field whose type matches the generic param)
9999
- `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)]
101101
- `wrap_in_nesting_path()` — inherited from trait default
102102

103103
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]
105-
- Compile-time assertion that parent's `SCHEMA_ID` matches [Spec §3.1 — chain validation]
104+
- `allOf` + `$ref` schema composition [[Spec §9.1](https://github.com/GlobalTypeSystem/gts-spec#91---identifier-reference-in-json-and-json-schema), [§3.2](https://github.com/GlobalTypeSystem/gts-spec#32-gts-types-inheritance)]
105+
- Compile-time assertion that parent's `SCHEMA_ID` matches [[Spec §3.1](https://github.com/GlobalTypeSystem/gts-spec#31-gts-types)]
106106
- Property nesting under parent's generic field
107107

108108
### 2.3 Runtime API methods
109109

110110
Generate on the struct impl:
111-
- `gts_schema_id() -> &'static GtsSchemaId` (LazyLock) [Spec §9.1schema `$id` access]
112-
- `gts_base_schema_id() -> Option<&'static GtsSchemaId>` (LazyLock) [Spec §3.2 — parent segment extraction]
113-
- `gts_make_instance_id(segment) -> GtsInstanceId` [Spec §3.7 — instance ID = schema chain + instance segment]
111+
- `gts_schema_id() -> &'static GtsSchemaId` (LazyLock) [[Spec §9.1](https://github.com/GlobalTypeSystem/gts-spec#91---identifier-reference-in-json-and-json-schema)]
112+
- `gts_base_schema_id() -> Option<&'static GtsSchemaId>` (LazyLock) [[Spec §3.2](https://github.com/GlobalTypeSystem/gts-spec#32-gts-types-inheritance)]
113+
- `gts_make_instance_id(segment) -> GtsInstanceId` [[Spec §3.7](https://github.com/GlobalTypeSystem/gts-spec#37-well-known-and-anonymous-instances)]
114114
- `gts_schema_with_refs_as_string() -> String`
115115
- `gts_schema_with_refs_as_string_pretty() -> String`
116116
- `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
131131

132132
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()`.
133133

134-
**Spec justification** [Spec §9.6]:
134+
**Spec justification** [[Spec §9.6](https://github.com/GlobalTypeSystem/gts-spec#96---x-gts-ref-support)]:
135135
- `"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).
136136
- `"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).
137137

0 commit comments

Comments
 (0)