From f61b70ba17a4a07994c2bcde5f055adfcfb05fd1 Mon Sep 17 00:00:00 2001 From: Mike Bush Date: Tue, 6 Oct 2020 08:45:26 +0000 Subject: [PATCH] Produce `items` field on parameters --- core/src/v2/actix.rs | 15 +++++++++--- tests/test_app.rs | 58 +++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/core/src/v2/actix.rs b/core/src/v2/actix.rs index 580f163910..e6d0ea6e0d 100644 --- a/core/src/v2/actix.rs +++ b/core/src/v2/actix.rs @@ -1,6 +1,6 @@ use super::models::{ - DefaultOperationRaw, DefaultResponseRaw, DefaultSchemaRaw, Either, Parameter, ParameterIn, - Response, SecurityScheme, + DefaultOperationRaw, DefaultResponseRaw, DefaultSchemaRaw, Either, Items, Parameter, + ParameterIn, Response, SecurityScheme, }; #[cfg(feature = "actix-multipart")] use super::schema::TypedData; @@ -316,11 +316,20 @@ macro_rules! impl_param_extractor ({ $ty:ty => $container:ident } => { op.parameters.push(Either::Right(Parameter { in_: ParameterIn::$container, required: def.required.contains(&k), - name: k, data_type: v.data_type, format: v.format, enum_: v.enum_, description: v.description, + items: v.items.as_ref().map(|schema| { + Items { + data_type: schema.data_type.clone(), + format: schema.format.clone(), + // collection_format, // this defaults to csv + enum_: schema.enum_.clone(), + ..Default::default() // range fields are not emitted + } + }), + name: k, ..Default::default() })); } diff --git a/tests/test_app.rs b/tests/test_app.rs index cd494202f1..3536f10151 100644 --- a/tests/test_app.rs +++ b/tests/test_app.rs @@ -309,7 +309,7 @@ fn test_params() { #[derive(Deserialize, Apiv2Schema)] struct BadgeParams { res: Option, - color: String, + colors: Vec, } #[derive(Deserialize, Apiv2Schema)] @@ -484,9 +484,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -514,9 +517,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -544,9 +550,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -574,9 +583,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -604,9 +616,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -634,9 +649,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -670,9 +688,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32", @@ -762,9 +783,12 @@ fn test_params() { }, { "in": "query", - "name": "color", + "items": { + "type": "string" + }, + "name": "colors", "required": true, - "type": "string" + "type": "array" }, { "format": "int32",