Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deduping problems in specification file #80

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/specification/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::specification::Structure::{Composite, Simple};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -47,7 +48,7 @@ pub enum CfnType {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PropertyRule {
#[serde(alias = "Required")]
pub required: bool,
pub required: Option<bool>,
#[serde(alias = "PrimitiveType")]
pub primitive_type: Option<CfnType>,
#[serde(alias = "PrimitiveItemType")]
Expand Down Expand Up @@ -91,6 +92,25 @@ impl PropertyRule {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RawRule {
#[serde(flatten, with = "::serde_with::rust::maps_first_key_wins")]
all: HashMap<String, Value>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RawSpecification {
#[serde(
alias = "PropertyTypes",
rename = "PropertyTypes",
with = "::serde_with::rust::maps_first_key_wins"
)]
pub property_types: HashMap<String, RawRule>,

#[serde(alias = "ResourceTypes", rename = "ResourceTypes")]
pub resource_types: HashMap<String, RawRule>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Specification {
#[serde(
Expand All @@ -106,7 +126,9 @@ pub struct Specification {
impl Specification {
pub fn new() -> Specification {
let str = include_str!("spec.json");
serde_json::from_str::<Specification>(str).unwrap()
let raw = serde_json::from_str::<RawSpecification>(str).unwrap();
let compressed_str = serde_json::to_string::<RawSpecification>(&raw).unwrap();
serde_json::from_str::<Specification>(&compressed_str).unwrap()
}

// Resource Properties in Specification look something like:
Expand Down