
Research
Malicious npm Package Brand-Squats TanStack to Exfiltrate Environment Variables
A brand-squatted TanStack npm package used postinstall scripts to steal .env files and exfiltrate developer secrets to an attacker-controlled endpoint.
openapi-typescript-validator
Advanced tools
Generate typescript with ajv validation based on openapi schemas
Generate typescript with ajv validation based on openapi schemas
This package will convert your openapi 3.0 spec to:
This schema (note: also works with JSON based schema's)
components:
schemas:
User:
type: object
properties:
id:
type: string
name:
type: string
required: ['id']
Will convert to:
export interface User {
id: string;
name?: string;
}
And will generate a decoder:
// user will be of type User if the JSON is valid
const user = UserDecoder.decode(json);
If the JSON is invalid, it will throw an error:
const user = UserDecoder.decode({
id: 1
});
// User: /id: should be string. JSON: {"id":1}
References als work, this schema
{
"components": {
"schemas": {
"Screen": {
"type": "object",
"properties": {
"components": {
"type": "array",
"items": { "$ref": "#/components/schemas/Component" }
}
},
"required": [ "components" ]
},
"Component": {
"oneOf": [
{ "$ref": "#/components/schemas/TitleComponent" },
{ "$ref": "#/components/schemas/ImageComponent" }
]
},
"TitleComponent": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["title"]
},
"title": {
"type": "string"
}
},
"required": [ "type", "title" ]
},
"ImageComponent": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["image"]
},
"url": {
"type": "string"
}
},
"required": [ "type", "url" ]
}
}
}
}
will generate
export type Component = TitleComponent | ImageComponent;
export interface Screen {
components: Component[];
}
export interface TitleComponent {
type: "title";
title: string;
}
export interface ImageComponent {
type: "image";
url: string;
}
Install the package
npm i openapi-typescript-validator --save-dev
We use ajv for the decoders
npm i ajv
Your tsconfig.json file will need to be able to resolve the json files.
"resolveJsonModule": true
Create a node script called generate-schemas.js
const path = require('path');
const { generate } = require('openapi-typescript-validator');
generate({
schemaFile: path.join(__dirname, 'myswagger.yaml'),
schemaType: 'yaml',
name: 'api',
directory: path.join(__dirname, '/generated')
})
and run node generate-schemas.js
generate can be called with GenerateOptions
| param | required | description |
|---|---|---|
| schemaFile | true | file location of the schema. |
| schemaType | true | yaml or json |
| name | true | prefix for the generated files |
| directory | true | location where the output files will be stored to |
| prettierOptions | false | See Prettier Options |
FAQs
Generate typescript with ajv validation based on openapi schemas
The npm package openapi-typescript-validator receives a total of 1,319 weekly downloads. As such, openapi-typescript-validator popularity was classified as popular.
We found that openapi-typescript-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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.

Research
A brand-squatted TanStack npm package used postinstall scripts to steal .env files and exfiltrate developer secrets to an attacker-controlled endpoint.

Research
Compromised SAP CAP npm packages download and execute unverified binaries, creating urgent supply chain risk for affected developers and CI/CD environments.

Company News
Socket has acquired Secure Annex to expand extension security across browsers, IDEs, and AI tools.