Omit private fields from json
diff --git a/codegen/src/gen.rs b/codegen/src/gen.rs
index 931a30a..cdd574c 100644
--- a/codegen/src/gen.rs
+++ b/codegen/src/gen.rs
@@ -562,7 +562,7 @@
let mut include_fold_impl = true;
if let types::Node::Struct(ref data) = s {
- if !data.all_fields_pub() {
+ if data.fields().is_empty() && !super::TERMINAL_TYPES.contains(&&s.ident()) {
include_fold_impl = false;
}
}
@@ -646,8 +646,7 @@
defs.insert(types::Node::Struct(types::Struct::new(
tt.to_string(),
types::Features::default(),
- IndexMap::new(),
- true)
+ IndexMap::new())
));
}
diff --git a/codegen/src/parse.rs b/codegen/src/parse.rs
index 3ec3142..b43bef5 100644
--- a/codegen/src/parse.rs
+++ b/codegen/src/parse.rs
@@ -98,16 +98,16 @@
items: &ItemLookup,
tokens: &TokenLookup,
) -> types::Struct {
- let mut all_fields_pub = true;
+ let all_fields_pub = item.fields.iter().all(|field| is_pub(&field.vis));
+ if !all_fields_pub {
+ return types::Struct::new(ident.to_string(), features, IndexMap::new());
+ }
+
let fields = match &item.fields {
syn::Fields::Named(fields) => fields
.named
.iter()
.map(|field| {
- if !is_pub(&field.vis) {
- all_fields_pub = false;
- }
-
(
field.ident.as_ref().unwrap().to_string(),
introspect_type(&field.ty, items, tokens),
@@ -118,7 +118,7 @@
_ => panic!("Struct representation not supported"),
};
- types::Struct::new(ident.to_string(), features, fields, all_fields_pub)
+ types::Struct::new(ident.to_string(), features, fields)
}
fn introspect_type(item: &syn::Type, items: &ItemLookup, tokens: &TokenLookup) -> types::Type {
diff --git a/codegen/src/types.rs b/codegen/src/types.rs
index 8fee440..de25e6e 100644
--- a/codegen/src/types.rs
+++ b/codegen/src/types.rs
@@ -20,8 +20,8 @@
pub struct Struct {
ident: String,
features: Features,
+ #[serde(skip_serializing_if = "IndexMap::is_empty")]
fields: IndexMap<String, Type>,
- all_fields_pub: bool,
}
#[derive(Debug, Clone, Serialize)]
@@ -103,13 +103,11 @@
ident: String,
features: Features,
fields: IndexMap<String, Type>,
- all_fields_pub: bool,
) -> Struct {
Struct {
ident,
features,
fields,
- all_fields_pub,
}
}
@@ -120,10 +118,6 @@
pub fn fields(&self) -> &IndexMap<String, Type> {
&self.fields
}
-
- pub fn all_fields_pub(&self) -> bool {
- self.all_fields_pub
- }
}
impl Enum {