Skip to content

Commit

Permalink
fix test with serde(default)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Feb 15, 2024
1 parent d178bca commit aeb7152
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/src/extractor/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn create_record_from_all_of(name: &str, all_of: &[ReferenceOr<Schema>], schema_
let props = item.properties();
for (name, schema) in props {
let mut field = create_field(schema, spec);
if !item.required().iter().any(|s| s == name) {
if !field.ty.is_iterable() && !item.required().iter().any(|s| s == name) {
field.optional = true;
}
fields.insert(name.to_string(), field);
Expand Down
2 changes: 1 addition & 1 deletion libninja/src/rust/lower_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl FieldExt for HirField {
let mut decorators = Vec::new();
let rust_ident = name.to_rust_ident();
if rust_ident.0 != name {
let name = &name;
if self.flatten {
decorators.push(quote! {
#[serde(flatten)]
Expand All @@ -39,6 +38,7 @@ impl FieldExt for HirField {
});
}
}
dbg!(self.optional);
if self.optional {
decorators.push(quote! {
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
9 changes: 4 additions & 5 deletions libninja/tests/all_of/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use openapiv3::{OpenAPI, Schema};
use pretty_assertions::assert_eq;

/// Tests that the `allOf` keyword is handled correctly.
use ln_core::{ConfigFlags};
use hir::{HirSpec, Record};
use ln_core::extractor::{extract_api_operations, extract_records};
/// Tests that the `allOf` keyword is handled correctly.
use ln_core::ConfigFlags;
use ln_core::extractor::extract_records;

const TRANSACTION: &str = include_str!("transaction.yaml");
const TRANSACTION_RS: &str = include_str!("transaction.rs");
Expand All @@ -15,8 +15,7 @@ const RESTRICTION_BACS_RS: &str = include_str!("restriction_bacs.rs");

fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> Record {
let schema = serde_yaml::from_str::<Schema>(schema).unwrap();
let mut record = ln_core::extractor::create_record(name, &schema, spec);
record
ln_core::extractor::create_record(name, &schema, spec)
}

fn formatted_code(record: Record, spec: &HirSpec) -> String {
Expand Down
14 changes: 7 additions & 7 deletions libninja/tests/all_of/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ pub struct Transaction {
#[serde(flatten)]
pub transaction_base: TransactionBase,
///The date that the transaction was authorized. Dates are returned in an [ISO 8601](https://wikipedia.org/wiki/ISO_8601) format ( `YYYY-MM-DD` ).
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub authorized_date: Option<chrono::NaiveDate>,
/**Date and time when a transaction was authorized in [ISO 8601](https://wikipedia.org/wiki/ISO_8601) format ( `YYYY-MM-DDTHH:mm:ssZ` ).
This field is returned for select financial institutions and comes as provided by the institution. It may contain default time values (such as 00:00:00).*/
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub authorized_datetime: Option<chrono::DateTime<chrono::Utc>>,
///The counterparties present in the transaction. Counterparties, such as the financial institutions, are extracted by Plaid from the raw description.
#[serde(skip_serializing_if = "Option::is_none")]
pub counterparties: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub counterparties: Vec<String>,
/**Date and time when a transaction was posted in [ISO 8601](https://wikipedia.org/wiki/ISO_8601) format ( `YYYY-MM-DDTHH:mm:ssZ` ).
This field is returned for select financial institutions and comes as provided by the institution. It may contain default time values (such as 00:00:00).*/
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub datetime: Option<chrono::DateTime<chrono::Utc>>,
/**The channel used to make a payment.
`online:` transactions that took place online.
Expand All @@ -28,10 +28,10 @@ This field is returned for select financial institutions and comes as provided b
This field replaces the `transaction_type` field.*/
pub payment_channel: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub personal_finance_category: Option<String>,
///A link to the icon associated with the primary personal finance category. The logo will always be 100x100 pixels.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub personal_finance_category_icon_url: Option<String>,
pub transaction_code: String,
}
Expand Down
2 changes: 1 addition & 1 deletion mir_rust/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl ToRustCode for Import {
alias,
imports,
vis,
feature,
..
} = import;
if path.ends_with('*') {
let path = syn::parse_str::<Path>(&path[..path.len() - 3]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion mir_rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ToRustCode for Function<TokenStream> {
annotations,
ret,
public,
generic,
..
} = self;
let annotations = annotations
.into_iter()
Expand Down

0 comments on commit aeb7152

Please sign in to comment.