Skip to content

breaking: refactor GTS macro API: rename methods, add instance serialization, hide internals#26

Merged
Artifizer merged 11 commits intoGlobalTypeSystem:mainfrom
Artifizer:main
Dec 26, 2025
Merged

breaking: refactor GTS macro API: rename methods, add instance serialization, hide internals#26
Artifizer merged 11 commits intoGlobalTypeSystem:mainfrom
Artifizer:main

Conversation

@Artifizer
Copy link
Copy Markdown
Contributor

chore: Makefile - added 'generate-schemas' target
refactor: extract GTS type schema definitions into shared functions
breaking: refactor GTS macro API: rename methods, add instance serialization, hide internals
fix(struct_to_gts_schema): fix generic base struct schema generation to be type-parameter independent

…to be type-parameter independent

When a generic base struct (e.g., TopicV1<P>) was instantiated with a
concrete type parameter (e.g., TopicV1<OrderTopicConfigV1>), it incorrectly
generated a different schema than TopicV1<()>, using the innermost type's
schema ID and incorrectly adding an allOf structure.

Changes:
- Use Self::SCHEMA_ID instead of Self::innermost_schema_id() to determine
  the struct's own schema ID and parent relationship
- Get properties from schemars::schema_for!(Self) for the current struct
  rather than recursively fetching the innermost type's schema
- Replace generic fields with {"type": "object"} placeholders regardless
  of the concrete type parameter used
- Add test_generic_base_struct_schema_consistency() to verify that
  TopicV1<()> and TopicV1<OrderTopicConfigV1> generate identical schemas

This ensures that generic base structs always generate their own base schema
consistently, with the type parameter only affecting compile-time type safety
but not the generated schema structure.

Signed-off-by: Artifizer <artifizer@gmail.com>
…ization, hide internals

API changes:
- Add gts_base_schema_id() returning Option<&'static GtsSchemaId>
- Add gts_instance_json(&self) returning serde_json::Value
- Add gts_instance_json_as_string(&self) returning compact JSON String
- Add gts_instance_json_as_string_pretty(&self) returning pretty JSON String
- Automatically add needed derive(...)
- Rename gts_json_schema_with_refs() to gts_schema_with_refs_as_string()
- Rename gts_json_schema_with_refs_pretty() to gts_schema_with_refs_as_string_pretty()
- Rename make_gts_instance_id() -> gts_make_instance_id() for "gts_" prefix consistency
- Make SCHEMA_ID and BASE_SCHEMA_ID constants private (use methods instead)

Update tests and README documentation with new API.

Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
…done in macro

Signed-off-by: Artifizer <artifizer@gmail.com>
- Add `json_schema_value()` methods to `GtsInstanceId` and `GtsSchemaId`
  in `gts/src/gts.rs` that return canonical JSON Schema representations
- Update `schemars::JsonSchema` implementations to use these shared methods,
  eliminating code duplication
- Update CLI schema generator (`gts-cli/src/gen_schemas.rs`) to use shared
  functions instead of duplicating schema definitions
- Export `GtsSchemaId` from `gts/src/lib.rs` for CLI usage
- Fix schema scanner to properly generate schemas with `x-gts-ref` extensions
  for GTS types

This ensures a single source of truth for GTS type schema definitions,
making them easier to maintain and ensuring consistency between the
macro-generated schemas and CLI-generated schemas.

Generated schema files are included as examples of the scanner output.

Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
…ake code and logic cleaner

Signed-off-by: Artifizer <artifizer@gmail.com>
@Artifizer Artifizer self-assigned this Dec 26, 2025
@Artifizer Artifizer merged commit a900499 into GlobalTypeSystem:main Dec 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant