Skip to content

Commit

Permalink
Add new test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
altearius committed Jun 24, 2024
1 parent 31993de commit fb9fc26
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 0 deletions.
109 changes: 109 additions & 0 deletions test/__snapshots__/test/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,92 @@ Generated by [AVA](https://avajs.dev).
}␊
`

## intersection.4.js

> Expected output to match snapshot for e2e test: intersection.4.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export type Intersection = A | B1;␊
export type A = A1 & {␊
b?: B;␊
};␊
export type A1 = Base;␊
export type B = B1 & {␊
x?: string;␊
};␊
export type B1 = Base;␊
export interface Base {␊
y?: string;␊
}␊
`

## intersection.5.js

> Expected output to match snapshot for e2e test: intersection.5.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export type Intersection = A | B;␊
export type A = Base & {␊
b?: B;␊
[k: string]: unknown;␊
};␊
export type B = Base & {␊
x?: string;␊
[k: string]: unknown;␊
};␊
export interface Base {␊
y?: string;␊
}␊
`

## intersection.6.js

> Expected output to match snapshot for e2e test: intersection.6.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export type Intersection = Car | Truck;␊
export type Car = Car1 & {␊
numDoors: number;␊
[k: string]: unknown;␊
};␊
export type Car1 = Vehicle;␊
export type Vehicle = Vehicle1 & {␊
year: number;␊
[k: string]: unknown;␊
};␊
export type Vehicle1 = Thing;␊
export type Truck = Truck1 & {␊
numAxles: number;␊
[k: string]: unknown;␊
};␊
export type Truck1 = Vehicle1;␊
export interface Thing {␊
name: string;␊
[k: string]: unknown;␊
}␊
`

## namedProperty.js

> Expected output to match snapshot for e2e test: namedProperty.js
Expand Down Expand Up @@ -448930,6 +449016,29 @@ Generated by [AVA](https://avajs.dev).
export type Union = string | false;␊
`

## union.5.js

> Expected output to match snapshot for e2e test: union.5.js

`/* eslint-disable */␊
/**␊
* This file was automatically generated by json-schema-to-typescript.␊
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
* and run json-schema-to-typescript to regenerate this file.␊
*/␊
export type Union = A | B;␊
export type A = C | D;␊
export type B = C | D;␊
export interface C {␊
c?: string;␊
}␊
export interface D {␊
d?: string;␊
}␊
`

## union.js

> Expected output to match snapshot for e2e test: union.js
Expand Down
Binary file modified test/__snapshots__/test/test.ts.snap
Binary file not shown.
29 changes: 29 additions & 0 deletions test/e2e/intersection.4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const input = {
type: 'object',
oneOf: [{$ref: '#/definitions/A'}, {$ref: '#/definitions/B'}],
definitions: {
A: {
type: 'object',
allOf: [{$ref: '#/definitions/Base'}],
properties: {
b: {$ref: '#/definitions/B'},
},
additionalProperties: false,
},
B: {
type: 'object',
allOf: [{$ref: '#/definitions/Base'}],
properties: {
x: {type: 'string'},
},
additionalProperties: false,
},
Base: {
type: 'object',
properties: {
y: {type: 'string'},
},
additionalProperties: false,
},
},
}
37 changes: 37 additions & 0 deletions test/e2e/intersection.5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const input = {
type: 'object',
oneOf: [{$ref: '#/definitions/A'}, {$ref: '#/definitions/B'}],
definitions: {
A: {
type: 'object',
allOf: [
{$ref: '#/definitions/Base'},
{
properties: {
b: {$ref: '#/definitions/B'},
},
},
],
additionalProperties: false,
},
B: {
type: 'object',
allOf: [
{$ref: '#/definitions/Base'},
{
properties: {
x: {type: 'string'},
},
},
],
additionalProperties: false,
},
Base: {
type: 'object',
properties: {
y: {type: 'string'},
},
additionalProperties: false,
},
},
}
37 changes: 37 additions & 0 deletions test/e2e/intersection.6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// From https://github.com/bcherny/json-schema-to-typescript/issues/597
export const input = {
oneOf: [{$ref: '#/definitions/Car'}, {$ref: '#/definitions/Truck'}],
definitions: {
Thing: {
type: 'object',
properties: {
name: {type: 'string'},
},
required: ['name'],
},
Vehicle: {
type: 'object',
allOf: [{$ref: '#/definitions/Thing'}],
properties: {
year: {type: 'integer'},
},
required: ['year'],
},
Car: {
type: 'object',
allOf: [{$ref: '#/definitions/Vehicle'}],
properties: {
numDoors: {type: 'integer'},
},
required: ['numDoors'],
},
Truck: {
type: 'object',
allOf: [{$ref: '#/definitions/Vehicle'}],
properties: {
numAxles: {type: 'integer'},
},
required: ['numAxles'],
},
},
}
43 changes: 43 additions & 0 deletions test/e2e/union.5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const input = {
type: 'object',
oneOf: [{$ref: '#/definitions/A'}, {$ref: '#/definitions/B'}],
definitions: {
A: {
oneOf: [
{
$ref: '#/definitions/C',
},
{
$ref: '#/definitions/D',
},
],
additionalProperties: false,
},
B: {
type: 'object',
oneOf: [
{
$ref: '#/definitions/C',
},
{
$ref: '#/definitions/D',
},
],
additionalProperties: false,
},
C: {
type: 'object',
properties: {
c: {type: 'string'},
},
additionalProperties: false,
},
D: {
type: 'object',
properties: {
d: {type: 'string'},
},
additionalProperties: false,
},
},
}

0 comments on commit fb9fc26

Please sign in to comment.