Support for generating examples
Hi,
this allow user to use json schema for generating examples. (@apiErrorExample, @apiHeaderExample, @apiParamExample and @apiSuccessExample) via:
@apiSchema (Title) {jsonschema=schema.json} apiSuccessExample
Generation of example is done via json-schema-faker, so it can benefit from all its functions. For instance json schema: { "type": "string", "faker": "internet.email" } Will generate random email address. For more information look here or here
Possible problems with this:
- Generated examples changes each generation. (But this can be prevented by specifying value for faker)
- This code for [Title] in @apiHeaderExample,... uses {Group} from @apiSchema (or 'Example:' if group wasn´t specified). This could be somewhat misleading for user.
Have you checked out https://github.com/willfarrell/apidoc-plugin-example?
@willfarrell the plugin is not working.
error:
debug: SyntaxError: Unexpected token a in JSON at position 0
at JSON.parse (<anonymous>)
at Object.build [as json] (/Users/garbin/Documents/Projects/koapi/koapp/node_modules/apidoc-plugin-example/schema/json.js:3:18)
docs:
* @apiExample {json=../../../../docs/schemas/client/sample.json} apiSuccessExample Response
I found var data in var json = JSON.parse(data); schema/json.js is 'apiSuccessExample'
apidoc version 0.17.5
Sorry everyone for taking so long. @garbin the latest version has been fixed, there was a breaking change in the core module. Can you try the latest version?