Skip to content

Commit

Permalink
Feat/enum types (#97)
Browse files Browse the repository at this point in the history
* add Document to common

Signed-off-by: stevelr <[email protected]>

* add utility for dumping smithy model in json

Signed-off-by: stevelr <[email protected]>

* - adds common::Document value type to correspond with smithy "Document"
- adds Unit type
- generate union/enums with unit type and serialized with numeric value
- initial support for borrowed struct definitions
- new command line utility `dump-json-model` to dump smithy model
- add fixed_array and fixed_map to simplify decoding
- bump weld-codegen to 0.4.3
- bump wasmbus-rpc to 0.8.4

Signed-off-by: stevelr <[email protected]>

* source file for common::Document, Number, and DocumentRef

Signed-off-by: stevelr <[email protected]>
  • Loading branch information
stevelr authored Mar 22, 2022
1 parent bac28da commit a9afe76
Show file tree
Hide file tree
Showing 18 changed files with 1,768 additions and 507 deletions.
8 changes: 7 additions & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "weld-codegen"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
authors = [ "wasmcloud Team" ]
license = "Apache-2.0"
Expand All @@ -18,12 +18,14 @@ BigInteger = []
BigDecimal = []

[dependencies]
anyhow = "1.0"
atelier_assembler = "0.1"
atelier_core = "0.2"
atelier_json = "0.2"
atelier_smithy = "0.2"
bytes = "1.0"
cfg-if = "1.0"
clap = { version = "3.1", features = [ "derive" ] }
directories = "4.0"
downloader = { version = "0.2", features = ["rustls-tls"], default-features = false }
handlebars = "4.0"
Expand All @@ -47,3 +49,7 @@ path = "src/lib.rs"
[[bin]]
name = "codegen"
path = "bin/gen.rs"

[[bin]]
name = "dump-smithy-model"
path = "bin/dump-smithy-model.rs"
34 changes: 34 additions & 0 deletions codegen/bin/dump-smithy-model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! dump model in json
use anyhow::{anyhow, Context, Result};
use clap::{self, Parser};
use std::path::PathBuf;
use weld_codegen::{config::CodegenConfig, sources_to_model};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// codegen.toml file (default: "./codegen.toml")
#[clap(short, long)]
config: Option<PathBuf>,
}

fn main() -> Result<()> {
let args = Args::parse();
let config_path = args
.config
.unwrap_or_else(|| PathBuf::from("./codegen.toml"));
if !config_path.is_file() {
return Err(anyhow!("missing config file {}", &config_path.display()));
}
let config = std::fs::read_to_string(&config_path)
.with_context(|| format!("error reading config file {}", config_path.display()))?
.parse::<CodegenConfig>()?;
let base_dir = config_path.parent().unwrap().to_path_buf();
let model = sources_to_model(&config.models, &base_dir, 0)?;
let json_model = atelier_json::model_to_json(&model);

let out = std::io::stdout();
serde_json::to_writer(&out, &json_model)?;
Ok(())
}
2 changes: 1 addition & 1 deletion codegen/codegen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[[models]]
url = "https://cdn.jsdelivr.net/gh/wasmcloud/interfaces@d6ae2dd196aae3c2486e747eb1b3cd188ea71132/core/wasmcloud-core.smithy"
[[models]]
url = "https://cdn.jsdelivr.net/gh/wasmcloud/interfaces@cb504c8b7cfcee0a8c5ecdedf75757f4718ad4e6/core/wasmcloud-model.smithy"
url = "https://cdn.jsdelivr.net/gh/wasmcloud/interfaces@e0f205da8a0e1549497571c3e994a1851480621c/core/wasmcloud-model.smithy"

[rust]
output_dir = "."
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/codegen_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const WASMBUS_RPC_CRATE: &str = "wasmbus_rpc";
const DEFAULT_MAP_TYPE: &str = "dict"; // python 3.9+
const DEFAULT_LIST_TYPE: &str = "list"; // python 3.9+
const DEFAULT_SET_TYPE: &str = "set"; // python 3.9+
const DEFAULT_DOCUMENT_TYPE: &str = "bytes";
const DEFAULT_DOCUMENT_TYPE: &str = "Document";

/// declarations for sorting. First sort key is the type (simple, then map, then struct).
/// In rust, sorting by BytesMut as the second key will result in sort by item name.
Expand Down
Loading

0 comments on commit a9afe76

Please sign in to comment.