swagger-koa
swagger-koa copied to clipboard
Question: How to avoid repeating validations specs in comments and code?
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!