apidoc-plugin-schema icon indicating copy to clipboard operation
apidoc-plugin-schema copied to clipboard

Support for generating examples

Open jirifryc opened this issue 9 years ago • 3 comments

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:

  1. Generated examples changes each generation. (But this can be prevented by specifying value for faker)
  2. This code for [Title] in @apiHeaderExample,... uses {Group} from @apiSchema (or 'Example:' if group wasn´t specified). This could be somewhat misleading for user.

jirifryc avatar Feb 06 '17 12:02 jirifryc

Have you checked out https://github.com/willfarrell/apidoc-plugin-example?

willfarrell avatar Feb 06 '17 15:02 willfarrell

@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

garbin avatar Feb 27 '17 04:02 garbin

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?

willfarrell avatar May 16 '17 00:05 willfarrell