Annotations don't contain dataType in case fo yo rest:api
kamal0808 opened this issue · 1 comments
Possible issue for: error: Cannot read property 'indexOf' of undefined
On receiving the above error, I went thru the code and found out that:
When created an API by using yo rest:api
, it doesn't generate the datatype in annotations for @apiParam
. See a sample annotation generated below for products
/**
* @api {post} /products Create product
* @apiName CreateProduct
* @apiGroup Product
* @apiParam name Product's name.
* @apiParam description Product's description.
* @apiParam price Product's price.
* @apiSuccess {Object} product Product's data.
* @apiError {Object} 400 Some parameters may contain invalid values.
* @apiError 404 Product not found.
*/
router.post('/',
body({ name, description, price }),
create)
Whereas, the user model generated by yo rest
does contain the datatype {String}
for @apiParam access_token
.
/**
* @api {get} /users Retrieve users
* @apiName RetrieveUsers
* @apiGroup User
* @apiPermission admin
* @apiParam {String} access_token User access_token.
* @apiUse listParams
* @apiSuccess {Object[]} users List of users.
* @apiError {Object} 400 Some parameters may contain invalid values.
* @apiError 401 Admin access only.
*/
I checked the code and there's a small fix required in this line, https://github.com/diegohaz/rest/blob/master/generators/api/templates/index.js#L71
I see the template in this line that could be used
https://github.com/diegohaz/rest/blob/master/generators/app/templates/api/user/index.js#L98
I understand that the user model already has the datatypes defined in annotations because the logic is defined for each param, and the yo rest:api
command doesn't accept datatypes from the CLI.
I am suggesting that since the generator already assigns the datatype String
to the params we create for the API, so let's assign "String" as the param data type in annotations.