Created
January 20, 2015 10:28
-
-
Save shiwano/5aa018e2a2b141319e5a to your computer and use it in GitHub Desktop.
TypeScript の型定義からコードを自動生成するツールを作った ref: http://qiita.com/shiwano/items/dd769ead84e0da2d349a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$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"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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