Skip to content

Add Rust JSON-LD option#39

Merged
JR-1991 merged 7 commits intomainfrom
rust-json-ld
Oct 13, 2025
Merged

Add Rust JSON-LD option#39
JR-1991 merged 7 commits intomainfrom
rust-json-ld

Conversation

@JR-1991
Copy link
Copy Markdown
Collaborator

@JR-1991 JR-1991 commented Oct 9, 2025

This pull request introduces support for generating Rust code with JSON-LD features and refines the handling of default values and serialization attributes in Rust struct generation. The changes add a new workflow to test Rust code generation with JSON-LD, update templates to support JSON-LD headers and contexts, and improve default value handling using the derivative crate. Supporting files and dependencies for the new JSON-LD environment are also included.

Rust Code Generation and JSON-LD Support

  • Added a new GitHub Actions workflow job (rust-ld) to test Rust code generation with JSON-LD, including Docker setup and test execution. (.github/workflows/test.yml)
  • Updated the Rust Jinja template to generate structs with optional JSON-LD headers, additional properties, and context management functions, including new macros and type definitions for JSON-LD support. (templates/rust.jinja) [1] [2] [3] [4] [5] [6]

Default Value Handling and Serialization Improvements

  • Replaced manual #[serde(default)] attributes with enhanced logic using the derivative crate to provide more accurate default value handling for struct fields, reflected in generated test files. (templates/rust.jinja, tests/data/expected_rust.rs, tests/data/expected_rust_forbidden.rs) [1] [2] F1419f02L14R15)

Environment and Dependency Setup for JSON-LD Testing

  • Added a new Rust environment for JSON-LD tests, including .gitignore, Cargo.toml with required dependencies (derivative, uuid, etc.), and a Dockerfile for building and testing. (tests/envs/rust-ld/.gitignore, tests/envs/rust-ld/Cargo.toml, tests/envs/rust-ld/Dockerfile) [1] [2] [3]

Introduces JSON-LD header generation and related types to the Rust template when enabled in config. Refactors struct generation to use the Derivative crate for custom Default implementations, and updates serde attributes to remove redundant defaults. Test expectations updated to reflect new struct derivations and attribute handling.
Introduces support for rendering the internal schema of a DataModel via a new Templates::Internal variant. Implements the render_internal_schema function to serialize the model as pretty-printed JSON.
Introduces a new test environment for Rust with JSON-LD code generation under tests/envs/rust-ld, including Dockerfile, Cargo.toml, and test suite. Updates GitHub Actions workflow to add a 'rust-ld' job for building and testing the new environment.
@JR-1991 JR-1991 self-assigned this Oct 9, 2025
@JR-1991 JR-1991 added the enhancement New feature or request label Oct 9, 2025
@JR-1991 JR-1991 changed the title Rust json ld Add Rust JSON-LD option Oct 9, 2025
The test workflow now includes the '-O jsonld' flag when running the convert command, enabling JSON-LD output generation for improved testing coverage.
Added the 'derivative' crate version 2.2.0 to the Rust test environment dependencies.
Moved the uuid dependency above derive_builder for improved organization in the dependencies list.
Introduces a new test for Rust JSON-LD export in exporters.rs and adds the expected output file tests/data/expected_rust_ld.rs to verify correct rendering.
@JR-1991 JR-1991 marked this pull request as ready for review October 13, 2025 15:01
@JR-1991 JR-1991 merged commit 6ac22a9 into main Oct 13, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant