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
This commit is contained in:
Erik Mendoza
2022-06-27 16:07:32 -05:00
parent 6df66da0d6
commit 04b44f297a
3 changed files with 72 additions and 3 deletions

View File

@@ -23782,7 +23782,7 @@ function extend() {
var min = Math.max(params.minimum || 0, 0);
var max = Math.min(params.maximum || Infinity, Infinity);
min = handleExclusiveMinimum(schema, min);
max = handleExclusiveMaximum(schema, min);
max = handleExclusiveMaximum(schema, max);
// discard out-of-bounds enumerations
schema.enum = schema.enum.filter(function (x) {
if (x >= min && x <= max) {

View File

@@ -0,0 +1,51 @@
{
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/v1"
}
],
"paths": {
"/foo": {
"get": {
"parameters": [
{
"name": "foo",
"in": "query",
"required": true,
"schema": {
"type": "integer",
"enum": [120]
}
}
],
"responses": {}
}
}
},
"components": {
"schemas": {
"Pet": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": "Description of Pet ID"
},
"name": {
"type": "string",
"description": "Description of Pet name"
}
}
}
}
}
}

View File

@@ -50,8 +50,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml');
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
queryParamWithEnumResolveAsExample =
path.join(__dirname, VALID_OPENAPI_PATH, '/query_param_with_enum_resolve_as_example.json');
it('Should add collection level auth with type as `bearer`' +
securityTestCases, function(done) {
@@ -1141,6 +1142,23 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});
it('[Github #518]- integer query params with enum values get default value of NaN' +
descriptionInBodyParams, function(done) {
var openapi = fs.readFileSync(queryParamWithEnumResolveAsExample, 'utf8');
Converter.convert({
type: 'string',
data: openapi
}, {
schemaFaker: true,
requestParametersResolution: 'Example'
}, (err, conversionResult) => {
let fakedParam = conversionResult.output[0].data.item[0].request.url.query[0].value;
expect(err).to.be.null;
expect(fakedParam).to.be.equal('120');
done();
});
});
});
describe('Converting swagger 2.0 files', function() {
it('should convert path paramters to postman-compatible paramters', function (done) {