Awesome
<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> # TypsonWrite your type definitions in TypeScript and Typson will generate json-schemas.
See it in action with its buddy docson
Features
- Available as Node.js module
- Can also run as-is in the browser.
- Integrates with Swagger.
- Supports types in multiple files.
- Translates required properties, extends, enums, maps, annotation keywords.
Usage
Node.js
- Install with
npm install typson -g
- Generate definitions from a type script:
typson schema example/invoice/line.ts
- Generate a schema from a type declared in a type script:
typson schema example/invoice/line.ts Invoice
Browser
<script src="vendor/require.js"/>
<script>
require(["lib/typson-schema"], function(typson) {
typson.schema("example/invoice/line.ts", "Invoice").done(function(schema) {
console.log(schema);
});
});
</script>
Swagger
Static
Generated definitions are compatible with Swagger, you can copy Typson's output to your API files.
Dynamic
You can make Swagger UI read type definitions directly by integrating Typson, you will need a modified version of swagger.js. This version just adds the capability to load the models from another source.
See how it looks like in the Swagger Typson example (Note: this example also illustrate Docson integration in Swagger).
Then, adapt Swagger UI's index.html
to
- Include Typson integration after the main inline script:
<script src="/typson/vendor/require.js"></script>
<script>
requirejs.config({
baseUrl: "/typson"
});
requirejs(["lib/typson-swagger"]);
</script>
- Initialize Swagger UI only once Typson is ready:
var typsonReady = $.Deferred();
typsonReady.done(function () {
instead of jQuery's $(function() {
initializer.
Then, just replace the models
section of your API file with a tsModels
property containing the URL pointing to the type script defining the models.