Skip to content

Commit

Permalink
feat(lex): Enforce properties field on LexObject (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan authored Oct 13, 2023
1 parent 67e9a1c commit 8601f48
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
22 changes: 8 additions & 14 deletions atrium-codegen/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,15 @@ fn find_ref_unions_in_object(
name: &str,
unions: &mut Vec<(String, LexRefUnion)>,
) {
if let Some(properties) = &object.properties {
for (k, property) in properties {
match property {
LexObjectProperty::Union(union) => {
unions.push((format!("{name}{}Enum", k.to_pascal_case()), union.clone()));
}
LexObjectProperty::Array(array) => {
find_ref_unions_in_array(
array,
&(name.to_string() + &k.to_pascal_case()),
unions,
);
}
_ => {}
for (k, property) in &object.properties {
match property {
LexObjectProperty::Union(union) => {
unions.push((format!("{name}{}Enum", k.to_pascal_case()), union.clone()));
}
LexObjectProperty::Array(array) => {
find_ref_unions_in_array(array, &(name.to_string() + &k.to_pascal_case()), unions);
}
_ => {}
}
}
}
18 changes: 8 additions & 10 deletions atrium-codegen/src/token_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn xrpc_parameters(parameters: &LexXrpcParameters) -> Result<TokenStream> {
description: parameters.description.clone(),
required: parameters.required.clone(),
nullable: None,
properties: Some(properties),
properties,
},
"Parameters",
)
Expand Down Expand Up @@ -224,15 +224,13 @@ fn lex_object(object: &LexObject, name: &str) -> Result<TokenStream> {
}
}
let mut fields = Vec::new();
if let Some(properties) = &object.properties {
for key in properties.keys().sorted() {
fields.push(lex_object_property(
&properties[key],
key,
required.contains(key),
name,
)?);
}
for key in object.properties.keys().sorted() {
fields.push(lex_object_property(
&object.properties[key],
key,
required.contains(key),
name,
)?);
}
Ok(quote! {
#description
Expand Down
2 changes: 1 addition & 1 deletion atrium-lex/src/lexicon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub struct LexObject {
pub description: Option<String>,
pub required: Option<Vec<String>>,
pub nullable: Option<Vec<String>>,
pub properties: Option<HashMap<String, LexObjectProperty>>,
pub properties: HashMap<String, LexObjectProperty>,
}

// xrpc
Expand Down

0 comments on commit 8601f48

Please sign in to comment.