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

Autogenerated schemas not quite as fully-featured as hand-written ones #355

Closed
dimbleby opened this issue Dec 23, 2020 · 4 comments
Closed
Labels
derive kube-derive proc_macro related

Comments

@dimbleby
Copy link
Contributor

Hi,

The new schema autogeneration stuff is very interesting. Meanwhile we have been writing schemas by hand: so I am now trying to generate something that is equivalent.

I'm having trouble with a couple of things:

  • I don't see a way to perform extra validation, in particular I'd like to be able to insist that a string match some pattern:
   mySpecialString:
      description: A string that matches a regular expression
      type: string
      pattern: "^[^:,]+:[^:,]+$"

GREsau/schemars#12 looks relevant: but also long inactive.

  • I don't see a way to insert funky stuff like x-kubernetes-int-or-string: true. Eg I currently have a field:
    /// Field that can be integer or string in the k8s object
    #[serde(deserialize_with = "string_or_number")]
    pub my_special_field: u16,

which makes use of this.

Am I missing a way to achieve these things?

Alternatively, WIBNI to be disable the schema generation. If I'm going to have to write it by hand anyway, why force me to generate it?

Thanks!

@dimbleby
Copy link
Contributor Author

I figured out that I can add a pattern, by hand-implementing JsonSchema. x-kubernetes-int-or-string: true currently still has me beaten, though.

@dimbleby
Copy link
Contributor Author

Ooh, I can do that too with a hand-crafted implementation. It's all a bit verbose, but do-able. Sorry for the noise!

@kazk
Copy link
Member

kazk commented Dec 24, 2020

Schema generation does not fully support declarative validation rules yet, but some of them are supported. I summarized the current state here: #129 (comment)

It also cannot generate structural schema for more complex types (any_of, all_of, one_of). This requires transforming the Open API v3 schema into something Kubernetes specific.

clux added a commit that referenced this issue Dec 24, 2020
for people wishing to minise their dependencies, add a skip_crd kube
attr.
clux added a commit that referenced this issue Dec 25, 2020
make schema a default compile feature of kube-derive - for #355
@clux clux added the derive kube-derive proc_macro related label Dec 25, 2020
@clux
Copy link
Member

clux commented Dec 25, 2020

@dimbleby : I am happy that you've found a workaround, but we also think you have a point here about people potentially being forced to use a new dependency that they might not need. So, to clarify this issue for future readers; in the next version, kube-derive will have a default-enabled schema feature that you can opt out of to manually generate the required schema. See https://github.com/clux/kube-rs/blob/9e0cd42cd2d645b51a6451fa369660d73591a91f/examples/crd_derive_no_schema.rs#L14-L45 for details. Until the 0.45.0 is out, this will be accessible from master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
derive kube-derive proc_macro related
Projects
None yet
Development

No branches or pull requests

3 participants