Debian Codegraph @

tests/integration/settings.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/::{generaterust-analyzer cargo schemars 1.2.2 generate/::SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#};
4
5 #[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:)]
6 #[schemars(inline)]
7 pub struct OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct# {
8 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(extend("examples" = [8, null]))]
9 maybe_intrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#maybe_int.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i32>,
10 valuesrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#values.: serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::Maprust-analyzer cargo serde_json 1.0.151 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>,
11 valuerust-analyzer cargo schemars 1.2.2 settings/OuterStruct#value.: Valuerust-analyzer cargo serde_json 1.0.151 value/Value#,
12 innerrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#inner.: InnerEnumrust-analyzer cargo schemars 1.2.2 settings/InnerEnum#,
13 maybe_innerrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#maybe_inner.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<InnerEnumrust-analyzer cargo schemars 1.2.2 settings/InnerEnum#>,
14 tuplesrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#tuples.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(u8, i64)>,
15 }
16
17 #[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:)]
18 pub enum InnerEnumrust-analyzer cargo schemars 1.2.2 settings/InnerEnum# {
19 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
20 UndocumentedUnit1rust-analyzer cargo schemars 1.2.2 settings/InnerEnum#UndocumentedUnit1#,
21 UndocumentedUnit2rust-analyzer cargo schemars 1.2.2 settings/InnerEnum#UndocumentedUnit2#,
22 /// This is a documented unit variant
23 DocumentedUnitrust-analyzer cargo schemars 1.2.2 settings/InnerEnum#DocumentedUnit#,
24 ValueNewTyperust-analyzer cargo schemars 1.2.2 settings/InnerEnum#ValueNewType#(Valuerust-analyzer cargo serde_json 1.0.151 value/Value#),
25 }
26
27 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
28 fn draft07rust-analyzer cargo schemars 1.2.2 settings/draft07().() {
29 testrust-analyzer cargo schemars 1.2.2 test!!(OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#, SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::draft07rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft07().())
30 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
31 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
32 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
33 }
34
35 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
36 fn draft2019_09rust-analyzer cargo schemars 1.2.2 settings/draft2019_09().() {
37 testrust-analyzer cargo schemars 1.2.2 test!!(OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#, SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::draft2019_09rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft2019_09().())
38 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
39 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
40 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
41 }
42
43 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
44 fn draft2020_12rust-analyzer cargo schemars 1.2.2 settings/draft2020_12().() {
45 testrust-analyzer cargo schemars 1.2.2 test!!(OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#, SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::draft2020_12rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]draft2020_12().())
46 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
47 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
48 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
49 }
50
51 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
52 fn openapi3rust-analyzer cargo schemars 1.2.2 settings/openapi3().() {
53 let mut settings = SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::openapi3rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]openapi3().();
54 // Hack to apply recursive transforms to schemas at components.schemas:
55 // First, move them to $defs, then run the transforms, then move them back again.
56 settings.transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(
57 0,
58 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(|s: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#| {
59 let defs = s.pointer_mutrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]pointer_mut().("/components/schemas").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().takerust-analyzer cargo serde_json 1.0.151 value/impl#[Value]take().();
60 s.insertrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]insert().("$defs".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), defs);
61 }),
62 );
63 settings.transformsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#transforms..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(|s: &mut Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#| {
64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().s.pointer_mutrust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]pointer_mut().("/components/schemas").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() = s.removerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]remove().("$defs").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
65 }));
66
67 testrust-analyzer cargo schemars 1.2.2 test!!(OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#, settings.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Clone]clone().()).assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().();
68
69 // Ensure that `take_definitions()` applies transforms correctly
70
71 let gen1 = settings.into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().();
72 let definitions1 =
73 &Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::fromrust-analyzer cargo schemars 1.2.2 schema/impl#[Value][`From<Schema>`]from().(gen1.into_root_schema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for().::<OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#>())[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index()."components"]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().[rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index()."schemas"]rust-analyzer cargo serde_json 1.0.151 value/index/impl#[Value][`Index<I>`]index().;
74
75 let mut gen2 = SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#::openapi3rust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]openapi3().().into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().();
76 gen2.subschema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]subschema_for().::<OuterStructrust-analyzer cargo schemars 1.2.2 settings/OuterStruct#>();
77 let definitions2 = Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Objectrust-analyzer cargo serde_json 1.0.151 value/Value#Object#(gen2.take_definitionsrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]take_definitions().(true));
78
79 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(definitions1, &definitions2);
80 }