Skip to content

Instantly share code, notes, and snippets.

@shiwano
Created January 20, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiwano/5aa018e2a2b141319e5a to your computer and use it in GitHub Desktop.
Save shiwano/5aa018e2a2b141319e5a to your computer and use it in GitHub Desktop.
TypeScript の型定義からコードを自動生成するツールを作った ref: http://qiita.com/shiwano/items/dd769ead84e0da2d349a
interface Product {
/** The unique identifier for a product */
id: integer;
/** Name of the product */
name: string;
/**
@minimum 0
@exclusiveMinimum
*/
price: number;
/**
@minItems 1
@uniqueItems
*/
tags?: string[];
}
module.exports = function(typhen) {
var plugin = typhen.loadPlugin('typhen-json-schema', {
baseUri: 'http://example.com/my-schema'
});
return typhen.run({
plugin: plugin,
src: 'typings/definitions.d.ts',
dest: 'generated'
});
};
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product",
"description": "A product from \"Acme\"'s catalog ",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product ",
"type": "integer"
},
"name": {
"description": "Name of the product ",
"type": "string"
},
"price": {
"minimum": 0,
"exclusiveMinimum": true,
"type": "number"
},
"tags": {
"minItems": 1,
"uniqueItems": true,
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
"required": ["id", "name", "price"]
}
$ npm install -g typhen typhen-json-schema
$ typhen --plugin typhen-json-schema --dest generated definitions.d.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment