Skip to content

Commit c406183

Browse files
authored
Merge pull request #768 from postmanlabs/feature/multi-example-support
Added support for multiple examples to be generated as request examples.
2 parents d764b53 + bece53a commit c406183

8 files changed

+814
-134
lines changed

libV2/schemaUtils.js

Lines changed: 399 additions & 125 deletions
Large diffs are not rendered by default.

test/data/valid_openapi/custom_headers.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
"type": "integer",
1717
"format": "int32"
1818
}
19-
},
20-
"application/vnd.retailer.v3+json": {
21-
"schema": {
22-
"type": "integer",
23-
"format": "int32"
24-
}
2519
}
2620
}
2721
}
@@ -34,4 +28,4 @@
3428
"url": "https://api.com"
3529
}
3630
]
37-
}
31+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
openapi: 3.0.0
2+
info:
3+
title: None
4+
version: 1.0.0
5+
description: None
6+
paths:
7+
/v1:
8+
post:
9+
requestBody:
10+
content:
11+
'application/json':
12+
schema:
13+
$ref: "#/components/schemas/World"
14+
examples:
15+
valid-request:
16+
value:
17+
includedFields:
18+
- user
19+
- height
20+
- weight
21+
missing-required-parameter:
22+
value:
23+
includedFields:
24+
- user
25+
responses:
26+
200:
27+
description: None
28+
content:
29+
'application/json':
30+
schema:
31+
$ref: "#/components/schemas/Request"
32+
examples:
33+
valid-request:
34+
summary: Complete request
35+
value:
36+
{
37+
"user": 1,
38+
"height": 168,
39+
"weight": 44
40+
}
41+
missing-required-parameter:
42+
summary: Request with only required params
43+
value:
44+
{
45+
"user": 1
46+
}
47+
components:
48+
schemas:
49+
World:
50+
type: object
51+
properties:
52+
includedFields:
53+
type: array
54+
Request:
55+
type: object
56+
required:
57+
- user
58+
- height
59+
- weight
60+
properties:
61+
user:
62+
type: integer
63+
description: None
64+
height:
65+
type: integer
66+
description: None
67+
weight:
68+
type: integer
69+
description: None
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
openapi: 3.0.0
2+
info:
3+
title: None
4+
version: 1.0.0
5+
description: None
6+
paths:
7+
/v1/:
8+
post:
9+
requestBody:
10+
content:
11+
'application/json':
12+
schema:
13+
$ref: "#/components/schemas/Request"
14+
examples:
15+
valid-request:
16+
value:
17+
{
18+
"user": 1,
19+
"height": 168,
20+
"weight": 44
21+
}
22+
missing-required-parameter:
23+
value:
24+
{
25+
"user": 1
26+
}
27+
responses:
28+
200:
29+
description: None
30+
content:
31+
'application/json':
32+
example: { hello: 'world' }
33+
components:
34+
schemas:
35+
Request:
36+
type: object
37+
required:
38+
- user
39+
- height
40+
- weight
41+
properties:
42+
user:
43+
type: integer
44+
description: None
45+
height:
46+
type: integer
47+
description: None
48+
weight:
49+
type: integer
50+
description: None
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
openapi: 3.0.0
2+
info:
3+
title: None
4+
version: 1.0.0
5+
description: None
6+
paths:
7+
/v1:
8+
post:
9+
requestBody:
10+
content:
11+
'application/json':
12+
schema:
13+
$ref: "#/components/schemas/World"
14+
examples:
15+
valid-request:
16+
value:
17+
includedFields:
18+
- user
19+
- height
20+
- weight
21+
missing-required-parameter:
22+
value:
23+
includedFields:
24+
- user
25+
responses:
26+
200:
27+
description: None
28+
content:
29+
'application/json':
30+
schema:
31+
$ref: "#/components/schemas/Request"
32+
examples:
33+
not-matching-key:
34+
summary: Request with only required params
35+
value:
36+
{
37+
"user": 1
38+
}
39+
not-matching-key-2:
40+
summary: Complete request
41+
value:
42+
{
43+
"user": 1,
44+
"height": 168,
45+
"weight": 44
46+
}
47+
48+
components:
49+
schemas:
50+
World:
51+
type: object
52+
properties:
53+
includedFields:
54+
type: array
55+
Request:
56+
type: object
57+
required:
58+
- user
59+
- height
60+
- weight
61+
properties:
62+
user:
63+
type: integer
64+
description: None
65+
height:
66+
type: integer
67+
description: None
68+
weight:
69+
type: integer
70+
description: None
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
openapi: 3.0.0
2+
info:
3+
title: None
4+
version: 1.0.0
5+
description: None
6+
paths:
7+
/v1:
8+
post:
9+
requestBody:
10+
content:
11+
'application/json':
12+
schema:
13+
$ref: "#/components/schemas/World"
14+
examples:
15+
hello-world:
16+
value:
17+
hello: world
18+
responses:
19+
200:
20+
description: None
21+
content:
22+
'application/json':
23+
schema:
24+
$ref: "#/components/schemas/Request"
25+
examples:
26+
valid-request:
27+
value:
28+
{
29+
"user": 1,
30+
"height": 168,
31+
"weight": 44
32+
}
33+
missing-required-parameter:
34+
value:
35+
{
36+
"user": 1
37+
}
38+
components:
39+
schemas:
40+
World:
41+
type: object
42+
properties:
43+
hello:
44+
type: string
45+
Request:
46+
type: object
47+
required:
48+
- user
49+
- height
50+
- weight
51+
properties:
52+
user:
53+
type: integer
54+
description: None
55+
height:
56+
type: integer
57+
description: None
58+
weight:
59+
type: integer
60+
description: None

test/unit/base.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
371371
Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
372372
expect(err).to.be.null;
373373
expect(conversionResult.output[0].data.item[0].response[0].header[0].value)
374-
.to.equal('application/vnd.retailer.v3+json');
374+
.to.equal('application/vnd.retailer.v3+xml');
375375
done();
376376
});
377377
});

0 commit comments

Comments
 (0)