mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
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:
@@ -23782,7 +23782,7 @@ function extend() {
|
|||||||
var min = Math.max(params.minimum || 0, 0);
|
var min = Math.max(params.minimum || 0, 0);
|
||||||
var max = Math.min(params.maximum || Infinity, Infinity);
|
var max = Math.min(params.maximum || Infinity, Infinity);
|
||||||
min = handleExclusiveMinimum(schema, min);
|
min = handleExclusiveMinimum(schema, min);
|
||||||
max = handleExclusiveMaximum(schema, min);
|
max = handleExclusiveMaximum(schema, max);
|
||||||
// discard out-of-bounds enumerations
|
// discard out-of-bounds enumerations
|
||||||
schema.enum = schema.enum.filter(function (x) {
|
schema.enum = schema.enum.filter(function (x) {
|
||||||
if (x >= min && x <= max) {
|
if (x >= min && x <= max) {
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,8 +50,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
|
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
|
||||||
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
|
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
|
||||||
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.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`' +
|
it('Should add collection level auth with type as `bearer`' +
|
||||||
securityTestCases, function(done) {
|
securityTestCases, function(done) {
|
||||||
@@ -1141,6 +1142,23 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
done();
|
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() {
|
describe('Converting swagger 2.0 files', function() {
|
||||||
it('should convert path paramters to postman-compatible paramters', function (done) {
|
it('should convert path paramters to postman-compatible paramters', function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user