Skip to content

Commit

Permalink
Added typson integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet committed Dec 22, 2013
1 parent 17ad5f9 commit d42d70a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Give Docson a JSON schema and it will generate a [beautiful documentation](http:

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).

[Typson](https://github.com/lbovet/typson) must be located at the same level as the `docson` directory on your server. Keep its directory named `typson`.

## Widget

To include a Docson schema documentations on any page (wiki, ...) without worrying about messing up with javascript libraries and cross-origin issues:
Expand Down
32 changes: 21 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,27 @@
$("#form").hide();
url = decodeURIComponent(window.location.hash.substring(1));
var segments = url.split("$");
$.get(segments[0])
.done(function (schema) {
try {
docson.doc("doc", schema, segments[1]);
} catch (e) {
error("Could not parse schema: " + e.message + "<pre>" + $('<pre/>').text(schema).html() + "</pre>");
}
})
.fail(function (xhr, status, err) {
error("Could not load " + segments[0] + ": " + status + " " + err);
});

function render(schema) {
try {
docson.doc("doc", schema, segments[1]);
} catch (e) {
error("Could not parse schema: " + e.message + "<pre>" + $('<pre/>').text(schema).html() + "</pre>");
}
}

if(/\.ts$/.test(segments[0])) {
require.config( { baseUrl: "../typson" } );
require(["typson-schema"], function(typson) {
typson.definitions(segments[0]).done(render);
});
} else {
$.get(segments[0])
.done(render)
.fail(function (xhr, status, err) {
error("Could not load " + segments[0] + ": " + status + " " + err);
});
}
} else {
$("#doc").empty();
$("#form").show();
Expand Down

0 comments on commit d42d70a

Please sign in to comment.