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

Cannot use derived schemas when IntOrString present #60

Closed
clux opened this issue Apr 21, 2022 · 2 comments
Closed

Cannot use derived schemas when IntOrString present #60

clux opened this issue Apr 21, 2022 · 2 comments

Comments

@clux
Copy link
Member

clux commented Apr 21, 2022

Minor issue when using the fully automatic schemas against something using IntOrString:

error[E0277]: the trait bound `IntOrString: JsonSchema` is not satisfied
   --> tests/./gen.rs:15:15
    |
15  |     pub port: IntOrString,
    |               ^^^^^^^^^^^ the trait `JsonSchema` is not implemented for `IntOrString`
    |
note: required by a bound in `SchemaGenerator::subschema_for`
   --> /home/clux/.cargo/registry/src/github.com-1ecc6299db9ec823/schemars-0.8.8/src/gen.rs:218:38
    |
218 |     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
    |                                      ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`

error[E0277]: the trait bound `IntOrString: JsonSchema` is not satisfied
 --> tests/./gen.rs:7:64
  |
7 | #[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
  |                                                                ^^^^^^^^^^ the trait `JsonSchema` is not implemented for `IntOrString`
  |
  = note: this error originates in the derive macro `JsonSchema` (in Nightly builds, run with -Z macro-backtrace for more info)

some potential solutions:

  • get an impl in k8s-openapi
  • inline IntOrString with JsonSchema derive (awkward, but avoids user dep on k8s-openapi in some cases perhaps)

This isn't a big deal because it's only the schema part, we can still generate the structs.

Workaround is not use -A or --schema=derived with such schemas, but use --schema=manual or the default and read the schema from a file if needed (if you need to overwrite the crd at some point).

@actionjax
Copy link

I ran into the same problem.

Workaround I found, if you enable feature

k8s-openapi = { ... features=[..., "schemars"] }

this goes away.

@clux
Copy link
Member Author

clux commented Dec 13, 2024

Ah, that is true. k8s-openapi does implement JsonSchema for IntOrString conditionally: https://github.com/Arnavion/k8s-openapi/blob/3f16b5e49b3a9c28f14ce0a280e5decf773658ce/src/v1_32/apimachinery/pkg/util/intstr/int_or_string.rs#L70

Thanks for the comment! Going to close this.

@clux clux closed this as completed Dec 13, 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

No branches or pull requests

2 participants