Commit 16a60a1b authored by Nugine's avatar Nugine
Browse files

refactor(codegen): move to v2

parent 370ec377
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@
)]

mod v1;
mod v2;

fn main() {
    v1::run();
    v2::run();
}
+4 −11
Original line number Diff line number Diff line
use crate::v2::smithy;
use crate::v2::utils::o;

mod rust;
mod smithy;

mod access;
mod dto;
@@ -14,17 +16,8 @@ mod aws_proxy;

use codegen_writer::Codegen;

fn o<T: ToOwned + ?Sized>(x: &T) -> T::Owned {
    x.to_owned()
}

pub fn run() {
    let model: smithy::Model = {
        let json_path = "model/s3.json";
        let json_file = std::fs::read(json_path).unwrap();
        serde_json::from_slice(&json_file).unwrap()
    };
    assert_eq!(model.smithy, "2.0");
    let model = smithy::Model::load_json("model/s3.json");

    let ops = ops::collect_operations(&model);
    let rust_types = dto::collect_rust_types(&model, &ops);

codegen/src/v2/mod.rs

0 → 100644
+5 −0
Original line number Diff line number Diff line
pub mod utils;

pub mod smithy;

pub fn run() {}
+9 −0
Original line number Diff line number Diff line
@@ -163,6 +163,15 @@ pub struct MapValue {
    // pub traits: Traits,
}

impl Model {
    pub fn load_json(path: &str) -> Self {
        let json = std::fs::read_to_string(path).unwrap();
        let model: Self = serde_json::from_str(&json).unwrap();
        assert_eq!(model.smithy, "2.0");
        model
    }
}

impl Traits {
    pub fn get(&self, key: &str) -> Option<&Value> {
        let map = self.0.as_ref()?;
+3 −0
Original line number Diff line number Diff line
pub fn o<T: ToOwned + ?Sized>(x: &T) -> T::Owned {
    x.to_owned()
}