Skip to content

Commit

Permalink
Merge pull request #16 from wbcsd/openapi-fixes
Browse files Browse the repository at this point in the history
Updates to openapi json
  • Loading branch information
zeitgeist authored Dec 21, 2023
2 parents 5ca238f + d08b4bc commit 84922e4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
20 changes: 13 additions & 7 deletions endpoint/src/datamodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub struct CarbonFootprint {
pub declared_unit: DeclaredUnit,
pub unitary_product_amount: StrictlyPositiveDecimal,
pub p_cf_excluding_biogenic: PositiveDecimal,
pub p_cf_including_biogenic: WrappedDecimal,
#[serde(skip_serializing_if = "Option::is_none")]
pub p_cf_including_biogenic: Option<WrappedDecimal>,
pub fossil_ghg_emissions: PositiveDecimal,
pub fossil_carbon_content: PositiveDecimal,
pub biogenic_carbon_content: PositiveDecimal,
Expand Down Expand Up @@ -83,10 +84,9 @@ pub struct CarbonFootprint {
#[serde(skip_serializing_if = "Option::is_none")]
pub boundary_processes_description: Option<String>,

pub reporting_period_start: DateTime<Utc>,
pub reporting_period_end: DateTime<Utc>,
pub reference_period_start: DateTime<Utc>,
pub reference_period_end: DateTime<Utc>,

#[serde(flatten)]
#[serde(skip_serializing_if = "Option::is_none")]
pub geographic_scope: Option<GeographicScope>,

Expand Down Expand Up @@ -359,10 +359,12 @@ pub struct DataQualityIndicators {
pub reliability_d_q_r: StrictlyPositiveDecimal,
}

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq, Default)]
#[serde(crate = "rocket::serde", rename_all = "camelCase")]
/// Data Type "Assurance" of Spec Version 2
pub struct Assurance {
pub assurance: bool,

#[serde(skip_serializing_if = "Option::is_none")]
pub coverage: Option<AssuranceCoverage>,

Expand All @@ -373,8 +375,12 @@ pub struct Assurance {
pub boundary: Option<AssuranceBoundary>,

pub provider_name: String,
pub completed_at: DateTime<Utc>,
pub standard: String,

#[serde(skip_serializing_if = "Option::is_none")]
pub completed_at: Option<DateTime<Utc>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub standard_name: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub comments: Option<String>,
Expand Down
36 changes: 18 additions & 18 deletions endpoint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ fn filtered_data(filter: Option<&'_ str>) -> Result<Vec<ProductFootprint>, Strin
.unwrap_or_default()
})
.unwrap_or_default(),
"pcf/reportingPeriodStart" => {
pf.pcf.reporting_period_start.to_string() == value
"pcf/referencePeriodStart" => {
pf.pcf.reference_period_start.to_string() == value
}
"pcf/reportingPeriodEnd" => {
pf.pcf.reporting_period_end.to_string() == value
"pcf/referencePeriodEnd" => {
pf.pcf.reference_period_end.to_string() == value
}
_ => {
return Err(format!("Unsupported property {property}"));
Expand All @@ -235,8 +235,8 @@ fn filtered_data(filter: Option<&'_ str>) -> Result<Vec<ProductFootprint>, Strin
let v = match property {
"created" => Some(pf.created),
"updated" => pf.updated,
"pcf/reportingPeriodStart" => Some(pf.pcf.reporting_period_start),
"pcf/reportingPeriodEnd" => Some(pf.pcf.reporting_period_end),
"pcf/referencePeriodStart" => Some(pf.pcf.reference_period_start),
"pcf/referencePeriodEnd" => Some(pf.pcf.reference_period_end),
_ => {
return Err(format!("Unsupported property {property}"));
}
Expand Down Expand Up @@ -533,7 +533,7 @@ fn get_list_test() {
// test auth
{
let resp = client
.get(get_list_uri.clone())
.get(get_list_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.header(rocket::http::Header::new("Host", EXAMPLE_HOST))
.dispatch();
Expand Down Expand Up @@ -569,7 +569,7 @@ fn get_list_with_filter_eq_test() {
let get_list_with_limit_uri = "/2/footprints?$filter=pcf/geographyCountry+eq+'FR'";

let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.header(rocket::http::Header::new("Host", EXAMPLE_HOST))
.dispatch();
Expand All @@ -591,7 +591,7 @@ fn get_list_with_filter_lt_test() {
let get_list_with_limit_uri = "/2/footprints?$filter=updated+lt+'2023-01-01T00:00:00.000Z'";

let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.header(rocket::http::Header::new("Host", EXAMPLE_HOST))
.dispatch();
Expand All @@ -613,7 +613,7 @@ fn get_list_with_filter_eq_and_lt_test() {
let get_list_with_limit_uri = "/2/footprints?$filter=(pcf/geographyCountry+eq+'FR')+and+(updated+lt+'2023-01-01T00:00:00.000Z')";

let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.header(rocket::http::Header::new("Host", EXAMPLE_HOST))
.dispatch();
Expand All @@ -636,7 +636,7 @@ fn get_list_with_filter_any_test() {
"/2/footprints?$filter=productIds/any(productId:(productId+eq+'urn:gtin:4712345060507'))";

let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new(
"Authorization",
bearer_token.clone(),
Expand All @@ -652,7 +652,7 @@ fn get_list_with_filter_any_test() {
"/2/footprints?$filter=productIds/any(productId:(productId+eq+'urn:gtin:12345'))";

let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.header(rocket::http::Header::new("Host", EXAMPLE_HOST))
.dispatch();
Expand All @@ -677,7 +677,7 @@ fn get_list_with_limit_test() {

{
let resp = client
.get(get_list_with_limit_uri.clone())
.get(get_list_with_limit_uri)
.header(rocket::http::Header::new(
"Authorization",
bearer_token.clone(),
Expand Down Expand Up @@ -743,7 +743,7 @@ fn post_events_test() {
// test GET request to POST endpoint
{
let resp = client
.get(post_events_uri.clone())
.get(post_events_uri)
.header(rocket::http::Header::new(
"Authorization",
bearer_token.clone(),
Expand All @@ -754,7 +754,7 @@ fn post_events_test() {

// test unauth request
{
let resp = client.post(post_events_uri.clone()).dispatch();
let resp = client.post(post_events_uri).dispatch();
assert_eq!(rocket::http::Status::Forbidden, resp.status());
}

Expand All @@ -779,7 +779,7 @@ fn post_events_test() {
),
};
let resp = client
.post(post_events_uri.clone())
.post(post_events_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.json(&event)
.dispatch();
Expand Down Expand Up @@ -826,7 +826,7 @@ fn get_pcf_test() {
{
let get_pcf_uri = "/2/footprints/abc";
let resp = client
.get(get_pcf_uri.clone())
.get(get_pcf_uri)
.header(rocket::http::Header::new(
"Authorization",
bearer_token.clone(),
Expand All @@ -838,7 +838,7 @@ fn get_pcf_test() {
{
let get_pcf_uri = "/2/footprints/16d8e365-698f-4694-bcad-a56e06a45afd";
let resp = client
.get(get_pcf_uri.clone())
.get(get_pcf_uri)
.header(rocket::http::Header::new("Authorization", bearer_token))
.dispatch();
assert_eq!(rocket::http::Status::Forbidden, resp.status());
Expand Down
12 changes: 8 additions & 4 deletions endpoint/src/sample_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ lazy_static! {
name: String::from("Ecoinvent").into(),
version: String::from("1.2.3").into(),
}])),
reporting_period_start: *TIME_PERIOD_START,
reporting_period_end: *TIME_PERIOD_END,
reference_period_start: *TIME_PERIOD_START,
reference_period_end: *TIME_PERIOD_END,
/*geography_region_or_subregion: None,
geography_country: Some(ISO3166CC(String::from("FR"))),
geography_country_subdivision: None, */
Expand All @@ -45,7 +45,11 @@ lazy_static! {
declared_unit: DeclaredUnit::Liter,
unitary_product_amount: dec!(12.0).into(),
aircraft_ghg_emissions: None,
assurance: None,
assurance: Some(Assurance {
assurance: true,
coverage: Some(AssuranceCoverage::ProductLevel),
..Default::default()
}),
biogenic_accounting_methodology: None,
biogenic_carbon_withdrawal: None,
characterization_factors: CharacterizationFactors::Ar5,
Expand All @@ -56,7 +60,7 @@ lazy_static! {
packaging_emissions_included: false,
packaging_ghg_emissions: None,
p_cf_excluding_biogenic: dec!(0.0).into(),
p_cf_including_biogenic: dec!(0.0).into(),
p_cf_including_biogenic: Some(dec!(0.0).into()),
uncertainty_assessment_description: None,
};
}
Expand Down

0 comments on commit 84922e4

Please sign in to comment.