Skip to content

Support for generating examples #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jirifryc
Copy link
Contributor

@jirifryc jirifryc commented Feb 6, 2017

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.

@willfarrell
Copy link
Owner

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

@garbin
Copy link

garbin commented Feb 27, 2017

@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

@willfarrell
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants