Skip to content

[WIP] Add JSON Structure to Rust conversion implementation - #70

Closed
clemensv with Copilot wants to merge 2 commits into
masterfrom
copilot/add-json-structure-to-rust
Closed

[WIP] Add JSON Structure to Rust conversion implementation#70
clemensv with Copilot wants to merge 2 commits into
masterfrom
copilot/add-json-structure-to-rust

Conversation

Copilot AI commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

Plan: Implement structuretorust - JSON Structure to Rust Conversion

Based on exploration of the codebase, I will implement structuretorust following these patterns:

Implementation Checklist

  • Create avrotize/structuretorust.py module following patterns from:

    • avrotorust.py for Rust code generation and templates
    • structuretocsharp.py and structuretopython.py for JSON Structure schema handling
  • Create Jinja templates in avrotize/structuretorust/ directory:

    • dataclass_struct.rs.jinja - for struct generation
    • dataclass_enum.rs.jinja - for enum generation
    • dataclass_union.rs.jinja - for union/choice types
  • Implement type mappings for JSON Structure Core types:

    • Primitives: string, number, boolean, null
    • Extended: binary, int8-128, uint8-128, float8/float/double, decimal, date, datetime, time, duration, uuid, uri, jsonpointer
    • Compound: object, array, set, map, tuple, any, choice (tagged/inline unions)
  • Support JSON Structure features:

    • Namespaces and definitions
    • Type references ($ref)
    • Extensions ($extends) and add-ins ($offers/$uses)
    • Abstract types
    • Required/optional properties
    • Type annotations (maxLength, precision, scale, contentEncoding)
  • Register CLI commands in commands.json for:

    • s2rust - Convert JSON Structure to Rust
  • Register functions in __init__.py:

    • convert_structure_to_rust
    • convert_structure_schema_to_rust
  • Create comprehensive tests in test/test_structuretorust.py:

    • Test basic types and compounds
    • Test namespaces and references
    • Test choice types (tagged and inline unions)
    • Test abstract types and inheritance
  • Generate Cargo.toml and lib.rs for Rust projects

  • Support Serde annotations for JSON serialization

Key Design Decisions

  1. Follow avrotorust patterns: Use similar struct generation, module organization, and template structure
  2. Reuse JSON Structure handling: Adopt $ref resolution, schema registry, and abstract type validation from structuretocsharp.py
  3. Minimal changes: Only add new files, no modifications to existing converters
  4. Test-driven: Create tests alongside implementation for continuous validation
Original prompt

This section details on the original issue you should resolve

<issue_title>Add structuretorust: JSON Structure to Rust conversion</issue_title>
<issue_description>## Overview
Implement conversion from JSON Structure schemas to Rust structs.

Requirements

This conversion should:

  1. Lean on the corresponding Avro conversion (avrotorust) as precedent for output structure, including use of Jinja templates where applicable
  2. Cover the full breadth of the JSON Structure Core spec as defined in draft-vasters-json-structure-core-00
  3. Follow the patterns established by structuretocsharp and structuretopython, including their continued support for Avro schemas

Implementation Guidance

  • Review avrotize/avrotorust.py for output patterns and template usage
  • Review avrotize/structuretocsharp.py and avrotize/structuretopython.py for the JSON Structure handling patterns
  • Ensure all JSON Structure Core types are supported:
    • JSON Primitive Types: string, number, boolean, null
    • Extended Primitive Types: binary, int8-128, uint8-128, float8/float/double, decimal, date, datetime, time, duration, uuid, uri, jsonpointer
    • Compound Types: object, array, set, map, tuple, any, choice (both tagged and inline unions)
  • Support JSON Structure-specific features:
    • Namespaces and definitions
    • Type references ($ref)
    • Extensions ($extends) and add-ins ($offers/$uses)
    • Abstract types
    • Required/optional properties
    • Type annotations (maxLength, precision, scale, contentEncoding, etc.)

References

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com>
@clemensv

Copy link
Copy Markdown
Owner

@copilot

Additional Requirements

Documentation

The README.md file needs to be updated to include documentation for this new conversion feature, following the pattern established for existing conversions.

Testing

All tests must follow the established testing patterns:

  • For programming language outputs (C#, Java, Python, TypeScript, JavaScript, C++, Go, Rust): Tests must run the embedded tests in the code outputs to verify correctness
  • For schema language outputs (CSV, Protobuf, XSD, GraphQL, etc.): Tests must compare the generated output to a desired output reference (-ref) schema stored in the /test/struct directory

This follows the pattern established for the Avro conversion tests in the repository.

@clemensv

Copy link
Copy Markdown
Owner

Closing duplicate PR. Keeping the newer PR #94 for this issue.

@clemensv clemensv closed this Nov 20, 2025
@clemensv
clemensv deleted the copilot/add-json-structure-to-rust branch November 20, 2025 10:16
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.

Add structuretorust: JSON Structure to Rust conversion

2 participants