-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(framework): Added smithy, smithy-core and smithy-generator crates #9249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Changed Files
|
crates/smithy-core/src/generator.rs
Outdated
| fn generate_shape_definition( | ||
| &self, | ||
| name: &str, | ||
| shape: &crate::types::SmithyShape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| shape: &crate::types::SmithyShape, | |
| shape: &types::SmithyShape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved, thanks.
crates/smithy-core/src/generator.rs
Outdated
| |target: &str| self.resolve_type(target, current_namespace, shape_to_namespace); | ||
|
|
||
| match shape { | ||
| crate::types::SmithyShape::Structure { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| crate::types::SmithyShape::Structure { | |
| types::SmithyShape::Structure { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved, thanks.
crates/smithy-core/src/generator.rs
Outdated
| def.push('}'); | ||
| def | ||
| } | ||
| crate::types::SmithyShape::Union { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| crate::types::SmithyShape::Union { | |
| types::SmithyShape::Union { |
import and use it, fix in other places too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved, thanks.
Pull Request is not mergeable
…pay-new-field * 'main' of github.com:juspay/hyperswitch: (21 commits) feat(payments): add tokenization action handling to payment flow for braintree (#9506) feat(connector): [Loonio] Add template code (#9586) fix(connector): [paysafe] make `eci_indicator` field optional (#9591) fix(core): add should_call_connector_customer function to connector specification (#9569) feat(ucs): Add profile ID to lineage tracking in Unified Connector Service (#9559) feat(core): Add support for partial auth in proxy payments [V2] (#9503) chore(version): 2025.09.30.0 fix(authorizedotnet): refund via ucs missing connector_metadata (#9581) feat(auth): add new authentication to communicate between microservices (#9547) Fix: Ideal Giropay Country Currency Config (#9552) feat(connector): [ACI] cypress added (#9502) feat(connector): Add Peachpayments Cypress (#9573) chore(version): 2025.09.29.0 feat(finix): template code (#9557) feat(cypress): add cypress test-cases for manual retry (#9505) feat(core): update additional payment method data in psync response (#9519) feat(connector): [Checkout] Add Google Pay Predecrypt Flow (#9130) feat(framework): Added smithy, smithy-core and smithy-generator crates (#9249) fix(core): add request_extended_authorization in the payment attempt and populate it in the payment response (#9492) chore(version): 2025.09.26.0 ...
Type of Change
Description
Overview of the Three Crates
1. smithy crate (Procedural Macro)
This is a procedural macro crate that provides the
#[derive(SmithyModel)]attribute. It's the entry point for developers who want to generate Smithy models from their Rust structs.Key characteristics:
proc-macro = true)crates/smithy/proc-macro2,quote,syn,smithy-coreSmithyModelderive macro2. smithy-core crate (Core Logic)
This contains the fundamental types and logic for Smithy model generation. It acts as the shared foundation between the macro and the generator.
Key characteristics:
Type: Library crate
Location:
crates/smithy-core/Dependencies:
serde,serde_json,syn,proc-macro2Main modules:
types.rs- Core data structures (SmithyModel, SmithyShape, SmithyTrait, etc.)generator.rs- SmithyGenerator for converting models to IDL files3. smithy-generator crate (Code Generation Tool)
This is an executable that scans the entire workspace for structs annotated with
#[derive(SmithyModel)]and generates the corresponding Smithy IDL files.Key characteristics:
Type: Binary crate with build script
Location:
crates/smithy-generator/Dependencies:
smithy-core, workspace crates (api_models,common_enums, etc.)Components:
build.rs- Workspace scanner and registry generatormain.rs- IDL file generatorHow They Work Together
Step 1: Developer Annotation
A developer annotates their Rust struct or enum with the derive macro:
Step 2: Procedural Macro Processing (
smithycrate)When the code is compiled, the
smithycrate's procedural macro:Parses the struct/enum definition using
synExtracts metadata from
#[smithy(...)]attributes (namespace, constraints, field types)Generates implementation of the
SmithyModelGeneratortrait for the annotated typeHandles complex scenarios like:
#[serde(flatten)])Option<T>)Vec<T>,HashMap<K,V>)The generated code implements
SmithyModelGenerator::generate_smithy_model()which returns aSmithyModelcontaining the structure definition.Step 3: Build-Time Discovery (
smithy-generatorbuild script)The
smithy-generatorcrate has a build script (build.rs) that:Scans the entire workspace recursively through all
crates/subdirectoriesUses regex parsing to find structs/enums with
#[derive(SmithyModel)]Generates a registry file (
model_registry.rs) containing:discover_smithy_models()function that callsgenerate_smithy_model()on each typeStep 4: IDL Generation (
smithy-generatorexecutable)When the
smithy-generatorbinary runs:discover_smithy_models()smithy-coreto convert models to Smithy IDL syntax.smithyfiles tosmithy/models/directoryStep 5: Smithy IDL Output
The final output is proper Smithy IDL files like:
Key Design Patterns
Type Resolution System
The
smithy-core/types.rscontains sophisticated type resolution logic that:String→smithy.api#String)Vec<T>→Listshapes,Option<T>→ optional members)Constraint System
The framework supports rich constraint modeling:
pattern,range,lengthhttpLabel,httpQueryrequired,mixinWorkspace Integration
The build script approach allows:
This architecture provides a seamless developer experience where you simply derive
SmithyModelon your types, and the toolchain automatically discovers them and generates proper Smithy IDL files during the build process.Additional Changes
Motivation and Context
How did you test it?
There are no test cases for this PR, since this is just addition of the Smithy Model generation framework to Hyperswitch. The only way to test this PR is to add the derive macros in structs and check the model generation, but that will be done in subsequent PRs.
Checklist
cargo +nightly fmt --allcargo clippy