Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@anttiviljami/dtsgenerator
Advanced tools
TypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file.
npm install -g dtsgenerator
$ dtsgen --help
Usage: script [options] <file ... | file patterns using node-glob>
Options:
-V, --version output the version number
--url <url> input json schema from the url. (default: )
--stdin read stdin with other files or urls.
-o, --out <file> output d.ts filename.
-n, --namespace <namespace> use root namespace instead of definitions or components.schema from OpenAPI, or -n "" to suppress namespaces.
-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
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<void> {
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
JSON Schema
OpenAPI
export
when given empty namespace #386. Thank you @zregvart :+1:number
type enum values #365. Thank you @vincentlin02 :+1:maxItems
property #339. Thank you @keean :+1:application/x-www-form-urlencoded
branch on OpenAPI. #357nullable
property on OpenAPI by #319. Thank you @sakari :+1:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types.npmignore
dtsgenerator
is licensed under the MIT license.
Copyright © 2016-2019, Hiroki Horiuchi
v2.5.1 (2020-04-27)
FAQs
TypeScript d.ts file generator for JSON Schema file
We found that @anttiviljami/dtsgenerator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.