Skip to content

declarative openapi validation rules #129

@clux

Description

@clux

It would be really cool if we had a way to create declarative openapi validation rules ala:

e.g. something like:

#[derive(OpenapiValidation, Deserialize, Serialize, Clone)]
pub struct FooSpec {
    #[openapi(MinLength=5)
    name: String,
    info: String,
    #[openapi(Minimum=1, Maximum=10)]
    replicas: i32,
}

The thing this most reminds me of is serde attributes, but this feels a whole lot dumber than that. We just need to generate: { type: object, properties: ... } from a struct, so it's easy to attach onto the the crd json!

The problem with this is that it would necessarily conflict with serde field attributes, which are also frequently used. A dumb proc macro that wasn't aware of serde wouldn't be hard to do, but I imagine it also would cause a lot of duplication between between serde attrs like skip_serializing_if, default with validation rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    derivekube-derive proc_macro related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions