GithubHelp home page GithubHelp logo

typson's Introduction

Typson

Write your type definitions in TypeScript and Typson will generate json-schemas.

See it in action with its buddy docson

Build Status

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

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

Similar Projects

Bitdeli Badge

typson's People

Contributors

bartvds avatar bitdeli-chef avatar lbovet avatar vondacho avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.