Skip to content

Commit 0de5bb7

Browse files
authored
Purely rely on e2e tests for exercising the generator (#11)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 72bc6cf commit 0de5bb7

File tree

19 files changed

+477
-1288
lines changed

19 files changed

+477
-1288
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ if(CODEGEN_TESTS)
7777
endif()
7878

7979
if(CODEGEN_GENERATOR)
80-
add_subdirectory(test/generator)
8180
add_subdirectory(test/e2e/typescript)
8281
endif()
8382

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export type ApiResponseMeta = ApiResponseHttpsexamplecomschemasmetadata;
2+
3+
export type ApiResponseData = ApiResponseHttpsexamplecomschemasuser;
4+
5+
export type ApiResponseAdditionalProperties = never;
6+
7+
export type ApiResponseHttpsexamplecomschemasuserName = string;
8+
9+
export type ApiResponseHttpsexamplecomschemasuserId = number;
10+
11+
export type ApiResponseHttpsexamplecomschemasuserEmail = ApiResponseHttpsexamplecomschemasemail;
12+
13+
export type ApiResponseHttpsexamplecomschemasuserAdditionalProperties = never;
14+
15+
export interface ApiResponseHttpsexamplecomschemasuser {
16+
"id": ApiResponseHttpsexamplecomschemasuserId;
17+
"name": ApiResponseHttpsexamplecomschemasuserName;
18+
"email"?: ApiResponseHttpsexamplecomschemasuserEmail;
19+
}
20+
21+
export type ApiResponseHttpsexamplecomschemasmetadataVersion = number;
22+
23+
export type ApiResponseHttpsexamplecomschemasmetadataTimestamp = string;
24+
25+
export type ApiResponseHttpsexamplecomschemasmetadataAdditionalProperties = never;
26+
27+
export interface ApiResponseHttpsexamplecomschemasmetadata {
28+
"timestamp"?: ApiResponseHttpsexamplecomschemasmetadataTimestamp;
29+
"version"?: ApiResponseHttpsexamplecomschemasmetadataVersion;
30+
}
31+
32+
export type ApiResponseHttpsexamplecomschemasemail = string;
33+
34+
export interface ApiResponse {
35+
"data": ApiResponseData;
36+
"meta": ApiResponseMeta;
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"defaultPrefix": "ApiResponse"
3+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$id": "https://example.com/api/response",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"description": "A bundled API response schema with embedded resource schemas",
5+
"type": "object",
6+
"required": [ "data", "meta" ],
7+
"properties": {
8+
"data": { "$ref": "https://example.com/schemas/user" },
9+
"meta": { "$ref": "https://example.com/schemas/metadata" }
10+
},
11+
"additionalProperties": false,
12+
"$defs": {
13+
"https://example.com/schemas/user": {
14+
"$schema": "https://json-schema.org/draft/2020-12/schema",
15+
"$id": "https://example.com/schemas/user",
16+
"type": "object",
17+
"required": [ "id", "name" ],
18+
"properties": {
19+
"id": { "type": "integer" },
20+
"name": { "type": "string" },
21+
"email": { "$ref": "https://example.com/schemas/email" }
22+
},
23+
"additionalProperties": false
24+
},
25+
"https://example.com/schemas/email": {
26+
"$schema": "https://json-schema.org/draft/2020-12/schema",
27+
"$id": "https://example.com/schemas/email",
28+
"type": "string",
29+
"format": "email"
30+
},
31+
"https://example.com/schemas/metadata": {
32+
"$schema": "https://json-schema.org/draft/2020-12/schema",
33+
"$id": "https://example.com/schemas/metadata",
34+
"type": "object",
35+
"properties": {
36+
"timestamp": { "type": "string" },
37+
"version": { "type": "integer" }
38+
},
39+
"additionalProperties": false
40+
}
41+
}
42+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import {
2+
ApiResponse,
3+
ApiResponseHttpsexamplecomschemasuser,
4+
ApiResponseHttpsexamplecomschemasmetadata,
5+
ApiResponseHttpsexamplecomschemasemail
6+
} from "./expected";
7+
8+
9+
// Valid: full API response with all fields
10+
const fullResponse: ApiResponse = {
11+
data: {
12+
id: 123,
13+
name: "John Doe",
14+
15+
},
16+
meta: {
17+
timestamp: "2024-01-15T10:30:00Z",
18+
version: 1
19+
}
20+
};
21+
22+
// Valid: minimal response (required fields only)
23+
const minimalResponse: ApiResponse = {
24+
data: {
25+
id: 1,
26+
name: "Jane"
27+
},
28+
meta: {}
29+
};
30+
31+
// Valid: user object directly
32+
const user: ApiResponseHttpsexamplecomschemasuser = {
33+
id: 42,
34+
name: "Test User"
35+
};
36+
37+
// Valid: user with email
38+
const userWithEmail: ApiResponseHttpsexamplecomschemasuser = {
39+
id: 42,
40+
name: "Test User",
41+
42+
};
43+
44+
// Valid: metadata object
45+
const metadata: ApiResponseHttpsexamplecomschemasmetadata = {
46+
timestamp: "2024-01-15",
47+
version: 2
48+
};
49+
50+
// Valid: email is just a string
51+
const email: ApiResponseHttpsexamplecomschemasemail = "[email protected]";
52+
53+
// Invalid: missing required field 'data'
54+
// @ts-expect-error - data is required
55+
const missingData: ApiResponse = {
56+
meta: {}
57+
};
58+
59+
// Invalid: missing required field 'meta'
60+
// @ts-expect-error - meta is required
61+
const missingMeta: ApiResponse = {
62+
data: { id: 1, name: "Test" }
63+
};
64+
65+
// Invalid: user missing required 'id'
66+
const userMissingId: ApiResponse = {
67+
// @ts-expect-error - id is required on user
68+
data: {
69+
name: "Test"
70+
},
71+
meta: {}
72+
};
73+
74+
// Invalid: user missing required 'name'
75+
const userMissingName: ApiResponse = {
76+
// @ts-expect-error - name is required on user
77+
data: {
78+
id: 1
79+
},
80+
meta: {}
81+
};
82+
83+
// Invalid: wrong type for user id
84+
const wrongIdType: ApiResponse = {
85+
data: {
86+
// @ts-expect-error - id must be number
87+
id: "not-a-number",
88+
name: "Test"
89+
},
90+
meta: {}
91+
};
92+
93+
// Invalid: extra property on user (additionalProperties: false)
94+
const extraUserProp: ApiResponse = {
95+
data: {
96+
id: 1,
97+
name: "Test",
98+
// @ts-expect-error - extra property not allowed
99+
extra: "not allowed"
100+
},
101+
meta: {}
102+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type SchemaSimpleEnum = "foo" | "bar" | "baz";
2+
3+
export type SchemaMixedEnum = "active" | 42 | true | null;
4+
5+
export type SchemaEnumWithObject = "simple" | {
6+
"type": "complex",
7+
"value": 123
8+
};
9+
10+
export type SchemaEnumWithArray = 1 | [ 1, 2, 3 ];
11+
12+
export type SchemaAdditionalProperties = never;
13+
14+
export interface Schema {
15+
"simpleEnum"?: SchemaSimpleEnum;
16+
"mixedEnum"?: SchemaMixedEnum;
17+
"enumWithObject"?: SchemaEnumWithObject;
18+
"enumWithArray"?: SchemaEnumWithArray;
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"defaultPrefix": "Schema"
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"type": "object",
4+
"properties": {
5+
"simpleEnum": {
6+
"enum": [ "foo", "bar", "baz" ]
7+
},
8+
"mixedEnum": {
9+
"enum": [ "active", 42, true, null ]
10+
},
11+
"enumWithObject": {
12+
"enum": [ "simple", { "type": "complex", "value": 123 } ]
13+
},
14+
"enumWithArray": {
15+
"enum": [ 1, [ 1, 2, 3 ] ]
16+
}
17+
},
18+
"additionalProperties": false
19+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
Schema,
3+
SchemaSimpleEnum,
4+
SchemaMixedEnum,
5+
SchemaEnumWithObject,
6+
SchemaEnumWithArray
7+
} from "./expected";
8+
9+
10+
// Valid: simple string enum values
11+
const simple1: SchemaSimpleEnum = "foo";
12+
const simple2: SchemaSimpleEnum = "bar";
13+
const simple3: SchemaSimpleEnum = "baz";
14+
15+
// Invalid: wrong string for simple enum
16+
// @ts-expect-error - must be "foo" | "bar" | "baz"
17+
const simpleInvalid: SchemaSimpleEnum = "invalid";
18+
19+
// Valid: mixed enum values
20+
const mixed1: SchemaMixedEnum = "active";
21+
const mixed2: SchemaMixedEnum = 42;
22+
const mixed3: SchemaMixedEnum = true;
23+
const mixed4: SchemaMixedEnum = null;
24+
25+
// Invalid: wrong value for mixed enum
26+
// @ts-expect-error - must be "active" | 42 | true | null
27+
const mixedInvalid: SchemaMixedEnum = "inactive";
28+
29+
// Valid: enum with object value
30+
const withObj1: SchemaEnumWithObject = "simple";
31+
const withObj2: SchemaEnumWithObject = { type: "complex", value: 123 };
32+
33+
// Invalid: completely wrong type for enum with object
34+
// @ts-expect-error - must be "simple" or the exact object literal
35+
const withObjInvalid: SchemaEnumWithObject = "wrong";
36+
37+
// Valid: enum with array value
38+
const withArr1: SchemaEnumWithArray = 1;
39+
const withArr2: SchemaEnumWithArray = [ 1, 2, 3 ];
40+
41+
// Invalid: wrong array
42+
// @ts-expect-error - must be exactly [1, 2, 3]
43+
const withArrInvalid: SchemaEnumWithArray = [ 1, 2 ];
44+
45+
// Valid: full schema object
46+
const fullSchema: Schema = {
47+
simpleEnum: "foo",
48+
mixedEnum: 42,
49+
enumWithObject: { type: "complex", value: 123 },
50+
enumWithArray: [ 1, 2, 3 ]
51+
};
52+
53+
// Valid: partial schema
54+
const partialSchema: Schema = {
55+
simpleEnum: "bar"
56+
};
57+
58+
// Valid: empty schema (all optional)
59+
const emptySchema: Schema = {};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type TreeNodeParent = TreeNode;
2+
3+
export type TreeNodeName = string;
4+
5+
export type TreeNodeChildrenItems = TreeNode;
6+
7+
export type TreeNodeChildren = TreeNodeChildrenItems[];
8+
9+
export type TreeNodeAdditionalProperties = never;
10+
11+
export interface TreeNode {
12+
"name": TreeNodeName;
13+
"children"?: TreeNodeChildren;
14+
"parent"?: TreeNodeParent;
15+
}

0 commit comments

Comments
 (0)