Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-ts - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

lib/parse-options.d.ts

2

lib/definitions/fromSchemaOptions.d.ts
export declare type FromSchemaOptions = {
parseNotKeyword?: boolean;
parseIfThenElseKeywords?: boolean;
definitionsPath?: string;
};

@@ -8,2 +9,3 @@ export declare type FromSchemaDefaultOptions = {

parseIfThenElseKeywords: false;
definitionsPath: "$defs";
};

6

lib/index.d.ts

@@ -5,2 +5,3 @@ import { M } from "ts-algebra";

import type { ParseSchema } from "./parse-schema";
import type { ParseOptions } from "./parse-options";
import type { Readonly, Writable } from "./utils";

@@ -10,5 +11,2 @@ export { FromSchemaOptions, FromSchemaDefaultOptions } from "./definitions";

export declare type JSONSchema = JSONSchema7;
export declare type FromSchema<S extends JSONSchema7, O extends FromSchemaOptions = FromSchemaDefaultOptions> = M.$Resolve<ParseSchema<S extends O.Object ? Writable<S> : S, {
parseNotKeyword: O["parseNotKeyword"] extends boolean ? O["parseNotKeyword"] : FromSchemaDefaultOptions["parseNotKeyword"];
parseIfThenElseKeywords: O["parseIfThenElseKeywords"] extends boolean ? O["parseIfThenElseKeywords"] : FromSchemaDefaultOptions["parseIfThenElseKeywords"];
}>>;
export declare type FromSchema<S extends JSONSchema, O extends FromSchemaOptions = FromSchemaDefaultOptions, W extends $JSONSchema7 = S extends O.Object ? Writable<S> : S> = M.$Resolve<ParseSchema<W, ParseOptions<W, O>>>;

@@ -14,6 +14,9 @@ import { M } from "ts-algebra";

import { NullableSchema, ParseNullableSchema } from "./nullable";
import { DefinitionSchema, ParseDefinitionSchema } from "./definition";
export declare type ParseSchemaOptions = {
parseNotKeyword: boolean;
parseIfThenElseKeywords: boolean;
definitionsPath: string;
definitions: Record<string, JSONSchema7>;
};
export declare type ParseSchema<S extends JSONSchema7, O extends ParseSchemaOptions> = JSONSchema7 extends S ? M.Any : S extends true | string ? M.Any : S extends false ? M.Never : S extends NullableSchema ? ParseNullableSchema<S, O> : And<DoesExtend<O["parseIfThenElseKeywords"], true>, DoesExtend<S, IfThenElseSchema>> extends true ? S extends IfThenElseSchema ? ParseIfThenElseSchema<S, O> : never : And<DoesExtend<O["parseNotKeyword"], true>, DoesExtend<S, NotSchema>> extends true ? S extends NotSchema ? ParseNotSchema<S, O> : never : S extends AllOfSchema ? ParseAllOfSchema<S, O> : S extends OneOfSchema ? ParseOneOfSchema<S, O> : S extends AnyOfSchema ? ParseAnyOfSchema<S, O> : S extends EnumSchema ? ParseEnumSchema<S, O> : S extends ConstSchema ? ParseConstSchema<S, O> : S extends MultipleTypesSchema ? ParseMultipleTypesSchema<S, O> : S extends SingleTypeSchema ? ParseSingleTypeSchema<S, O> : M.Any;
export declare type ParseSchema<S extends JSONSchema7, O extends ParseSchemaOptions> = JSONSchema7 extends S ? M.Any : S extends true | string ? M.Any : S extends false ? M.Never : S extends NullableSchema ? ParseNullableSchema<S, O> : S extends DefinitionSchema<O> ? ParseDefinitionSchema<S, O> : And<DoesExtend<O["parseIfThenElseKeywords"], true>, DoesExtend<S, IfThenElseSchema>> extends true ? S extends IfThenElseSchema ? ParseIfThenElseSchema<S, O> : never : And<DoesExtend<O["parseNotKeyword"], true>, DoesExtend<S, NotSchema>> extends true ? S extends NotSchema ? ParseNotSchema<S, O> : never : S extends AllOfSchema ? ParseAllOfSchema<S, O> : S extends OneOfSchema ? ParseOneOfSchema<S, O> : S extends AnyOfSchema ? ParseAnyOfSchema<S, O> : S extends EnumSchema ? ParseEnumSchema<S, O> : S extends ConstSchema ? ParseConstSchema<S, O> : S extends MultipleTypesSchema ? ParseMultipleTypesSchema<S, O> : S extends SingleTypeSchema ? ParseSingleTypeSchema<S, O> : M.Any;
{
"name": "json-schema-to-ts",
"version": "2.1.2",
"version": "2.2.0",
"description": "Infer typescript types from your JSON schemas!",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -137,3 +137,3 @@ <img src="assets/header-round-medium.png" width="100%" align="center" />

- [If/Then/Else](#ifthenelse)
- [Definitions](#definitions)
- [Definitions](#definitions)
- [FAQ](#frequently-asked-questions)

@@ -615,8 +615,48 @@

## Definitions
### Definitions
Since the introduction of [template literal types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) with Typescript 4.1, the `definitions` keyword seems implementable in `json-schema-to-ts`.
```typescript
const personSchema = {
type: "object",
properties: {
firstName: { $ref: "#/$defs/name" },
lastName: { $ref: "#/$defs/name" },
},
required: ["firstName", "lastName"],
additionalProperties: false,
$defs: {
name: { type: "string" },
},
} as const;
I'll soon be looking into it. Meanwhile, feel free to [open an issue](https://github.com/ThomasAribart/json-schema-to-ts/issues) 🤗
type Person = FromSchema<typeof personSchema>;
// => {
// firstName: string;
// lastName: string;
// }
```
You can specify a different definitions path with the `definitionsPath` option:
```typescript
const personSchema = {
type: "object",
properties: {
firstName: { $ref: "#/definitions/name" },
lastName: { $ref: "#/definitions/name" },
},
required: ["firstName", "lastName"],
additionalProperties: false,
definitions: {
name: { type: "string" },
},
} as const;
type Person = FromSchema<
typeof personSchema,
{ definitionsPath: "definitions" }
>;
// => Will work 🙌
```
## Frequently Asked Questions

@@ -623,0 +663,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc