Skip to content

Commit d074353

Browse files
committed
refactor(ast_codegen): alter JSON schema format
1 parent 39177c9 commit d074353

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

tasks/ast_codegen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
9191

9292
if let CliOptions { schema: Some(schema_path), dry_run: false, .. } = cli_options {
9393
let path = schema_path.to_str().expect("invalid path for schema output.");
94-
let schema = serde_json::to_string_pretty(&schema).normalize()?;
94+
let schema = serde_json::to_string_pretty(&schema.defs).normalize()?;
9595
write_all_to(schema.as_bytes(), path)?;
9696
}
9797

tasks/ast_codegen/src/schema/defs.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
use super::{with_either, TypeName};
1010

1111
#[derive(Debug, Serialize)]
12+
#[serde(untagged)]
1213
pub enum TypeDef {
1314
Struct(StructDef),
1415
Enum(EnumDef),
@@ -38,24 +39,29 @@ impl TypeDef {
3839
}
3940

4041
#[derive(Debug, Serialize)]
42+
#[serde(tag = "type", rename = "struct", rename_all = "camelCase")]
4143
pub struct StructDef {
4244
pub id: TypeId,
4345
pub name: String,
46+
#[serde(skip)]
4447
pub visitable: bool,
4548
pub fields: Vec<FieldDef>,
49+
#[serde(skip)]
4650
pub has_lifetime: bool,
4751
pub size_64: usize,
4852
pub align_64: usize,
4953
pub offsets_64: Option<Vec<usize>>,
5054
pub size_32: usize,
5155
pub align_32: usize,
5256
pub offsets_32: Option<Vec<usize>>,
57+
#[serde(skip)]
5358
pub generated_derives: Vec<String>,
5459
#[serde(skip)]
5560
pub markers: OuterMarkers,
5661
}
5762

5863
#[derive(Debug, Serialize)]
64+
#[serde(tag = "type", rename = "enum", rename_all = "camelCase")]
5965
pub struct EnumDef {
6066
pub id: TypeId,
6167
pub name: String,
@@ -97,6 +103,7 @@ pub struct VariantDef {
97103
pub name: String,
98104
pub fields: Vec<FieldDef>,
99105
pub discriminant: u8,
106+
#[serde(skip)]
100107
pub markers: InnerMarkers,
101108
}
102109

@@ -112,6 +119,7 @@ impl VariantDef {
112119

113120
#[derive(Debug, Serialize)]
114121
pub struct InheritDef {
122+
#[serde(rename = "super")]
115123
pub super_: TypeRef,
116124
pub variants: Vec<VariantDef>,
117125
}
@@ -120,13 +128,18 @@ pub struct InheritDef {
120128
pub struct FieldDef {
121129
/// `None` if unnamed
122130
pub name: Option<String>,
131+
#[serde(skip)]
123132
pub vis: Visibility,
133+
#[serde(rename = "type")]
124134
pub typ: TypeRef,
135+
#[serde(skip)]
125136
pub markers: InnerMarkers,
137+
#[serde(skip)]
126138
pub docs: Vec<String>,
127139
}
128140

129141
#[derive(Debug, Serialize)]
142+
#[serde(rename_all = "camelCase")]
130143
pub enum Visibility {
131144
None,
132145
Pub,
@@ -158,10 +171,11 @@ impl FieldDef {
158171

159172
#[derive(Debug, Serialize)]
160173
pub struct TypeRef {
174+
#[serde(skip)]
161175
pub(super) id: Option<TypeId>,
162176
pub(super) name: TypeName,
163177

164-
#[serde(skip)]
178+
#[serde(rename = "id")]
165179
pub(super) transparent_id: Option<TypeId>,
166180

167181
#[serde(skip)]

tasks/ast_codegen/src/schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a> From<crate::util::TypeIdentResult<'a>> for TypeName {
8484

8585
#[derive(Debug, Default, serde::Serialize)]
8686
pub struct Schema {
87-
defs: Vec<TypeDef>,
87+
pub defs: Vec<TypeDef>,
8888
}
8989

9090
impl Schema {

0 commit comments

Comments
 (0)