raml-to-typescript
v0.1.1raml-to-typescript
RAML to TypeScript Definition Files Converter. Uses raml2obj
and json-schema-to-typescript
.
See the changelog.
install
locally:
npm install --save raml-to-typescript
globally:
npm install -g raml-to-typescript
usage
as a CLI tool:
raml2ts -i example-contract/geo.raml -o example-dts
as a library:
const raml2ts = require('raml-to-typescript');
raml2ts.generateDefinitions(contractFilePath, outputDir)
.then(successCb)
.catch(errorCb)
// or
raml2ts.generateDefinitions(contractFilePath, outputDir, json2tsOptions)
.then(successCb)
.catch(errorCb)
example
RAML file:
#%RAML 1.0
title: Example Service
/geo:
/countries:
description: |
Collection of all countries.
get:
description: Fetch collection of countries
responses:
200:
body:
application/json:
type: !include countries.schema.json
related countries.schema.json
schema file:
{
"title": "Countries",
"type": "array",
"items": {
"$ref": "#/definitions/Country"
},
"definitions": {
"Country": {
"type": "object",
"properties": {
"id": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"pattern": "[A-Z]+"
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"id",
"name"
]
}
}
}
will produce following output:
export type Countries = Country[];
export interface Country {
id: string;
name: string;
}
limitations
Currently, only JSON Schema files are supported (RAML-defined types are not yet supported).
todos
- include request schemas as well as response schemas
npm i raml-to-typescript
Metadata
- MIT
- Whatever
- Tomasz Ducin
- released 1/17/2018