Skip to content

Commit 808eefc

Browse files
authored
Merge pull request #573 from postmanlabs/fix/518-enumFakedAsNaN
Fix #518 integer query params with enum values get default value of NaN
2 parents 5b0ff9c + 242a696 commit 808eefc

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
5151
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
5252
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
5353
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'),
5456
formDataParamDescription = path.join(__dirname, VALID_OPENAPI_PATH, '/form_data_param_description.yaml'),
5557
allHTTPMethodsSpec = path.join(__dirname, VALID_OPENAPI_PATH, '/all-http-methods.yaml');
5658

@@ -1144,6 +1146,23 @@ describe('CONVERT FUNCTION TESTS ', function() {
11441146
});
11451147
});
11461148

1149+
it('[Github #518]- integer query params with enum values get default value of NaN' +
1150+
descriptionInBodyParams, function(done) {
1151+
var openapi = fs.readFileSync(queryParamWithEnumResolveAsExample, 'utf8');
1152+
Converter.convert({
1153+
type: 'string',
1154+
data: openapi
1155+
}, {
1156+
schemaFaker: true,
1157+
requestParametersResolution: 'Example'
1158+
}, (err, conversionResult) => {
1159+
let fakedParam = conversionResult.output[0].data.item[0].request.url.query[0].value;
1160+
expect(err).to.be.null;
1161+
expect(fakedParam).to.be.equal('120');
1162+
done();
1163+
});
1164+
});
1165+
11471166
it('[Github #559]Should convert description in form data parameters' +
11481167
petstoreParamExample, function(done) {
11491168
var openapi = fs.readFileSync(formDataParamDescription, 'utf8');

0 commit comments

Comments
 (0)