Skip to content

Commit eeb57bb

Browse files
committed
test: more complex test cases
1 parent 2690933 commit eeb57bb

File tree

5 files changed

+361
-133
lines changed

5 files changed

+361
-133
lines changed
Lines changed: 98 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,108 @@
11
module.exports = {
22
validateArgs: {
3-
parameters: [],
4-
requestBody: {
5-
description: 'a test body',
6-
content: {
7-
'application/json': {
8-
schema: {
9-
allOf: [
10-
{ $ref: '#/components/schemas/Test1' },
11-
{ $ref: '#/components/schemas/Test2'}
12-
],
13-
},
14-
},
15-
},
16-
},
17-
schemas: {
18-
Test1: {
19-
type: 'object',
20-
required: ['foo'],
21-
properties: {
22-
foo: {
23-
type: 'string',
24-
},
3+
"paths": {
4+
"/pets": {
5+
"patch": {
6+
"requestBody": {
7+
"content": {
8+
"application/json": {
9+
"schema": {
10+
"oneOf": [
11+
{
12+
"$ref": "#/components/schemas/Cat"
13+
},
14+
{
15+
"$ref": "#/components/schemas/Dog"
16+
}
17+
],
18+
"discriminator": {
19+
"propertyName": "pet_type"
20+
}
21+
}
22+
}
23+
}
2524
},
26-
},
27-
Test2: {
28-
type: 'object',
29-
required: ['boo'],
30-
properties: {
31-
boo: {
32-
type: 'string',
33-
},
25+
"responses": {
26+
"200": {
27+
"description": "Updated"
28+
}
29+
}
30+
}
31+
}
32+
},
33+
"components": {
34+
"schemas": {
35+
"Pet": {
36+
"type": "object",
37+
"required": [
38+
"pet_type",
39+
"age",
40+
],
41+
"properties": {
42+
"pet_type": {
43+
"type": "string",
44+
"enum": ["Cat", "Dog"]
45+
},
46+
"age": {
47+
"type": "integer",
48+
}
3449
},
35-
},
50+
},
51+
"Dog": {
52+
"allOf": [
53+
{
54+
"$ref": "#/components/schemas/Pet"
55+
},
56+
{
57+
"type": "object",
58+
"properties": {
59+
"pet_type": {
60+
"type": "string",
61+
"enum": ["Dog"]
62+
},
63+
"bark": {
64+
"type": "boolean"
65+
},
66+
"breed": {
67+
"type": "string",
68+
"enum": [
69+
"Dingo",
70+
"Husky",
71+
"Retriever",
72+
"Shepherd"
73+
]
74+
}
75+
}
76+
}
77+
]
78+
},
79+
"Cat": {
80+
"allOf": [
81+
{
82+
"$ref": "#/components/schemas/Pet"
83+
},
84+
{
85+
"type": "object",
86+
"properties": {
87+
"pet_type": {
88+
"type": "string",
89+
"enum": ["Cat"]
90+
},
91+
"hunts": {
92+
"type": "boolean"
93+
},
94+
}
95+
}
96+
]
97+
}
98+
}
99+
}
36100
},
37-
},
38101
request: {
39102
body: {
40-
foo: 'hello',
41-
boo: 'world',
103+
"pet_type": "Cat",
104+
"age": 3,
105+
"hunts": true
42106
},
43107
},
44108
};
Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,76 @@
11
module.exports = {
22
validateArgs: {
3-
parameters: [],
4-
requestBody: {
5-
description: 'a test body',
6-
content: {
7-
'application/json': {
8-
schema: {
9-
oneOf: [
10-
{ $ref: '#/components/schemas/Test1' },
11-
{ $ref: '#/components/schemas/Test2'}
12-
],
3+
"paths": {
4+
"/pets": {
5+
"patch": {
6+
"requestBody": {
7+
"content": {
8+
"application/json": {
9+
"schema": {
10+
"anyOf": [
11+
{
12+
"$ref": "#/components/schemas/PetByAge"
13+
},
14+
{
15+
"$ref": "#/components/schemas/PetByType"
16+
}
17+
]
18+
}
19+
}
20+
}
21+
},
22+
"responses": {
23+
"200": {
24+
"description": "Updated"
25+
}
26+
}
27+
}
28+
}
29+
},
30+
"components": {
31+
"schemas": {
32+
"PetByAge": {
33+
"type": "object",
34+
"additionalProperties": true,
35+
"properties": {
36+
"age": {
37+
"type": "integer"
1338
},
39+
"nickname": {
40+
"type": "string"
41+
}
1442
},
43+
"required": [
44+
"age"
45+
]
1546
},
16-
},
17-
schemas: {
18-
Test1: {
19-
type: 'object',
20-
required: ['foo'],
21-
properties: {
22-
foo: {
23-
type: 'string',
24-
},
25-
},
26-
},
27-
Test2: {
28-
type: 'object',
29-
required: ['boo'],
30-
properties: {
31-
boo: {
32-
type: 'string',
33-
},
34-
},
47+
"PetByType": {
48+
"type": "object",
49+
"additionalProperties": true,
50+
"properties": {
51+
"pet_type": {
52+
"type": "string",
53+
"enum": [
54+
"Cat",
55+
"Dog"
56+
]
57+
},
58+
"hunts": {
59+
"type": "boolean"
60+
}
3561
},
36-
},
62+
"required": [
63+
"pet_type"
64+
]
65+
}
66+
}
67+
}
3768
},
3869
request: {
3970
body: {
40-
boo: 'world',
71+
"nickname": "Fido",
72+
"pet_type": "Dog",
73+
"age": 4
4174
},
4275
},
4376
};

0 commit comments

Comments
 (0)