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

Annotations don't contain dataType in case fo yo rest:api #265

Open
kamal0808 opened this issue May 30, 2021 · 1 comment · May be fixed by #266
Open

Annotations don't contain dataType in case fo yo rest:api #265

kamal0808 opened this issue May 30, 2021 · 1 comment · May be fixed by #266

Comments

@kamal0808
Copy link

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.

@kamal0808
Copy link
Author

Created a pull request, could someone be working on accepting the dataTypes for models' attributes?
#266

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.

1 participant