# docson

> Documentation for your JSON types

Latest version **2.1.0** (published 2018-08-08) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install docson
pnpm add docson
yarn add docson
bun add docson
```

Provides the command `docson`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-08-08 |
| First published | 2016-03-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 2.5 MB |
| Known vulnerabilities | 0 (+8 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 494 |
| Author | Laurent Bovet |
| Maintainers | lbovet, rom1504 |
| Keywords | json, schema, documentation |

## Links

- npm: https://www.npmjs.com/package/docson
- Repository: https://github.com/lbovet/docson
- Homepage: https://github.com/lbovet/docson#readme
- Issues: https://github.com/lbovet/docson/issues
- npm.io page: https://npm.io/package/docson

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [urijs](https://npm.io/package/urijs.md) ^1.19.1
- [jquery](https://npm.io/package/jquery.md) ^2.2.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [marked](https://npm.io/package/marked.md) ^0.3.14
- [express](https://npm.io/package/express.md) ^4.16.3
- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [commander](https://npm.io/package/commander.md) ^2.15.1
- [handlebars](https://npm.io/package/handlebars.md) ^4.0.11
- [jsonpointer](https://npm.io/package/jsonpointer.md) ^4.0.1
- [serve-index](https://npm.io/package/serve-index.md) ^1.9.1
- [jsonpointer.js](https://npm.io/package/jsonpointer.js.md) ^0.4.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.0 (latest) — 2018-08-08
- 2.0.1 — 2018-07-24
- 1.0.2 — 2016-03-22
- 1.0.1 — 2016-03-22
- 1.0.0 — 2016-03-22

## README

<p align='right'>A <a href="http://www.swisspush.org">swisspush</a> project <a href="http://www.swisspush.org" border=0><img align="top"  src='https://1.gravatar.com/avatar/cf7292487846085732baf808def5685a?s=32'></a></p>

Docson
======

Documentation for your JSON types.

Give Docson a JSON schema and it will generate a [beautiful documentation](http://lbovet.github.io/docson/index.html#/docson/examples/example.json).

## Features
* [JSON schema](http://json-schema.org/) v4 keywords.
* Runs entirely in the browser.
* Render schema descriptions with markdown

## Installation

* Place the Docson distribution on the web server serving the schemas (to avoid cross-origin issues).

## Usage

### Via cli tool

    $ docson -d ./schemas/
    server ready and running at localhost:3000

    # and then...
    firefox http://localhost:3000/schemas/ship.json

### As a webpage widget

To include a Docson schema documentations on any page (wiki, ...) without worrying about messing up with javascript libraries and cross-origin issues:

* Install Docson somewhere as described above.
* Place the following `script` tags in the including page, nothing else is needed:

    <script src="http://somewhere/path-to-docson/public/js/widget.js" data-schema="/path-to/schema.json">
    </script>


### Add to a webpage

* Open [index.html](http://lbovet.github.io/docson/index.html) and enter the schema path in the form field.
* Or give the schema path directly as hash parameter: [index.html#/docson/examples/example.json](http://lbovet.github.io/docson/index.html#/docson/examples/example.json)

Note that you can refer to a sub-schema by adding a json-pointer path as 'dollar-parameter': [index.html#/docson/examples/example.json$items](http://lbovet.github.io/docson/index.html#/docson/examples/example.json$items)

## Typson

You can directly reference your JSON types defined as TypeScript interfaces. If the path ends with `.ts`, Docson will use [Typson](https://github.com/lbovet/typson) to convert the Type Scripts to schema in order to generate the documentation.

For example, [index.html#/typson/example/invoice/line.ts$InvoiceLine](http://lbovet.github.io/docson/index.html#/typson/example/invoice/line.ts$InvoiceLine) is the documentation of [line.ts](https://github.com/lbovet/typson/blob/master/example/invoice/line.ts).

You need to install [Typson](https://github.com/lbovet/typson) by yourself on your server. It must be in a directory named `typson` located at the same level as the `docson` directory.


## Swagger

You can adapt [Swagger UI](https://github.com/wordnik/swagger-ui) to display Docson-generated model documentation instead of the builtin signatures.

See how it looks like in the [Swagger Docson example](http://lbovet.github.io/swagger-ui/dist/index.html)

In Swagger UI's `index.html`, include the [Swagger integration script after other script tags](https://github.com/lbovet/swagger-ui/blob/3f37722b03db6c48cc2a8460df26dda5f4d6f8e4/src/main/html/index.html#L19):

```html
  <script src='/path-to-docson/docson-swagger.js' type='text/javascript'></script>
```

Also, you will need a patched version of [Swagger Client](https://github.com/lbovet/swagger-js/blob/models-exposed/lib/swagger.js) so that the raw json-schema model is visible from Docson. Either replace the `swagger.js` file in your Swagger UI disctribution or take it directly from github by replacing

```html
   <script src='/lib/swagger.js' type='text/javascript'></script>
```

with 

```html
  <script src='https://raw2.github.com/lbovet/swagger-js/models-exposed/lib/swagger.js' type='text/javascript'></script>
```

For a better layout of parameter models, you may [want to change the width of some elements](https://github.com/lbovet/swagger-ui/blob/3f37722b03db6c48cc2a8460df26dda5f4d6f8e4/src/main/html/index.html#L20-L27):

```html
  <style>
      .swagger-ui-wrap {
          max-width: 1200px;
      }
      .swagger-ui-wrap .body-textarea {
          width: 200px;
      }
  </style>
```

## Integration

You can also integrate Docson in your application and use its javascript API:

```javascript
docson.doc(element, schema, ref)
```

* `element` is the element which will host the documentation. Either a DOM element (id or object) or jQuery element.
* `schema` is the URI or path to the schema or a string containing the schema source itself.
* `ref` is an optional json-pointer path to a sub-schema.

Examples:
* [Simple integration example](http://lbovet.github.io/docson/examples/example.html)
* [See it in action](http://lbovet.github.io/typson-demo/) with its buddy [typson](https://github.com/lbovet/typson).

## Limitations

* Mixing unrelated keywords can lead to unexpected results.

Not implemented:
* Non-primitive values in enums and default values
* dependencies, additionalItems, patternProperties

## Development

* [All tests](http://lbovet.github.io/docson/tests/test.html)

Please pull-request your failing schemas in the `tests/` folder and open an issue describing the expected result.

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lbovet/docson/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

---
_Source: https://npm.io/package/docson · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
