Skip to content

Commit 04b44f2

Browse files
committed
Fix #518 integer query params with enum values get default value of NaN
Fixes: #518 Resolve parameters correctly when requestParametersResolution is set as 'Example' and the schema contains an enum value
1 parent 6df66da commit 04b44f2

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

assets/json-schema-faker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23782,7 +23782,7 @@ function extend() {
2378223782
var min = Math.max(params.minimum || 0, 0);
2378323783
var max = Math.min(params.maximum || Infinity, Infinity);
2378423784
min = handleExclusiveMinimum(schema, min);
23785-
max = handleExclusiveMaximum(schema, min);
23785+
max = handleExclusiveMaximum(schema, max);
2378623786
// discard out-of-bounds enumerations
2378723787
schema.enum = schema.enum.filter(function (x) {
2378823788
if (x >= min && x <= max) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/foo": {
17+
"get": {
18+
"parameters": [
19+
{
20+
"name": "foo",
21+
"in": "query",
22+
"required": true,
23+
"schema": {
24+
"type": "integer",
25+
"enum": [120]
26+
}
27+
}
28+
],
29+
"responses": {}
30+
}
31+
}
32+
},
33+
"components": {
34+
"schemas": {
35+
"Pet": {
36+
"type": "object",
37+
"properties": {
38+
"id": {
39+
"type": "integer",
40+
"format": "int64",
41+
"description": "Description of Pet ID"
42+
},
43+
"name": {
44+
"type": "string",
45+
"description": "Description of Pet name"
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}

test/unit/base.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
5050
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
5151
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
5252
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
53-
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml');
54-
53+
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
54+
queryParamWithEnumResolveAsExample =
55+
path.join(__dirname, VALID_OPENAPI_PATH, '/query_param_with_enum_resolve_as_example.json');
5556

5657
it('Should add collection level auth with type as `bearer`' +
5758
securityTestCases, function(done) {
@@ -1141,6 +1142,23 @@ describe('CONVERT FUNCTION TESTS ', function() {
11411142
done();
11421143
});
11431144
});
1145+
1146+
it('[Github #518]- integer query params with enum values get default value of NaN' +
1147+
descriptionInBodyParams, function(done) {
1148+
var openapi = fs.readFileSync(queryParamWithEnumResolveAsExample, 'utf8');
1149+
Converter.convert({
1150+
type: 'string',
1151+
data: openapi
1152+
}, {
1153+
schemaFaker: true,
1154+
requestParametersResolution: 'Example'
1155+
}, (err, conversionResult) => {
1156+
let fakedParam = conversionResult.output[0].data.item[0].request.url.query[0].value;
1157+
expect(err).to.be.null;
1158+
expect(fakedParam).to.be.equal('120');
1159+
done();
1160+
});
1161+
});
11441162
});
11451163
describe('Converting swagger 2.0 files', function() {
11461164
it('should convert path paramters to postman-compatible paramters', function (done) {

0 commit comments

Comments
 (0)