Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { GenericDef } from 'good-cop'
import { ServiceDocObject } from '../../types/services.types'
import { _ } from '../../validator'
export function generateJsDoc(doc: ServiceDocObject, outputValidator: GenericDef) {
return `/** ${doc.description}${jsDocErrCodes(doc.errors)}${jsDocExample(outputValidator)}\n */`
}
function jsDocErrCodes(errDescr?: ServiceDocObject['errors']) {
return errDescr?.length
? `\n * @errorCodes\n${errDescr.map(([code, errMsg = '', errDescr = '']) => ` * - ${code}: ${errMsg}${errDescr ? ` - ${errDescr}` : ''}`)}`
: ''
}
function jsDocExample(def: GenericDef = _.void()) {
const example = def?.getExampleValue()
if (example) {
const aaa = JSON.stringify(example, null, 2)
.replace(/\\*"/g, '\'')
.replace(/\n/g, '\n * ')
return `\n * @example\n * ${aaa}`
} else return ''
} |