Skip to content
This repository was archived by the owner on Jun 13, 2019. It is now read-only.

[WIP] API Gateway Data Model#39

Open
naftulikay wants to merge 1 commit intoiliana:masterfrom
naftulikay:feature/data-api-gateway
Open

[WIP] API Gateway Data Model#39
naftulikay wants to merge 1 commit intoiliana:masterfrom
naftulikay:feature/data-api-gateway

Conversation

@naftulikay
Copy link
Contributor

Tests are broken until I can get a deserializer written which can deserialize Value::Null into Default::default() for T: Default.

@mockersf
Copy link
Contributor

Based on serde-rs/serde#1098 (comment), you can do this:

#[derive(Deserialize)]
struct Test {
    #[serde(default, deserialize_with = "nullable_default")]
    default_field: DefaultField,
}

#[derive(Deserialize, Default)]
struct DefaultField {
    u8: u8,
}
fn nullable_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
    D: Deserializer<'de>,
    T: Default + Deserialize<'de>,
{
    let opt = Option::deserialize(deserializer)?;
    Ok(opt.unwrap_or_else(T::default))
}

This will use default for type if the field is missing or null.

@naftulikay
Copy link
Contributor Author

I apologize for my delay on this, new job, excuses, etc.

@softprops
Copy link
Contributor

Is there anyone I can help move this forward? I'd love to help

@srijs
Copy link

srijs commented Sep 17, 2018

I've recently spent some time doing this for rust-aws-lambda over here: https://github.com/srijs/rust-aws-lambda/tree/master/aws_lambda_gateway, which then led to cool things like being able to run tower-web apps on lambda.

If you're interested, I'd be happy to see if this can be generalized so that it's useful for crowbar as well. Between this and what's being discussed in #32, maybe we can find a way to have an ecosystem of crates that can be used from either runtime?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants