Skip to content

Commit 7f6de44

Browse files
committed
test(parser): implementing testing for the new patternProperties keyword
1 parent e2823f5 commit 7f6de44

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed

.changeset/two-humans-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
Handle patternProperties keyword added in OpenAPI 3.1

packages/openapi-ts-tests/main/test/3.1.x.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe(`OpenAPI ${version}`, () => {
4444
};
4545

4646
const scenarios = [
47+
{
48+
config: createConfig({
49+
input: 'pattern-properties.json',
50+
output: 'pattern-properties',
51+
}),
52+
description: 'handles pattern properties',
53+
},
4754
{
4855
config: createConfig({
4956
input: 'additional-properties-false.json',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type PatternPropertiesTest = {
4+
id?: string;
5+
metadata?: MetadataObject;
6+
};
7+
8+
export type MetadataObject = {
9+
name?: string;
10+
description?: string;
11+
[key: string]: Array<string> | string | {
12+
value?: string;
13+
enabled?: boolean;
14+
} | undefined;
15+
};
16+
17+
export type NestedPatternObject = {
18+
base?: string;
19+
[key: string]: {
20+
[key: string]: string;
21+
} | string | undefined;
22+
};
23+
24+
export type UnionPatternObject = {
25+
type?: 'user' | 'admin' | 'guest';
26+
[key: string]: ({
27+
[key: string]: unknown;
28+
} & {
29+
level?: number;
30+
}) | (string | number) | ('user' | 'admin' | 'guest') | undefined;
31+
};
32+
33+
export type PatternPropertiesResponse = {
34+
success?: boolean;
35+
data?: MetadataObject;
36+
};
37+
38+
export type PostPatternTestData = {
39+
body: PatternPropertiesTest;
40+
path?: never;
41+
query?: never;
42+
url: '/pattern-test';
43+
};
44+
45+
export type PostPatternTestResponses = {
46+
/**
47+
* Success
48+
*/
49+
200: PatternPropertiesResponse;
50+
};
51+
52+
export type PostPatternTestResponse = PostPatternTestResponses[keyof PostPatternTestResponses];
53+
54+
export type ClientOptions = {
55+
baseUrl: `${string}://${string}` | (string & {});
56+
};
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "OpenAPI 3.1.0 pattern properties example",
5+
"version": "1"
6+
},
7+
"paths": {
8+
"/pattern-test": {
9+
"post": {
10+
"summary": "Test pattern properties",
11+
"requestBody": {
12+
"required": true,
13+
"content": {
14+
"application/json": {
15+
"schema": {
16+
"$ref": "#/components/schemas/PatternPropertiesTest"
17+
}
18+
}
19+
}
20+
},
21+
"responses": {
22+
"200": {
23+
"description": "Success",
24+
"content": {
25+
"application/json": {
26+
"schema": {
27+
"$ref": "#/components/schemas/PatternPropertiesResponse"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components": {
37+
"schemas": {
38+
"PatternPropertiesTest": {
39+
"type": "object",
40+
"properties": {
41+
"id": {
42+
"type": "string"
43+
},
44+
"metadata": {
45+
"$ref": "#/components/schemas/MetadataObject"
46+
}
47+
},
48+
"additionalProperties": false
49+
},
50+
"MetadataObject": {
51+
"type": "object",
52+
"properties": {
53+
"name": {
54+
"type": "string"
55+
},
56+
"description": {
57+
"type": "string"
58+
}
59+
},
60+
"patternProperties": {
61+
"^meta_": {
62+
"type": "string",
63+
"description": "Any property starting with 'meta_' must be a string"
64+
},
65+
"^config_": {
66+
"type": "object",
67+
"properties": {
68+
"value": {
69+
"type": "string"
70+
},
71+
"enabled": {
72+
"type": "boolean"
73+
}
74+
},
75+
"additionalProperties": false
76+
},
77+
"^tag_[a-zA-Z0-9_]+$": {
78+
"type": "string",
79+
"description": "Tag properties must match pattern and be strings"
80+
},
81+
"^[0-9]+_item$": {
82+
"type": "array",
83+
"items": {
84+
"type": "string"
85+
},
86+
"description": "Numbered item properties must be arrays of strings"
87+
}
88+
},
89+
"additionalProperties": false
90+
},
91+
"NestedPatternObject": {
92+
"type": "object",
93+
"properties": {
94+
"base": {
95+
"type": "string"
96+
}
97+
},
98+
"patternProperties": {
99+
"^nested_": {
100+
"type": "object",
101+
"patternProperties": {
102+
"^sub_": {
103+
"type": "string"
104+
}
105+
},
106+
"additionalProperties": false
107+
}
108+
},
109+
"additionalProperties": false
110+
},
111+
"UnionPatternObject": {
112+
"type": "object",
113+
"properties": {
114+
"type": {
115+
"type": "string",
116+
"enum": ["user", "admin", "guest"]
117+
}
118+
},
119+
"patternProperties": {
120+
"^user_": {
121+
"oneOf": [
122+
{
123+
"type": "string"
124+
},
125+
{
126+
"type": "number"
127+
}
128+
]
129+
},
130+
"^admin_": {
131+
"allOf": [
132+
{
133+
"type": "object"
134+
},
135+
{
136+
"properties": {
137+
"level": {
138+
"type": "number",
139+
"minimum": 1,
140+
"maximum": 10
141+
}
142+
}
143+
}
144+
]
145+
}
146+
},
147+
"additionalProperties": false
148+
},
149+
"PatternPropertiesResponse": {
150+
"type": "object",
151+
"properties": {
152+
"success": {
153+
"type": "boolean"
154+
},
155+
"data": {
156+
"$ref": "#/components/schemas/MetadataObject"
157+
}
158+
},
159+
"additionalProperties": false
160+
}
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)