Swagger 3.0 - cannot add parameters to query parameter - express

I have node express application and am using swagger-jsdoc & swagger-ui-express
Inside router I place this code:
/**
* #swagger
* /get:
* get:
* tags: [ /api/roba/get ]
* summary: Vraca informacije o robi po datom id-u
* description: Vraca informacije o robi po datom id-u
* parameters:
* - name: robaid
* responses:
* 400:
* description: Nije prosledjen parametar robaid
*/
And it does work normally, however when I try adding description or anything else under - name it doesn't display that endpoint.
I get error YAMLSemanticError: Implicit map keys need to be on a single line at line 7, column 18: - name: robaid
Code that does not work (I tried only with required or description thinking one of these do not work but not working):
/**
* #swagger
* /get:
* get:
* tags: [ /api/roba/get ]
* summary: Vraca informacije o robi po datom id-u
* description: Vraca informacije o robi po datom id-u
* parameters:
* - name: robaid
* required: true
* description: Some description
* responses:
* 400:
* description: Nije prosledjen parametar robaid
*/

You are seeing the issue as the indentation isn't correct on lines of required and description, you can try the code below:
/**
* #swagger
* /get:
* get:
* tags: [ /api/roba/get ]
* summary: Vraca informacije o robi po datom id-u
* description: Vraca informacije o robi po datom id-u
* parameters:
* - name: robaid
* required: true
* description: Some description
* responses:
* 400:
* description: Nije prosledjen parametar robaid
*/
Hope it helps!

Related

Date regexp failing [duplicate]

I'm having trouble constructing a proper #regex marker.
I'm trying to match on a couple of date formats in my response JSON:
"created": "2017-03-23T14:16:25.854Z"
"modified": "2018-06-21T05:38:37.978Z"
I've attempted the following markers:
'#regex [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z'
'#regex [0-9]{4}-[0-9]{2}-[0-9]{2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}.'
'#regex \d+-\d+-\d+.\d+:\d+:\d+.\d+.'
All 3 forms appear to be correct (according to rubular.com). I've also played around with escaping characters that might be problematic. The only one I been able to get tot work so far is:
[0-9-T:.Z]+
But this feels a little "loose" of a pattern match.
Basically I'm attempting this:
* def meta = { created: '#regex[[0-9]{4}-[0-9]{2}-[0-9]{2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}.]', modified: '#regex[[0-9]{4}-[0-9]{2}-[0-9]{2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}.]' }
And match each response ==
"""
{
id: '#regex [a-z0-9]+',
name: '#string',
type: '<Type>',
meta: #(meta),
integration_id: '#uuid'
}
"""
Get an error similar to this:
KarateException: objects-api.feature:40 - path: $[0].meta.created, actual: '2016-11-30T20:48:16.782Z', expected: '#regex [0-9]+-[0-9]+-[0-9]+[0-9]+:[0-9]+:[0-9]+[0-9]+', reason: regex match failed
Here is a suggestion, why don't you parse the dates into java Date objects and that will open up more possibilities such as being able to compare 2 dates.
Here are good examples:
https://stackoverflow.com/a/54133126/143475
https://stackoverflow.com/a/55938480/143475
That said, I think you missed having to escape the backslash-es, this is a Java thing and is mentioned in the docs. So this works:
* def date = '2017-03-23T14:16:25.854Z'
* match date == '#regex \\d+-\\d+-\\d+.\\d+:\\d+:\\d+.\\d+.'
* match date == '#regex [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z'
The Karate JS engine also supports the RegExp JS object, so see if this example gives you some solutions as well:
https://stackoverflow.com/a/54768838/143475
EDIT, this works for me as well:
* def meta = { created: '#regex \\d+-\\d+-\\d+.\\d+:\\d+:\\d+.\\d+.', modified: '#regex \\d+-\\d+-\\d+.\\d+:\\d+:\\d+.\\d+.' }
* def response = [{ meta: { created: '2017-03-23T14:16:25.854Z', modified: '2018-06-21T05:38:37.978Z' } }]
* match each response == { meta: '#(meta)' }

Querying case-insensitive columns by SQL in Tarantool

