Skip to content
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

New schema format #2206

Draft
wants to merge 67 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
3cdf3b2
New schema format
aumetra Aug 12, 2024
e4fba7f
Extend proc-macro functionality, add derives to std
aumetra Aug 19, 2024
abaed01
Add rename_all support
aumetra Aug 19, 2024
f34ab22
Deduplicate a little
aumetra Aug 20, 2024
00865e0
Add warnings for unknown serde attributes
aumetra Aug 20, 2024
9e971d6
Add rename option and option to mute warnings
aumetra Aug 21, 2024
c4aa695
Add to `cw_serde`
aumetra Aug 21, 2024
e0af552
Add codegen for cw_schema
aumetra Aug 26, 2024
d392b72
Remove unused dependency
aumetra Aug 26, 2024
571df77
Merge branch 'main' into aw/new-schema
aumetra Aug 26, 2024
9dacb7a
Update lockfiles
aumetra Aug 26, 2024
1259017
Fix doctests
aumetra Aug 26, 2024
59deef9
Add missing derives
aumetra Aug 26, 2024
244cea9
Use `TypeId` internally
aumetra Aug 27, 2024
b960a0d
Allow non-static types to implement the schema
aumetra Aug 27, 2024
34e87ce
Add test for same name in different modules
aumetra Aug 27, 2024
1101aa8
Add some debug assertions
aumetra Aug 27, 2024
9a4bebe
Add non-static lifetime snapshot test
aumetra Aug 27, 2024
4fbc80b
Add explanation of the hack
aumetra Aug 27, 2024
8b209cf
Add impl to write new schema format
aumetra Sep 2, 2024
275784b
Regenerate all schemas
aumetra Sep 2, 2024
b4b7b2b
Allow clippy lint
aumetra Sep 2, 2024
0e7480c
Merge branch 'main' into aw/new-schema
aumetra Oct 1, 2024
286cabd
Fix CI
aumetra Oct 1, 2024
1b337d6
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 1, 2024
bf43ec3
Initial codegen tool
aumetra Oct 7, 2024
4ee73cb
Merge branch 'main' into aw/new-schema
aumetra Oct 8, 2024
27d31ad
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 8, 2024
10ee9fa
Add enum codegen
aumetra Oct 8, 2024
14add23
Add some templates
aumetra Oct 15, 2024
63d647d
Merge branch 'main' into aw/new-schema
aumetra Oct 24, 2024
2780474
Fix enum templates
aumetra Oct 24, 2024
30b0d91
Add struct codegen
aumetra Oct 24, 2024
9855d42
PoC Rust codegen
aumetra Oct 25, 2024
2b560a2
Slight refactor
aumetra Oct 28, 2024
db942c0
Add serde renames for prettier enums
aumetra Oct 28, 2024
f7f5672
Fix Rust enums, add dummy modules for other languages
aumetra Oct 30, 2024
f93d67c
WIP TypeScript codegen
aumetra Oct 30, 2024
386a467
Export enum type in TypeScript
aumetra Oct 30, 2024
08d06c4
Deserialize the full CosmWasm API definition
aumetra Nov 4, 2024
5b7caf0
Add some TypeScript snapshots
aumetra Nov 12, 2024
d91cd1b
More robust non-static type equality
aumetra Nov 12, 2024
4de3214
Add TypeScript compile checks
aumetra Nov 12, 2024
6c6e2ad
feat: Python codegen init
kulikthebird Nov 6, 2024
fc49079
feat: Add Python codegen
kulikthebird Nov 8, 2024
2a737c8
chore: Replace dataclasses and dataclasses_json with pydantic
kulikthebird Nov 22, 2024
126b2b7
TypeScript E2E tests
aumetra Nov 25, 2024
777aca3
chore: Add tests and validate schemas
kulikthebird Nov 26, 2024
dcbc887
Fix TypeScript codegen
aumetra Nov 27, 2024
4e8d217
Add polyfill types to Rust codegen
aumetra Nov 27, 2024
1b38229
Use TypeScript polyfill
aumetra Nov 27, 2024
285abd6
chore: Remove python playground
kulikthebird Nov 27, 2024
297b70e
Merge pull request #2295 from CosmWasm/tkulik/python_codegen
aumetra Dec 2, 2024
6801e88
Fix up a few things
aumetra Dec 2, 2024
f3f338c
Add some Go codegen
aumetra Dec 2, 2024
d2b5896
chore: Update python codegen
kulikthebird Dec 10, 2024
cdd1b55
Merge pull request #2308 from CosmWasm/tkulik/chore/update_python_cod…
aumetra Dec 17, 2024
8cc0688
Add E2E scaffold
aumetra Jan 7, 2025
403e33f
Add Go E2E tests
aumetra Jan 7, 2025
a91f479
Fix some more E2E test issues
aumetra Jan 13, 2025
bd164c0
Rust E2E tests
aumetra Jan 20, 2025
2a367ae
Fix issues with duplicated names
aumetra Jan 20, 2025
4f70890
Merge branch 'main' into aw/new-schema
aumetra Feb 10, 2025
3e56a49
Add missing derives
aumetra Feb 10, 2025
e77dd61
Add support for maps (because that's a thing people do apparently)
aumetra Feb 10, 2025
5a13c0a
Fix lockfiles
aumetra Feb 10, 2025
73a1f2c
Fix CI failures
aumetra Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extend proc-macro functionality, add derives to std
aumetra committed Aug 19, 2024
commit e4fba7f5b1e9bf02e50ed514542e25e662f03aae
283 changes: 236 additions & 47 deletions Cargo.lock

Large diffs are not rendered by default.

116 changes: 70 additions & 46 deletions packages/cw-schema-derive/src/expand.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;

use crate::bail;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{punctuated::Punctuated, DataEnum, DataStruct, DataUnion, DeriveInput, Lit};
use std::borrow::Cow;
use syn::{DataEnum, DataStruct, DataUnion, DeriveInput, Lit};

struct SerdeContainerOptions {
rename_all: Option<syn::LitStr>,
@@ -45,12 +44,16 @@ impl SerdeContainerOptions {
}

struct ContainerOptions {
r#as: Option<syn::Ident>,
r#type: Option<syn::Expr>,
crate_path: syn::Path,
}

impl ContainerOptions {
fn parse(attributes: &[syn::Attribute]) -> syn::Result<Self> {
let mut options = ContainerOptions {
r#as: None,
r#type: None,
crate_path: syn::parse_str("::cw_schema")?,
};

@@ -62,6 +65,10 @@ impl ContainerOptions {
if meta.path.is_ident("crate") {
let stringified: syn::LitStr = meta.value()?.parse()?;
options.crate_path = stringified.parse()?;
} else if meta.path.is_ident("as") {
options.r#as = Some(meta.value()?.parse()?);
} else if meta.path.is_ident("type") {
options.r#type = Some(meta.value()?.parse()?);
} else {
bail!(meta.path, "unknown attribute");
}
@@ -228,55 +235,72 @@ fn expand_struct(mut meta: ContainerMeta, input: DataStruct) -> syn::Result<Toke
let description = normalize_option(meta.description.as_ref());
let crate_path = &meta.options.crate_path;

let node_ty = match input.fields {
syn::Fields::Named(named) => {
let items = named.named.iter().map(|field| {
let name = field.ident.as_ref().unwrap();
let description = normalize_option(extract_documentation(&field.attrs)?);
let field_ty = &field.ty;

let expanded = quote! {
(
stringify!(#name).into(),
#crate_path::StructProperty {
description: #description,
value: <#field_ty as #crate_path::Schemaifier>::visit_schema(visitor),
}
)
};

Ok(expanded)
}).collect::<syn::Result<Vec<_>>>()?;

let node = if let Some(ref r#as) = meta.options.r#as {
quote! {
let definition_resource = #crate_path::Schemaifier::visit_schema(visitor);
visitor.get_schema::<#r#as>().unwrap().clone()
}
} else {
let node_ty = if let Some(ref r#type) = meta.options.r#type {
quote! {
#crate_path::StructType::Named {
properties: #crate_path::reexport::BTreeMap::from([
#( #items, )*
])
}
#r#type
}
}
syn::Fields::Unnamed(fields) => {
let type_names = fields.unnamed.iter().map(|field| &field.ty);
} else {
let node_ty = match input.fields {
syn::Fields::Named(named) => {
let items = named.named.iter().map(|field| {
let name = field.ident.as_ref().unwrap();
let description = normalize_option(extract_documentation(&field.attrs)?);
let field_ty = &field.ty;

let expanded = quote! {
(
stringify!(#name).into(),
#crate_path::StructProperty {
description: #description,
value: <#field_ty as #crate_path::Schemaifier>::visit_schema(visitor),
}
)
};

Ok(expanded)
}).collect::<syn::Result<Vec<_>>>()?;

quote! {
#crate_path::StructType::Named {
properties: #crate_path::reexport::BTreeMap::from([
#( #items, )*
])
}
}
}
syn::Fields::Unnamed(fields) => {
let type_names = fields.unnamed.iter().map(|field| &field.ty);

quote! {
#crate_path::StructType::Tuple {
items: vec![
#(
<#type_names as #crate_path::Schemaifier>::visit_schema(visitor),
)*
],
}
}
}
syn::Fields::Unit => quote! { #crate_path::StructType::Unit },
};

quote! {
#crate_path::StructType::Tuple {
items: vec![
#(
<#type_names as #crate_path::Schemaifier>::visit_schema(visitor),
)*
],
}
#crate_path::NodeType::Struct(#node_ty)
}
}
syn::Fields::Unit => quote! { #crate_path::StructType::Unit },
};
};

let node = quote! {
#crate_path::Node {
name: std::any::type_name::<Self>().into(),
description: #description,
value: #crate_path::NodeType::Struct(#node_ty),
quote! {
#crate_path::Node {
name: std::any::type_name::<Self>().into(),
description: #description,
value: #node_ty,
}
}
};

Loading