TypeScript d.ts file generator for JSON Schema file
npm install dtsgeneratorwsTypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file.








- Install
- Usage
- Advance Usage
- Development
- ChangeLog
- License
npm install -g dtsgeneratorws
- Releases
``
$ dtsgen --help
Usage: script [options]
Options:
-V, --version output the version number
--url
--stdin read stdin with other files or urls.
-o, --out
-n, --namespace
-h, --help output usage information
Examples:
$ dtsgen --help
$ dtsgen --out types.d.ts schema/*/.schema.json
$ cat schema1.json | dtsgen
$ dtsgen -o swaggerSchema.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json
$ dtsgen -o petstore.d.ts -n PetStore --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
`
For customize the output type name.
npm install -S dtsgenerator
For example, it want to add the I prefix to the interface name.
This is not usual example...
https://github.com/horiuchi/dtsgenerator/blob/master/example/add-prefix/index.ts
`js
import dtsGenerator, { DefaultTypeNameConvertor, SchemaId } from 'dtsgenerator';
import * as fs from 'fs';
const filePath = '../../test/snapshots/json-schema-draft-04/schema/schema.json';
function typeNameConvertor(id: SchemaId): string[] {
const names = DefaultTypeNameConvertor(id);
if (names.length > 0) {
const lastIndex = names.length - 1;
names[lastIndex] = 'I' + names[lastIndex];
}
return names;
}
async function main(): Promise
const content = JSON.parse( fs.readFileSync(filePath, 'utf-8') );
const result = await dtsGenerator({
contents: [content],
typeNameConvertor,
});
console.log(result);
}
main();
`
Output debug message by debug library.
$ DEBUG=dtsgen dtsgen schema/news.json
- The home of JSON Schema
- The OpenAPI Specification
- JSON Schema
- Draft-04 and before
- Draft-07 and before
- OpenAPI
- OpenAPI Specification version 2.0
- OpenAPI Specification version 3.0
- supported features in these spec
- fixed:
- Fix: the bug of name conversion by #402. Thank you @unclechu :+1:
- Fix: Error when spaces included in a 'name' property under paths/parameters by #407. Thank you @scvnathan :+1:
- features:
- Add to support the text media type on Open API Schema by #396. Thank you @silesky :+1:
- fixed
- Fix: the bug of #386. thank you for reporting issue @Oloompa :+1:
- fixed
- Fix: typescript import statement #381. thank you @lupus92 :+1:
- Fix: use export when given empty namespace #386. Thank you @zregvart :+1:
dtsgenerator` is licensed under the MIT license.
Copyright © 2016-2020, Hiroki Horiuchi