We know that string Tarantool indices can be made case-insensitive by specifying the collation option: collation = "unicode_ci". E.g.:
t = box.schema.create_space("test")
t:format({{name = "id", type = "number"}, {name = "col1", type = "string"}})
t:create_index('primary')
t:create_index("col1_idx", {parts = {{field = "col1", type = "string", collation = "unicode_ci"}}})
t:insert{1, "aaa"}
t:insert{2, "bbb"}
t:insert{3, "ccc"}
Now we can do a case-insensitive query:
tarantool> t.index.col1_idx:select("AAA")
---
- - [1, 'aaa']
...
But how to do it using SQL? This doesn't work:
tarantool> box.execute("select * from \"test\" where \"col1\" = 'AAA'")
---
- metadata:
- name: id
type: number
- name: col1
type: string
rows: []
...
Neither does this:
tarantool> box.execute("select * from \"test\" indexed by \"col1_idx\" where \"col1\" = 'AAA'")
---
- metadata:
- name: id
type: number
- name: col1
type: string
rows: []
...
There's a dirty trick with a poor performance (full scan). We don't want it, do we?
tarantool> box.execute("select * from \"test\" indexed by \"col1_idx\" where upper(\"col1\") = 'AAA'")
---
- metadata:
- name: id
type: number
- name: col1
type: string
rows:
- [1, 'aaa']
...
At last, we have one more workaround:
tarantool> box.execute("select * from \"test\" where \"col1\" = 'AAA' collate \"unicode_ci\"")
---
- metadata:
- name: id
type: number
- name: col1
type: string
rows:
- [1, 'aaa']
...
But the question is - does it use the index? Without an index it also works...
One can check query plan to figure out whether particular index is used or not. To get query plan simply add 'EXPLAIN QUERY PLAN ' prefix to the original query. For instance:
tarantool> box.execute("explain query plan select * from \"test\" where \"col1\" = 'AAA' collate \"unicode_ci\"")
---
- metadata:
- name: selectid
type: integer
- name: order
type: integer
- name: from
type: integer
- name: detail
type: text
rows:
- [0, 0, 0, 'SEARCH TABLE test USING COVERING INDEX col1_idx (col1=?) (~1 row)']
...
So the answer is 'yes', index is used in this case.
As for another example:
box.execute("select * from \"test\" indexed by \"col1_idx\" where \"col1\" = 'AAA'")
Unfortunately collation in this comparison is binary, since index's collation is ignored. In SQL only column's collations are considered to be used during comparison. This limitation will be resolved as soon as corresponding issue is closed.

Swagger error - should have only three digit status codes

I am building a Swagger documentation for an API in Swagger Editor and I have this error :
should only have three-digit status codes, `default`, and vendor extensions (`x-*`) as properties
This is the swagger code:
/stareMesaj:
post:
tags:
- Metode disponibile
summary: Stare mesaj
description: Call de upload mesaj. More soon.
operationId: stareMesaj
responses:
'200':
description: 1.Ultimele 60 zile - Nu aveti drept de interogare stare pentru
mesaj/ 2.Mai mult de 60 zile - Formularul cu id de incarcare= xxx a
fost depus de mai mult de 60 de zile 3. Id maxim - Nu aveti drept
de interogare stare pentru mesaj= max id
headers:
X-Rate-Limit:
description: calls per hour allowed by the user
schema:
type: integer
format: int32
The error appears on this line :
responses:
Just before '200'
What might be the problem ? The status code is obviously three digit code
Thanks
X-Rate-Limit needs to be indented to the right of headers:
responses:
'200':
description: ...
headers:
X-Rate-Limit:
description: calls per hour allowed by the user
schema:
type: integer
format: int32

how to add arrays and examples in my Swagger UI using Swagger express?

To sum it up, I basically am trying to make a swagger Ui based on this "tutorial" : https://github.com/fliptoo/swagger-express
Unfortunately, it doesn't describe at all how to add examples for the body and how to add arrays as well.
The code for the documentation I have right now is :
/**
* #swagger
* path: /animal/dogs
* operations:
* - httpMethod: POST
* summary: Add several dogs to the animal shelter
* notes: Returns results of the post
* responseClass: Shelter
* nickname : shelterPostWithDogs
* consumes:
* - application/json
* parameters:
* - name: body
* schema: true
* description: Dogs object that needs to be added
* paramType: body
* required: true
* dataType: Dog
*/
And I have at the bottom :
/**
* #swagger
* models:
* Dog:
* id: Dog
* properties:
* dog_id:
* required: true
* type: int
* Shelter:
* id: Shelter
* properties:
* shelter_id:
* type: int
* location:
* type: string
*/
Unfortunately, with this, I have this in my Model :
Dog {
dog_id (int)
}
I would like instead to have this:
Dog {
[
{ dog_id(int)}
  ]
}
What do I have to change to get this result?
Bonus : How do I add examples to my model? I would like something similar to this one : http://petstore.swagger.io/#!/pet/addPet
Unfortunately, I don't know how to do it in swagger express
I am also very new to swagger-express but one thing I will suggest, you have to use type as "array" in models definition:
Dog:
id: Dog
properties:
dog_id:
required: true
type: **array**
Hope this will help you.
Thanks!

Rebol iterated face- truncating text

Using this code:
view layout [
t: text-list "this line truncated> lfkjsdflksjfslfsdjfsdlldskjflsdkfj" with [
text-pane: func [face id][
if pair? id [return 1 + second id / iter/size]
iter/offset: iter/old-offset: id - 1 * iter/size * 0x1
if iter/offset/y + iter/size/y > size/y [return none]
cnt: id: id + sn
if iter/text: pick data id [
iter/font/color: 255.0.0
lines: at data id
iter
]
]
]
]
All text beyond 'this line tuncated>' doesn't show up on the display window.
How do I get around this?
After a lot of painful digging here is how to NOT have the text-list truncate words from your
list. Add the "para: [ wrap?: false ]" line as shown below:
view layout [
t: text-list "this line truncated> lfkjsdflksjfslfsdjfsdlldskjflsdkfj" with [
text-pane: func [face id][
if pair? id [return 1 + second id / iter/size]
iter/offset: iter/old-offset: id - 1 * iter/size * 0x1
if iter/offset/y + iter/size/y > size/y [return none]
cnt: id: id + sn
if iter/text: pick data id [
iter/font/color: 255.0.0
lines: at data id
iter
]
]
para: [ wrap?: false ]
]
]