
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
openapi-ts-json-schema
Advanced tools
Generate JSON schema TypeScript files (.ts
) from OpenAPI definitions which can be natively used to infer types from (with json-schema-to-ts
or fastify-type-provider-json-schema-to-ts
).
Given an OpenAPI definition file, openapi-ts-json-schema
will:
$ref
s and dereference them with @apidevtools/json-schema-ref-parser
(resolving $ref
's)@openapi-contrib/openapi-schema-to-json-schema
and openapi-jsonschema-parameters
.ts
files with as const
assertion)npm i openapi-ts-json-schema -D
import { openapiToTsJsonSchema } from 'openapi-ts-json-schema';
const { outputPath } = await openapiToTsJsonSchema({
openApiSchema: 'path/to/open-api-specs.yaml',
definitionPathsToGenerateFrom: ['paths', 'components.schemas'],
});
...then in your code:
import Ajv from 'ajv';
import { FromSchema } from 'json-schema-to-ts';
import myModelSchema from 'path/to/schemas-autogenerated/MyModel.ts';
// Use generated JSON schemas as usual
const ajv = new Ajv();
const valid = ajv.validate(myModelSchema, { hello: 'World' });
// Use generated JSON schemas to infer model types from
type MyModel = FromSchema<typeof myModelSchema>;
Generated JSON schema path names get escaped in order to be valid file system names.
Property | Type | Description | Default |
---|---|---|---|
openApiSchema (required) | string | Path to the OpenApi file (supports yaml and json). | - |
definitionPathsToGenerateFrom (required) | string[] | OpenApi definition object paths to generate the JSON schemas from. Only matching paths will be generated. (Supports dot notation: ["components.schemas"] ). | - |
schemaPatcher | (params: { schema: JSONSchema }) => void | Dynamically patch generated JSON schemas. The provided function will be invoked against every single JSON schema node. | - |
outputPath | string | Path where the generated schemas will be saved. Defaults to /schemas-autogenerated in same directory as provided openApiSchema . | - |
silent | boolean | Don't console.log user messages. | false |
definitionPathsToGenerateFrom
option in favour of exporting the whole OpenAPI definitions based on the structure defined in specs0.2.0
paths[path].parameters
and paths[path][operation].parameters
)$ref
property in deferenced schemasFAQs
OpenAPI to JSON schema generator with TypeScript in mind
The npm package openapi-ts-json-schema receives a total of 1,289 weekly downloads. As such, openapi-ts-json-schema popularity was classified as popular.
We found that openapi-ts-json-schema demonstrated a not healthy version release cadence and project activity because the last version was released 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
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.