Registry / serialization / rm-json-schema-to-typescript

rm-json-schema-to-typescript

JSON →
library10.2.0jsnpmunverified

The `rm-json-schema-to-typescript` package is a fork of the popular `json-schema-to-typescript` library, designed to compile JSON schemas into TypeScript interfaces and typings. Currently at version 10.2.0, this package offers modified reference resolving behavior compared to its upstream counterpart. Its development status is tied to the original project, with an explicit intention to be deprecated once the core changes implemented in this fork are accepted into the main `json-schema-to-typescript` repository. As a fork, its release cadence is likely reactive to critical fixes or its specific feature set rather than a strict schedule. It aims to provide a drop-in replacement where its altered reference resolution is beneficial, but users should be aware of its temporary nature and plan for eventual migration.

npm install rm-json-schema-to-typescript
INSTALL
IMPORT
SIG · RM-JSON-SCHEMA-TO-
R
rm-json-schema-to-typescript
serializationjavascriptv10.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'json-schema-to-typescript'
const { compile } = require('json-schema-to-typescript')
The npm package is `rm-json-schema-to-typescript`, but the import path shown in the provided documentation is `json-schema-to-typescript`. This implies it's a drop-in replacement using the original's module name. Always verify the actual import path for the installed package.
compileFromFile
import { compileFromFile } from 'json-schema-to-typescript'
import { compileFromFile } from 'rm-json-schema-to-typescript'
Similar to `compile`, the import path refers to the original package name. Ensure your `package.json` correctly points to `rm-json-schema-to-typescript` if using this fork.
Options
import type { Options } from 'json-schema-to-typescript'
Type imports for configuration options are available. The options object can modify behavior like banner comments, `$ref` resolution, or Prettier formatting.

This quickstart demonstrates how to compile a JSON schema object into a TypeScript interface using the `compile` function, and how it writes the output to a file.

import { compile, compileFromFile } from 'json-schema-to-typescript'; import * as fs from 'fs/promises'; // Define a simple JSON schema programmatically const mySchema = { title: 'UserSchema', type: 'object', properties: { id: { type: 'string', format: 'uuid' }, name: { type: 'string' }, email: { type: 'string', format: 'email' }, isActive: { type: 'boolean', default: true } }, required: ['id', 'name', 'email'], additionalProperties: false }; async function generateTypes() { try { // Compile from a JS object in memory const tsFromObject = await compile(mySchema, 'UserSchema'); console.log('Generated from object:\n', tsFromObject); // For demonstration, write to a dummy file. In real use, this might be dynamic. await fs.writeFile('user.d.ts', tsFromObject); // Example of compiling from a file (assuming 'example.json' exists) // For a real scenario, you'd create this file first. // const tsFromFile = await compileFromFile('example.json'); // await fs.writeFile('example.d.ts', tsFromFile); console.log('TypeScript types generated successfully.'); } catch (error) { console.error('Error generating types:', error); } } generateTypes();
Debug
Known issues
deprecatedThis `rm-json-schema-to-typescript` package is a fork and is explicitly slated for deprecation once its specific changes are accepted into the upstream `json-schema-to-typescript` project. Users should treat it as a temporary solution and plan for migration.
fix
Monitor the original `json-schema-to-typescript` project for updates that incorporate the `rm-json-schema-to-typescript` fork's features. If no upstream merge occurs, consider migrating to another active JSON Schema to TypeScript solution or maintaining a custom fork.
affects: >=10.0.0
gotchaThis fork specifically features 'changed reference resolving' compared to the original `json-schema-to-typescript`. This modification may lead to different output typings for schemas that rely on complex `$ref` patterns.
fix
Thoroughly review generated TypeScript types if migrating from or to the original `json-schema-to-typescript` package, especially for schemas with external or complex internal `$ref`erences. Test the output against expected type definitions.
affects: >=10.0.0
gotchaDespite the npm package name being `rm-json-schema-to-typescript`, the provided documentation and code examples suggest importing symbols from `'json-schema-to-typescript'`. This discrepancy can cause confusion and potential module resolution errors if not handled correctly.
fix
When installing via npm as `rm-json-schema-to-typescript`, ensure your import statements in code use `import { ... } from 'json-schema-to-typescript'` as per the documentation. If issues arise, explicitly check your project's module resolution settings or the `package.json` `exports` field of the installed package.
affects: >=10.0.0
Errors
Common errors & fixes
Error: Cannot find module 'json-schema-to-typescript'
The package `rm-json-schema-to-typescript` is installed, but the import path in the code might be incorrect or the module resolver cannot find the aliased module.
fix
Ensure `rm-json-schema-to-typescript` is correctly installed. Based on the documentation, try `import { compile } from 'json-schema-to-typescript'` even if you installed the `rm-` prefixed package. Verify your `tsconfig.json` or module resolution settings if problems persist.
TypeError: Schema must be an object or boolean
The input provided to `compile` or `compileFromFile` is not a valid JSON Schema object or a path to a valid JSON Schema file.
fix
Validate your JSON Schema against the JSON Schema specification (e.g., using a linter or online validator) to ensure it is correctly structured. Check the file path for `compileFromFile`.
Error: $ref cycle detected
The JSON schema contains circular `$ref`erences that the parser cannot resolve, or the `cwd` option for resolving external references is incorrect.
fix
Review the `$ref` definitions in your JSON schema for circular dependencies. If using external `$ref`s, ensure the `cwd` option in `compile` or `compileFromFile` options correctly points to the base directory for resolution.
Upgrade
Version history
10.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
rm-json-schema-to-typescript — npm install rm-json-schema-to-typescript · libregistry