Skip to content

Commit

Permalink
Merge branch 'main' into remove-cargo-component
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel authored Dec 17, 2024
2 parents 8bc6665 + f5a4681 commit cd2fb80
Show file tree
Hide file tree
Showing 74 changed files with 2,573 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ jobs:
shared-key: build
workspaces: |
./
pulumi_wasm_generator_lib/tests/output/array-of-enum-map/
pulumi_wasm_generator_lib/tests/output/azure-native-nested-types/
pulumi_wasm_generator_lib/tests/output/cyclic-types/
pulumi_wasm_generator_lib/tests/output/different-enum/
pulumi_wasm_generator_lib/tests/output/functions-secrets/
pulumi_wasm_generator_lib/tests/output/mini-awsnative/
pulumi_wasm_generator_lib/tests/output/output-funcs/
Expand Down Expand Up @@ -208,7 +211,10 @@ jobs:
save-if: false
workspaces: |
./
pulumi_wasm_generator_lib/tests/output/array-of-enum-map/
pulumi_wasm_generator_lib/tests/output/azure-native-nested-types/
pulumi_wasm_generator_lib/tests/output/cyclic-types/
pulumi_wasm_generator_lib/tests/output/different-enum/
pulumi_wasm_generator_lib/tests/output/functions-secrets/
pulumi_wasm_generator_lib/tests/output/mini-awsnative/
pulumi_wasm_generator_lib/tests/output/output-funcs/
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/cleancache.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ jobs:
save-if: false
workspaces: |
./
pulumi_wasm_generator_lib/tests/output/array-of-enum-map/
pulumi_wasm_generator_lib/tests/output/azure-native-nested-types/
pulumi_wasm_generator_lib/tests/output/cyclic-types/
pulumi_wasm_generator_lib/tests/output/different-enum/
pulumi_wasm_generator_lib/tests/output/functions-secrets/
pulumi_wasm_generator_lib/tests/output/mini-awsnative/
pulumi_wasm_generator_lib/tests/output/output-funcs/
Expand Down Expand Up @@ -257,7 +260,10 @@ jobs:
save-if: false
workspaces: |
./
pulumi_wasm_generator_lib/tests/output/array-of-enum-map/
pulumi_wasm_generator_lib/tests/output/azure-native-nested-types/
pulumi_wasm_generator_lib/tests/output/cyclic-types/
pulumi_wasm_generator_lib/tests/output/different-enum/
pulumi_wasm_generator_lib/tests/output/functions-secrets/
pulumi_wasm_generator_lib/tests/output/mini-awsnative/
pulumi_wasm_generator_lib/tests/output/output-funcs/
Expand Down
42 changes: 40 additions & 2 deletions examples/typesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ mod tests {
use pulumi_wasm_rust::Output;
use pulumi_wasm_typesystem::typesystem_server::TypesystemServerArgs;
use pulumi_wasm_typesystem::{
MyEnum, UnionCase1, UnionCase2, UnionCaseWithConst1, UnionCaseWithConst2,
IntegerEnum, MyEnum, NumberEnum, UnionCase1, UnionCase2, UnionCaseWithConst1,
UnionCaseWithConst2,
};
use std::panic::catch_unwind;

Expand Down Expand Up @@ -34,17 +35,54 @@ mod tests {
}

#[test]
fn test_enum_deserialization() {
fn test_string_enum_deserialization() {
let enum1 = MyEnum::Value1;
let enum2 = MyEnum::Value2;
let enum3 = MyEnum::SpecialCharacters;

let enum1_json = serde_json::to_string(&enum1).unwrap();
let enum2_json = serde_json::to_string(&enum2).unwrap();
let enum3_json = serde_json::to_string(&enum3).unwrap();
assert_eq!(enum1_json, r#""VALUE1""#);
assert_eq!(enum2_json, r#""Value2""#);
assert_eq!(enum3_json, r#""Plants'R'Us""#);

let deserialized_enum1: MyEnum = serde_json::from_str(&enum1_json).unwrap();
let deserialized_enum2: MyEnum = serde_json::from_str(&enum2_json).unwrap();
let deserialized_enum3: MyEnum = serde_json::from_str(&enum3_json).unwrap();
assert_eq!(deserialized_enum1, enum1);
assert_eq!(deserialized_enum2, enum2);
assert_eq!(deserialized_enum3, enum3);
}

#[test]
fn test_integer_enum_deserialization() {
let enum1 = IntegerEnum::Value1;
let enum2 = IntegerEnum::Value2;

let enum1_json = serde_json::to_string(&enum1).unwrap();
let enum2_json = serde_json::to_string(&enum2).unwrap();
assert_eq!(enum1_json, "1");
assert_eq!(enum2_json, "2");

let deserialized_enum1: IntegerEnum = serde_json::from_str(&enum1_json).unwrap();
let deserialized_enum2: IntegerEnum = serde_json::from_str(&enum2_json).unwrap();
assert_eq!(deserialized_enum1, enum1);
assert_eq!(deserialized_enum2, enum2);
}

#[test]
fn test_number_enum_deserialization() {
let enum1 = NumberEnum::Value1;
let enum2 = NumberEnum::Value2;

let enum1_json = serde_json::to_string(&enum1).unwrap();
let enum2_json = serde_json::to_string(&enum2).unwrap();
assert_eq!(enum1_json, "1.0");
assert_eq!(enum2_json, "2.0");

let deserialized_enum1: NumberEnum = serde_json::from_str(&enum1_json).unwrap();
let deserialized_enum2: NumberEnum = serde_json::from_str(&enum2_json).unwrap();
assert_eq!(deserialized_enum1, enum1);
assert_eq!(deserialized_enum2, enum2);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions providers/typesystem.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pulumi_wasm_generator_lib/src/code_generation/yaml/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ fn map_type(

let gtp = match tpe {
GlobalType::Object(_, gtp) => gtp,
GlobalType::NumberEnum(_, _) => panic!("NumberEnum type is not supported"),
GlobalType::IntegerEnum(_, _) => panic!("IntegerEnum type is not supported"),
GlobalType::StringEnum(_, _) => panic!("StringEnum type is not supported"),
GlobalType::String => panic!("String type is not supported"),
GlobalType::Boolean => panic!("Boolean type is not supported"),
Expand Down
20 changes: 18 additions & 2 deletions pulumi_wasm_generator_lib/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ pub(crate) struct GlobalTypeProperty {
pub(crate) description: Option<String>,
}

#[derive(Debug, PartialEq, Hash, Ord, PartialOrd, Eq)]
#[derive(Debug, PartialEq, PartialOrd)]
pub(crate) enum GlobalType {
Object(Option<String>, Vec<GlobalTypeProperty>),
StringEnum(Option<String>, Vec<StringEnumElement>),
NumberEnum(Option<String>, Vec<NumberEnumElement>),
IntegerEnum(Option<String>, Vec<IntegerEnumElement>),
String,
Boolean,
Number,
Expand All @@ -149,6 +151,20 @@ pub(crate) struct StringEnumElement {
pub(crate) description: Option<String>,
}

#[derive(Debug, PartialEq, PartialOrd)]
pub(crate) struct NumberEnumElement {
pub(crate) name: String,
pub(crate) value: f64,
pub(crate) description: Option<String>,
}

#[derive(Debug, PartialEq, PartialOrd)]
pub(crate) struct IntegerEnumElement {
pub(crate) name: String,
pub(crate) value: i64,
pub(crate) description: Option<String>,
}

#[derive(Debug, PartialEq, Hash, Ord, PartialOrd, Eq)]
pub(crate) struct Resource {
pub(crate) element_id: ElementId,
Expand All @@ -167,7 +183,7 @@ pub(crate) struct Function {
pub(crate) output_properties: Vec<OutputProperty>,
}

#[derive(Debug, PartialEq, Hash, Ord, PartialOrd, Eq)]
#[derive(Debug, PartialEq)]
pub(crate) struct Package {
pub(crate) name: String,
pub(crate) display_name: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::bindings::component::pulumi_wasm::register_interface::{ObjectField, r
use crate::Component;

impl {{interface.name}}::Guest for Component {
fn invoke(name: String, args: {{interface.name}}::Args) -> {{interface.name}}::Res {
fn invoke(name: String, args: {{interface.name}}::Args){{#if interface.output_properties}} -> {{interface.name}}::Res{{/if}} {
pulumi_wasm_common::setup_logger();
let request = RegisterResourceRequest {
type_: "{{interface.type}}".into(),
Expand All @@ -25,11 +25,13 @@ impl {{interface.name}}::Guest for Component {

let mut hashmap: HashMap<String, _> = o.fields.into_iter().map(|f| (f.name, f.output)).collect();

{{#if interface.output_properties}}
{{interface.name}}::Res {
{{#each interface.output_properties}}
{{arg_name}}: hashmap.remove("{{name}}").unwrap(),
{{/each}}
}
{{/if}}

}
}
Loading

0 comments on commit cd2fb80

Please sign in to comment.