Skip to content

associated functions are not accessible by serde under CELSchema context #1746

@aharbis

Description

@aharbis

Current and expected behavior

We often use associated functions for defaulting fields, as in large / complex structures it helps to keep code organized. In a minimal example this might look like:

#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct MySpec {
    #[serde(default = "MySpec::default_value")]
    pub value: bool,
}

impl MySpec {
    fn default_value() -> bool {
        true
    }
}

This has worked well for us, using JsonSchema; however, now that we're migrating to using kube's new CELSchema capabilities, we noticed that this breaks the use of associated functions in this way. Switching from JsonSchema to CELSchema (and no other changes) yields:

error[E0599]: no function or associated item named `default_value` found for struct `<apis::example::MySpec as schemars::JsonSchema>::json_schema::MySpec` in the current scope
   --> src/apis/example.rs:116:23
    |
115 | pub struct MySpec {
    | ----------------- function or associated item `default_value` not found for this struct
116 |     #[serde(default = "MySpec::default_value")]
    |                       ^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `MySpec`

Possible solution

No response

Additional context

No response

Environment

OpenShift 4.18

Configuration and features

k8s-openapi = { version = "0.24", features = ["latest", "schemars"] }
kube = { version = "0.99", features = ["runtime", "derive", "client"] }

Affected crates

No response

Would you like to work on fixing this bug?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions