Skip to content

Commit

Permalink
Ensure compatibility with preserve_order feature of schemars (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran authored May 3, 2024
2 parents 21e21c8 + 2e68ac6 commit 00bd0f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
3 changes: 2 additions & 1 deletion apistos-gen-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ futures-core = { workspace = true }
apistos = { path = "../apistos", features = ["multipart", "uuid"] }
apistos-core = { path = "../apistos-core", version = "0.2.1" }
apistos-gen = { path = "../apistos-gen", version = "0.2.1" }
schemars = { workspace = true }
# we use the "preserve_order" feature from schemars here following https://github.com/netwo-io/apistos/pull/78
schemars = { workspace = true, features = ["preserve_order"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
Expand Down
50 changes: 25 additions & 25 deletions apistos-gen-test/src/tests/api_component_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,31 +519,6 @@ fn api_component_derive_named_enums() {
);

let (child_schema_name, child_schema) = name_child_schemas.first().expect("missing child schema");
assert_eq!(child_schema_name, "ActiveOrInactiveQuery");
assert_schema(&child_schema.clone());
let json = serde_json::to_value(child_schema).expect("Unable to serialize as Json");
assert_json_eq!(
json,
json!({
"properties": {
"description": {
"type": "string"
},
"id": {
"format": "uint32",
"minimum": 0.0,
"type": "integer"
}
},
"required": [
"description",
"id"
],
"type": "object"
})
);

let (child_schema_name, child_schema) = name_child_schemas.last().expect("missing child schema");
assert_eq!(child_schema_name, "KindQuery");
assert_schema(&child_schema.clone());
let json = serde_json::to_value(child_schema).expect("Unable to serialize as Json");
Expand Down Expand Up @@ -580,6 +555,31 @@ fn api_component_derive_named_enums() {
]
})
);

let (child_schema_name, child_schema) = name_child_schemas.last().expect("missing child schema");
assert_eq!(child_schema_name, "ActiveOrInactiveQuery");
assert_schema(&child_schema.clone());
let json = serde_json::to_value(child_schema).expect("Unable to serialize as Json");
assert_json_eq!(
json,
json!({
"properties": {
"description": {
"type": "string"
},
"id": {
"format": "uint32",
"minimum": 0.0,
"type": "integer"
}
},
"required": [
"description",
"id"
],
"type": "object"
})
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion apistos-gen/src/internal/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ToTokens for Schemas {
schemars::schema::Schema::Object(sch_obj) => {
if let Some(obj) = sch_obj.object.as_mut() {
if obj.properties.len() == 1 {
if let Some((prop_name, _)) = obj.properties.first_key_value() {
if let Some((prop_name, _)) = obj.properties.iter().next() {
#update_metadata_title;
}
} else if let Some(enum_values) = obj.properties.iter_mut().find_map(|(_, p)| match p {
Expand Down

0 comments on commit 00bd0f0

Please sign in to comment.