Skip to content

Commit

Permalink
Produce items field on parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
platy committed Oct 6, 2020
1 parent bdf51fe commit f61b70b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
15 changes: 12 additions & 3 deletions core/src/v2/actix.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
}));
}
Expand Down
58 changes: 41 additions & 17 deletions tests/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn test_params() {
#[derive(Deserialize, Apiv2Schema)]
struct BadgeParams {
res: Option<u16>,
color: String,
colors: Vec<String>,
}

#[derive(Deserialize, Apiv2Schema)]
Expand Down Expand Up @@ -484,9 +484,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -514,9 +517,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -544,9 +550,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -574,9 +583,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -604,9 +616,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -634,9 +649,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -670,9 +688,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down Expand Up @@ -762,9 +783,12 @@ fn test_params() {
},
{
"in": "query",
"name": "color",
"items": {
"type": "string"
},
"name": "colors",
"required": true,
"type": "string"
"type": "array"
},
{
"format": "int32",
Expand Down

0 comments on commit f61b70b

Please sign in to comment.