diff --git a/scripts/test.sh b/scripts/test.sh index f51048d8..2fe0aa64 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -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 diff --git a/utoipa/src/openapi/schema.rs b/utoipa/src/openapi/schema.rs index 573a24c6..c8e5ccbc 100644 --- a/utoipa/src/openapi/schema.rs +++ b/utoipa/src/openapi/schema.rs @@ -1031,6 +1031,12 @@ impl From for AdditionalProperties { } } +impl From for AdditionalProperties { + fn from(value: ArrayBuilder) -> Self { + Self::RefOr(RefOr::T(Schema::Array(value.build()))) + } +} + impl From for AdditionalProperties { fn from(value: Ref) -> Self { Self::RefOr(RefOr::Ref(value)) @@ -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();