Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger getMany query params wrong type on "filter" "or" "sort" "join" #196

Closed
DaVarga opened this issue Jul 31, 2019 · 3 comments · Fixed by #198
Closed

Swagger getMany query params wrong type on "filter" "or" "sort" "join" #196

DaVarga opened this issue Jul 31, 2019 · 3 comments · Fixed by #198

Comments

@DaVarga
Copy link
Contributor

DaVarga commented Jul 31, 2019

I experiencing some issues with the types of the getMany query params.
The types of filter or sort and join are reflected with "type": "string" where in my opinion they should have the type

"type": "array",
"items": {
  "type": "string"
},
  "collectionFormat": "multi"
}
@Diluka
Copy link
Contributor

Diluka commented Aug 1, 2019

since it's working nice. do you mean here?

const filterMeta = {
name: filter,
// tslint:disable-next-line:max-line-length
description: `<h4>Adds fields request condition (multiple conditions) to the request.</h4><i>Syntax:</i> <strong>?${filter}=field${d}condition${d}value</strong><br/><i>Examples:</i> <ul><li><strong>?${filter}=name${d}eq${d}batman</strong></li><li><strong>?${filter}=isVillain${d}eq${d}false&${filter}=city${d}eq${d}Arkham</strong> (multiple filters are treated as a combination of AND type of conditions)</li><li><strong>?${filter}=shots${d}in${d}12${coma}26</strong> (some conditions accept multiple values separated by commas)</li><li><strong>?${filter}=power${d}isnull</strong> (some conditions don't accept value)</li></ul><br/>Filter Conditions:<ul><li><strong><code>eq</code></strong> (<code>=</code>, equal)</li><li><strong><code>ne</code></strong> (<code>!=</code>, not equal)</li><li><strong><code>gt</code></strong> (<code>&gt;</code>, greater than)</li><li><strong><code>lt</code></strong> (<code>&lt;</code>, lower that)</li><li><strong><code>gte</code></strong> (<code>&gt;=</code>, greater than or equal)</li><li><strong><code>lte</code></strong> (<code>&lt;=</code>, lower than or equal)</li><li><strong><code>starts</code></strong> (<code>LIKE val%</code>, starts with)</li><li><strong><code>ends</code></strong> (<code>LIKE %val</code>, ends with)</li><li><strong><code>cont</code></strong> (<code>LIKE %val%</code>, contains)</li><li><strong><code>excl</code></strong> (<code>NOT LIKE %val%</code>, not contains)</li><li><strong><code>in</code></strong> (<code>IN</code>, in range, <strong><em>accepts multiple values</em></strong>)</li><li><strong><code>notin</code></strong> (<code>NOT IN</code>, not in range, <strong><em>accepts multiple values</em></strong>)</li><li><strong><code>isnull</code></strong> (<code>IS NULL</code>, is NULL, <strong><em>doesn't accept value</em></strong>)</li><li><strong><code>notnull</code></strong> (<code>IS NOT NULL</code>, not NULL, <strong><em>doesn't accept value</em></strong>)</li><li><strong><code>between</code></strong> (<code>BETWEEN</code>, between, <strong><em>accepts two values</em></strong>)</li></ul>`,
required: false,
in: 'query',
type: String,
};

filter is string. and it's a query param. so it can be repeat like ?filter=a||eq||1&filter=b||eq||2.

@DaVarga
Copy link
Contributor Author

DaVarga commented Aug 1, 2019

Yes exactly. Sure it works, but it doesn't comply with the swagger spec. https://swagger.io/docs/specification/2-0/describing-parameters/#array

If you generate a consumer api out of the swagger.json you most likely end up with an api wich only accepts one filter parameter. Passing something like a||eq||1&filter=b||eq||eq||2 might work, but it's not really nice.

I have tried to change the meta in swagger.helper.ts. That worked great. Also in the swagger interface you have separate input fields per parameter.

@chriszrc
Copy link

Adding many filter params is very cumbersome this way in the text box:

user_id||eq||1&filter=region||eq||Poland&filter=year||eq||2012

And requires typing in &filter over and over again, the collectionFormat = multi is nicer, the UI provides an option to click a button and add additional form fields for each additional filter parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants