Skip to content

Commit

Permalink
Allow additionalProperties to be an array (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Sep 12, 2023
1 parent b1ce2d0 commit 1b3479e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
54 changes: 29 additions & 25 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@

set -e

crate="$1"

echo "Testing crate: $crate..."

if [[ "$crate" == "utoipa" ]]; then
cargo test -p utoipa --features openapi_extensions,preserve_order,preserve_path_order,debug
elif [[ "$crate" == "utoipa-gen" ]]; then
cargo test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,utoipa/uuid,uuid,utoipa/ulid,ulid,utoipa/url,url,utoipa/time,time,utoipa/repr,utoipa/smallvec,smallvec,rc_schema,utoipa/rc_schema

cargo test -p utoipa-gen --test schema_derive_test --features decimal_float
cargo test -p utoipa-gen --test path_derive_auto_into_responses --features auto_into_responses,utoipa/uuid,uuid
cargo test -p utoipa-gen --test path_derive_actix --test path_parameter_derive_actix --features actix_extras,utoipa/uuid,uuid
cargo test -p utoipa-gen --test path_derive_auto_into_responses_actix --features actix_extras,utoipa/auto_into_responses,utoipa/uuid,uuid

cargo test -p utoipa-gen --test path_derive_rocket --features rocket_extras

cargo test -p utoipa-gen --test path_derive_axum_test --features axum_extras
cargo test -p utoipa-gen --test path_derive_auto_into_responses_axum --features axum_extras,utoipa/auto_into_responses
elif [[ "$crate" == "utoipa-swagger-ui" ]]; then
cargo test -p utoipa-swagger-ui --features actix-web,rocket,axum
elif [[ "$crate" == "utoipa-redoc" ]]; then
cargo test -p utoipa-redoc --features actix-web,rocket,axum
elif [[ "$crate" == "utoipa-rapidoc" ]]; then
cargo test -p utoipa-rapidoc --features actix-web,rocket,axum
fi
: "${CARGO:=cargo}"

crates="${1:-utoipa utoipa-gen utoipa-swagger-ui utoipa-redoc utoipa-rapidoc}"

for crate in $crates; do
echo "Testing crate: $crate..."

if [[ "$crate" == "utoipa" ]]; then
$CARGO test -p utoipa --features openapi_extensions,preserve_order,preserve_path_order,debug
elif [[ "$crate" == "utoipa-gen" ]]; then
$CARGO test -p utoipa-gen --features utoipa/actix_extras,chrono,decimal,utoipa/uuid,uuid,utoipa/ulid,ulid,utoipa/url,url,utoipa/time,time,utoipa/repr,utoipa/smallvec,smallvec,rc_schema,utoipa/rc_schema

$CARGO test -p utoipa-gen --test schema_derive_test --features decimal_float
$CARGO test -p utoipa-gen --test path_derive_auto_into_responses --features auto_into_responses,utoipa/uuid,uuid
$CARGO test -p utoipa-gen --test path_derive_actix --test path_parameter_derive_actix --features actix_extras,utoipa/uuid,uuid
$CARGO test -p utoipa-gen --test path_derive_auto_into_responses_actix --features actix_extras,utoipa/auto_into_responses,utoipa/uuid,uuid

$CARGO test -p utoipa-gen --test path_derive_rocket --features rocket_extras

$CARGO test -p utoipa-gen --test path_derive_axum_test --features axum_extras
$CARGO test -p utoipa-gen --test path_derive_auto_into_responses_axum --features axum_extras,utoipa/auto_into_responses
elif [[ "$crate" == "utoipa-swagger-ui" ]]; then
$CARGO test -p utoipa-swagger-ui --features actix-web,rocket,axum
elif [[ "$crate" == "utoipa-redoc" ]]; then
$CARGO test -p utoipa-redoc --features actix-web,rocket,axum
elif [[ "$crate" == "utoipa-rapidoc" ]]; then
$CARGO test -p utoipa-rapidoc --features actix-web,rocket,axum
fi
done
24 changes: 24 additions & 0 deletions utoipa/src/openapi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ impl From<ObjectBuilder> for AdditionalProperties<Schema> {
}
}

impl From<ArrayBuilder> for AdditionalProperties<Schema> {
fn from(value: ArrayBuilder) -> Self {
Self::RefOr(RefOr::T(Schema::Array(value.build())))
}
}

impl From<Ref> for AdditionalProperties<Schema> {
fn from(value: Ref) -> Self {
Self::RefOr(RefOr::Ref(value))
Expand Down Expand Up @@ -1615,6 +1621,24 @@ mod tests {
})
);

let json_value = ObjectBuilder::new()
.additional_properties(Some(
ArrayBuilder::new().items(ObjectBuilder::new().schema_type(SchemaType::Number)),
))
.build();
assert_json_eq!(
json_value,
json!({
"type": "object",
"additionalProperties": {
"items": {
"type": "number",
},
"type": "array",
}
})
);

let json_value = ObjectBuilder::new()
.additional_properties(Some(Ref::from_schema_name("ComplexModel")))
.build();
Expand Down

0 comments on commit 1b3479e

Please sign in to comment.