Skip to content

Commit

Permalink
Merge pull request #768 from postmanlabs/feature/multi-example-support
Browse files Browse the repository at this point in the history
Added support for multiple examples to be generated as request examples.
  • Loading branch information
VShingala committed Sep 28, 2023
2 parents d764b53 + bece53a commit c406183
Show file tree
Hide file tree
Showing 8 changed files with 814 additions and 134 deletions.
524 changes: 399 additions & 125 deletions libV2/schemaUtils.js

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions test/data/valid_openapi/custom_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
"type": "integer",
"format": "int32"
}
},
"application/vnd.retailer.v3+json": {
"schema": {
"type": "integer",
"format": "int32"
}
}
}
}
Expand All @@ -34,4 +28,4 @@
"url": "https://api.com"
}
]
}
}
69 changes: 69 additions & 0 deletions test/data/valid_openapi/multiExampleMatchingRequestResponse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
openapi: 3.0.0
info:
title: None
version: 1.0.0
description: None
paths:
/v1:
post:
requestBody:
content:
'application/json':
schema:
$ref: "#/components/schemas/World"
examples:
valid-request:
value:
includedFields:
- user
- height
- weight
missing-required-parameter:
value:
includedFields:
- user
responses:
200:
description: None
content:
'application/json':
schema:
$ref: "#/components/schemas/Request"
examples:
valid-request:
summary: Complete request
value:
{
"user": 1,
"height": 168,
"weight": 44
}
missing-required-parameter:
summary: Request with only required params
value:
{
"user": 1
}
components:
schemas:
World:
type: object
properties:
includedFields:
type: array
Request:
type: object
required:
- user
- height
- weight
properties:
user:
type: integer
description: None
height:
type: integer
description: None
weight:
type: integer
description: None
50 changes: 50 additions & 0 deletions test/data/valid_openapi/multiExampleRequest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
openapi: 3.0.0
info:
title: None
version: 1.0.0
description: None
paths:
/v1/:
post:
requestBody:
content:
'application/json':
schema:
$ref: "#/components/schemas/Request"
examples:
valid-request:
value:
{
"user": 1,
"height": 168,
"weight": 44
}
missing-required-parameter:
value:
{
"user": 1
}
responses:
200:
description: None
content:
'application/json':
example: { hello: 'world' }
components:
schemas:
Request:
type: object
required:
- user
- height
- weight
properties:
user:
type: integer
description: None
height:
type: integer
description: None
weight:
type: integer
description: None
70 changes: 70 additions & 0 deletions test/data/valid_openapi/multiExampleRequestResponse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
openapi: 3.0.0
info:
title: None
version: 1.0.0
description: None
paths:
/v1:
post:
requestBody:
content:
'application/json':
schema:
$ref: "#/components/schemas/World"
examples:
valid-request:
value:
includedFields:
- user
- height
- weight
missing-required-parameter:
value:
includedFields:
- user
responses:
200:
description: None
content:
'application/json':
schema:
$ref: "#/components/schemas/Request"
examples:
not-matching-key:
summary: Request with only required params
value:
{
"user": 1
}
not-matching-key-2:
summary: Complete request
value:
{
"user": 1,
"height": 168,
"weight": 44
}

components:
schemas:
World:
type: object
properties:
includedFields:
type: array
Request:
type: object
required:
- user
- height
- weight
properties:
user:
type: integer
description: None
height:
type: integer
description: None
weight:
type: integer
description: None
60 changes: 60 additions & 0 deletions test/data/valid_openapi/multiExampleResponse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
openapi: 3.0.0
info:
title: None
version: 1.0.0
description: None
paths:
/v1:
post:
requestBody:
content:
'application/json':
schema:
$ref: "#/components/schemas/World"
examples:
hello-world:
value:
hello: world
responses:
200:
description: None
content:
'application/json':
schema:
$ref: "#/components/schemas/Request"
examples:
valid-request:
value:
{
"user": 1,
"height": 168,
"weight": 44
}
missing-required-parameter:
value:
{
"user": 1
}
components:
schemas:
World:
type: object
properties:
hello:
type: string
Request:
type: object
required:
- user
- height
- weight
properties:
user:
type: integer
description: None
height:
type: integer
description: None
weight:
type: integer
description: None
2 changes: 1 addition & 1 deletion test/unit/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
Converter.convert({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
expect(err).to.be.null;
expect(conversionResult.output[0].data.item[0].response[0].header[0].value)
.to.equal('application/vnd.retailer.v3+json');
.to.equal('application/vnd.retailer.v3+xml');
done();
});
});
Expand Down
Loading

0 comments on commit c406183

Please sign in to comment.