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

Refactor for bindgen updates #15

Closed
wants to merge 3 commits into from
Closed

Refactor for bindgen updates #15

wants to merge 3 commits into from

Conversation

bhelx
Copy link
Contributor

@bhelx bhelx commented Nov 4, 2024

See dylibso/xtp-bindgen#18

Required Vs Nullable

Picking up where #10 left off . How i am implementing required vs nullable

This schema:

    RequiredVsNullable:
      description: A weird little object
      required:
        - aRequiredNotNullableBoolean
        - aRequiredNullableBoolean
      properties:
        aRequiredNotNullableBoolean:
          type: boolean
          description: A required, not-nullable boolean prop
        aRequiredNullableBoolean:
          type: boolean
          description: A required ,nullable boolean prop
          nullable: true
        aNotRequiredNotNullableBoolean:
          type: boolean
          description: A not-required, not-nullable boolean prop
        aNotRequiredNullableBoolean:
          type: boolean
          description: A not-required, nullable boolean prop
          nullable: true

Results in this object:

    #[derive(
        Default, serde::Serialize, serde::Deserialize, extism_pdk::FromBytes, extism_pdk::ToBytes,
    )]
    #[encoding(Json)]
    pub struct RequiredVsNullable {
        /// A not-nullable boolean prop
        #[serde(rename = "aNotRequiredNotNullableBoolean")]
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(default = "panic_if_key_missing")]
        pub a_not_required_not_nullable_boolean: Option<bool>,

        /// A nullable boolean prop
        #[serde(rename = "aNotRequiredNullableBoolean")]
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(default = "panic_if_key_missing")]
        pub a_not_required_nullable_boolean: Option<bool>,

        /// A not-nullable boolean prop
        #[serde(rename = "aRequiredNotNullableBoolean")]
        pub a_required_not_nullable_boolean: bool,

        /// A nullable boolean prop
        #[serde(rename = "aRequiredNullableBoolean")]
        #[serde(default)]
        pub a_required_nullable_boolean: Option<bool>,
    }

}
return "i64";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: we have a type for i64 but don't yet support it because of json limitations. i have an issue filed for this.

@bhelx bhelx changed the title Refactor for bingen updates Refactor for bindgen updates Nov 4, 2024
* Refactor: see dylibso/xtp-bindgen#18
* Support nullable vs required
src/index.ts Outdated Show resolved Hide resolved
return optionalize(`types::${helpers.capitalize((type as EnumType).name)}`)
case 'map':
const { keyType, valueType } = type as MapType
return optionalize(`std::collections::HashMap<${toRustTypeX(keyType)}, ${toRustTypeX(valueType)}>`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to use serde_json::Value::Map instead of HashMap while we're here. (serde_json::Map gives the plugin author the ability to preserve key order.)

src/index.ts Show resolved Hide resolved
@zshipko zshipko linked an issue Nov 8, 2024 that may be closed by this pull request
@zshipko
Copy link
Contributor

zshipko commented Nov 21, 2024

Closing since this work was included in #18

@zshipko zshipko closed this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve handling of optional buffers
3 participants