Debian Codegraph @

tests/integration/transform.rs

raw symbols SCIP
1 use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*;
2 use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!;
3 use schemarsrust-analyzer cargo schemars 1.2.2 crate/::{
4 transformrust-analyzer cargo schemars 1.2.2 transform/::{RecursiveTransformrust-analyzer cargo schemars 1.2.2 transform/RecursiveTransform#, Transformrust-analyzer cargo schemars 1.2.2 transform/Transform#},
5 Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#,
6 };
7 use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Maprust-analyzer cargo serde_json 1.0.151 map/Map#;
8
9 fn insert_upper_typerust-analyzer cargo schemars 1.2.2 transform/insert_upper_type().(schema: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#) {
10 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Stringrust-analyzer cargo serde_json 1.0.151 value/Value#String#(ty)) = schema.getrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]get().("type") {
11 schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("x-upperType".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), ty.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
12 }
13 }
14
15 fn insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().(schema: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#) {
16 let count = schema
17 .getrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]get().("properties")
18 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::as_objectrust-analyzer cargo serde_json 1.0.151 value/impl#[Value]as_object().)
19 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(0, Maprust-analyzer cargo serde_json 1.0.151 map/Map#::lenrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`]len().);
20 schema.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("x-propertyCount".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), count.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
21 }
22
23 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
24 #[schemars(transform = RecursiveTransformrust-analyzer cargo schemars 1.2.2 transform/RecursiveTransform#(insert_upper_typerust-analyzer cargo schemars 1.2.2 transform/insert_upper_type().), transform = insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().)]
25 struct Structrust-analyzer cargo schemars 1.2.2 transform/Struct# {
26 valuerust-analyzer cargo schemars 1.2.2 transform/Struct#value.: Valuerust-analyzer cargo serde_json 1.0.151 value/Value#,
27 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(transform = insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().)]
28 intrust-analyzer cargo schemars 1.2.2 transform/Struct#int.: i32,
29 }
30
31 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
32 fn transform_structrust-analyzer cargo schemars 1.2.2 transform/transform_struct().() {
33 testrust-analyzer cargo schemars 1.2.2 test!!(Structrust-analyzer cargo schemars 1.2.2 transform/Struct#)
34 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
35 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
36 .customrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]custom().(assert_upper_type_validrust-analyzer cargo schemars 1.2.2 transform/assert_upper_type_valid().);
37 }
38
39 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
40 #[schemars(transform = RecursiveTransformrust-analyzer cargo schemars 1.2.2 transform/RecursiveTransform#(insert_upper_typerust-analyzer cargo schemars 1.2.2 transform/insert_upper_type().), transform = insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().)]
41 enum Externalrust-analyzer cargo schemars 1.2.2 transform/External# {
42 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
43 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(transform = insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().)]
44 Unitrust-analyzer cargo schemars 1.2.2 transform/External#Unit#,
45 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(transform = insert_property_countrust-analyzer cargo schemars 1.2.2 transform/insert_property_count().)]
46 NewTyperust-analyzer cargo schemars 1.2.2 transform/External#NewType#(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#),
47 }
48
49 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
50 fn transform_enumrust-analyzer cargo schemars 1.2.2 transform/transform_enum().() {
51 testrust-analyzer cargo schemars 1.2.2 test!!(Externalrust-analyzer cargo schemars 1.2.2 transform/External#)
52 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
53 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
54 .customrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]custom().(assert_upper_type_validrust-analyzer cargo schemars 1.2.2 transform/assert_upper_type_valid().);
55 }
56
57 fn assert_upper_type_validrust-analyzer cargo schemars 1.2.2 transform/assert_upper_type_valid().(schema: &Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, _: schemarsrust-analyzer cargo schemars 1.2.2 crate/::generaterust-analyzer cargo schemars 1.2.2 generate/::Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#) {
58 let mut schema = schema.clonerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][Clone]clone().();
59
60 RecursiveTransformrust-analyzer cargo schemars 1.2.2 transform/RecursiveTransform#(|s: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#| {
61 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(
62 s.removerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]remove().("x-upperType").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
63 s.getrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]get().("type").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().()),
64 );
65 })
66 .transformrust-analyzer cargo schemars 1.2.2 transform/impl#[`RecursiveTransform<T>`][Transform]transform().(&mut schema);
67
68 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().schema.to_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]to_value().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("x-upperType"));
69 }