Skip to content

Commit

Permalink
Merge pull request #1050 from teozkr/fix/schemars-preserve-order
Browse files Browse the repository at this point in the history
Fix compatibility with schemars' preserve_order feature
  • Loading branch information
nightkr committed Oct 14, 2022
2 parents b92dc5b + 04fe818 commit b2e5f77
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions kube-core/src/schema.rs
Expand Up @@ -2,14 +2,13 @@
//!
//! [`CustomResourceDefinition`]: `k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition`

use std::collections::btree_map::Entry;

// Used in docs
#[allow(unused_imports)] use schemars::gen::SchemaSettings;

use schemars::{
schema::{InstanceType, Metadata, ObjectValidation, Schema, SchemaObject, SingleOrVec},
visit::Visitor,
MapEntry,
};

/// schemars [`Visitor`] that rewrites a [`Schema`] to conform to Kubernetes' "structural schema" rules
Expand Down Expand Up @@ -101,10 +100,10 @@ fn hoist_subschema_properties(
let variant_properties = std::mem::take(&mut variant_obj.properties);
for (property_name, property) in variant_properties {
match common_obj.properties.entry(property_name) {
Entry::Vacant(entry) => {
MapEntry::Vacant(entry) => {
entry.insert(property);
}
Entry::Occupied(entry) => {
MapEntry::Occupied(entry) => {
if &property != entry.get() {
panic!("Property {:?} has the schema {:?} but was already defined as {:?} in another subschema. The schemas for a property used in multiple subschemas must be identical",
entry.key(),
Expand Down

0 comments on commit b2e5f77

Please sign in to comment.