-
-
Notifications
You must be signed in to change notification settings - Fork 342
Allow opting out of schema derivation per kind #690
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
Merged
nightkr
merged 14 commits into
kube-rs:master
from
nightkr:feature/derive-schema-finegrained-optout
Nov 4, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4ea04d3
Allow opting out of schema derivation per type
nightkr 3443a5d
Changelog
nightkr 38684a8
Document `derive_schema = false`
nightkr d6686b4
Add an in-between mode where schema is still used but not derived
nightkr e3b1f52
Fix straggling link that still went to the old derive_schema field
nightkr 24be356
Added example for custom JsonSchema derive
nightkr a6a3083
Fix error building example tests
nightkr 1d89771
Update CHANGELOG.md
nightkr 3083d34
Update CHANGELOG.md
nightkr 92090b1
Move overrides into `#[kube(crates)]`, rename `schema_mode` to `schema`
nightkr adbc575
Update kube-derive/src/lib.rs
nightkr 42d8170
#[kube(schema = "custom")] => #[kube(schema = "manual")]
nightkr ca99b44
Merge branch 'master' into feature/derive-schema-finegrained-optout
nightkr a2fe3c4
Fix example still referring to `schema = "custom"`
nightkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use kube::CustomResourceExt; | ||
use kube_derive::CustomResource; | ||
use schemars::{ | ||
schema::{InstanceType, ObjectValidation, Schema, SchemaObject}, | ||
JsonSchema, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// CustomResource with manually implemented `JsonSchema` | ||
#[derive(CustomResource, Serialize, Deserialize, Debug, Clone)] | ||
#[kube( | ||
group = "clux.dev", | ||
version = "v1", | ||
kind = "Bar", | ||
namespaced, | ||
schema = "manual" | ||
)] | ||
pub struct MyBar { | ||
bars: u32, | ||
} | ||
|
||
impl JsonSchema for Bar { | ||
fn schema_name() -> String { | ||
"Bar".to_string() | ||
} | ||
|
||
fn json_schema(__gen: &mut schemars::gen::SchemaGenerator) -> Schema { | ||
Schema::Object(SchemaObject { | ||
object: Some(Box::new(ObjectValidation { | ||
required: ["spec".to_string()].into(), | ||
properties: [( | ||
"spec".to_string(), | ||
Schema::Object(SchemaObject { | ||
instance_type: Some(InstanceType::Object.into()), | ||
object: Some(Box::new(ObjectValidation { | ||
required: ["bars".to_string()].into(), | ||
properties: [( | ||
"bars".to_string(), | ||
Schema::Object(SchemaObject { | ||
instance_type: Some(InstanceType::Integer.into()), | ||
..SchemaObject::default() | ||
}), | ||
)] | ||
.into(), | ||
..ObjectValidation::default() | ||
})), | ||
..SchemaObject::default() | ||
}), | ||
)] | ||
.into(), | ||
..ObjectValidation::default() | ||
})), | ||
..SchemaObject::default() | ||
}) | ||
} | ||
} | ||
|
||
fn main() { | ||
let crd = Bar::crd(); | ||
println!("{}", serde_yaml::to_string(&crd).unwrap()); | ||
} | ||
|
||
// Verify CustomResource derivable still | ||
#[test] | ||
fn verify_bar_is_a_custom_resource() { | ||
use kube::Resource; | ||
use static_assertions::assert_impl_all; | ||
|
||
println!("Kind {}", Bar::kind(&())); | ||
let bar = Bar::new("five", MyBar { bars: 5 }); | ||
println!("Spec: {:?}", bar.spec); | ||
assert_impl_all!(Bar: kube::Resource, JsonSchema); | ||
|
||
let crd = Bar::crd(); | ||
for v in crd.spec.versions { | ||
assert!(v.schema.unwrap().open_api_v3_schema.is_some()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.