swagger-koa icon indicating copy to clipboard operation
swagger-koa copied to clipboard

Question: How to avoid repeating validations specs in comments and code?

Open jonahx opened this issue 8 years ago • 0 comments

Very nice project.

If I understand correctly, you write your API specs as jsdoc comments. This middleware will read them and populate a swagger frontend for you, allowing you to browse them.

Consider the parameters section:

 *      parameters:
 *        - name: username
 *          description: Your username
 *          paramType: query
 *          required: true
 *          dataType: string
 *        - name: password
 *          description: Your password
 *          paramType: query
 *          required: true
 *          dataType: string

which outlines validation specs. These are specs I'd obviously want to enforce in code as well, using something like validate.js. But repeating this validation info as both code and comments is cumbersome, and also risks the documentation becoming out of sync with the code. I'd rather generate the parameters part of the spec directly from the objects that define the actual validation.

Is this a problem you've solved yourself? Any recommendations?

Thanks!

jonahx avatar Apr 18 '16 18:04 jonahx