mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge pull request #487 from postmanlabs/fix10229/falsyExamples
Fix10229/falsy examples
This commit is contained in:
@@ -406,7 +406,7 @@ module.exports = {
|
|||||||
let example = _.get(parameter, 'example'),
|
let example = _.get(parameter, 'example'),
|
||||||
examples = _.values(_.get(parameter, 'examples'));
|
examples = _.values(_.get(parameter, 'examples'));
|
||||||
|
|
||||||
if (example) {
|
if (example !== undefined) {
|
||||||
_.set(parameter, 'schema.example', example);
|
_.set(parameter, 'schema.example', example);
|
||||||
}
|
}
|
||||||
else if (examples) {
|
else if (examples) {
|
||||||
|
|||||||
194
test/data/valid_openapi/issue#10229.json
Normal file
194
test/data/valid_openapi/issue#10229.json
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.1.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "#10229",
|
||||||
|
"license": {
|
||||||
|
"name": "MIT"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "http://petstore.swagger.io/v1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/pets": {
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "http://petstore.swagger.io:{port}/{basePath}",
|
||||||
|
"variables": {
|
||||||
|
"port": {
|
||||||
|
"enum": [
|
||||||
|
"8443",
|
||||||
|
"443"
|
||||||
|
],
|
||||||
|
"default": "8443"
|
||||||
|
},
|
||||||
|
"basePath": {
|
||||||
|
"default": "v2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"get": {
|
||||||
|
"summary": "List all pets",
|
||||||
|
"operationId": "listPets",
|
||||||
|
"tags": [
|
||||||
|
"pets"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query",
|
||||||
|
"description": "How many items to return at one time (max 100)",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
},
|
||||||
|
"example": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "otherString",
|
||||||
|
"in": "query",
|
||||||
|
"description": "other parameter",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"example": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "otherBoolean",
|
||||||
|
"in": "query",
|
||||||
|
"description": "other parameter",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"example": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "A paged array of pets",
|
||||||
|
"headers": {
|
||||||
|
"x-next": {
|
||||||
|
"description": "A link to the next page of responses",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Pets"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"summary": "Create a pet",
|
||||||
|
"operationId": "createPets",
|
||||||
|
"tags": [
|
||||||
|
"pets"
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"a": {
|
||||||
|
"type": "null",
|
||||||
|
"example": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": "Null response"
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "unexpected error",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"a": {
|
||||||
|
"type": "null",
|
||||||
|
"example": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"components": {
|
||||||
|
"schemas": {
|
||||||
|
"Pet": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Pets": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/Pet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Error": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"code",
|
||||||
|
"message"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"code": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,7 +43,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
securityTestCases = path.join(__dirname, VALID_OPENAPI_PATH + '/security-test-cases.yaml'),
|
securityTestCases = path.join(__dirname, VALID_OPENAPI_PATH + '/security-test-cases.yaml'),
|
||||||
emptySecurityTestCase = path.join(__dirname, VALID_OPENAPI_PATH + '/empty-security-test-case.yaml'),
|
emptySecurityTestCase = path.join(__dirname, VALID_OPENAPI_PATH + '/empty-security-test-case.yaml'),
|
||||||
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
|
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
|
||||||
parameterExamples = path.join(__dirname, VALID_OPENAPI_PATH + '/parameteres_with_examples.yaml');
|
parameterExamples = path.join(__dirname, VALID_OPENAPI_PATH + '/parameteres_with_examples.yaml'),
|
||||||
|
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json');
|
||||||
|
|
||||||
|
|
||||||
it('Should add collection level auth with type as `bearer`' +
|
it('Should add collection level auth with type as `bearer`' +
|
||||||
@@ -393,6 +394,25 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('#GITHUB-10229 should generate correct example is out of the schema and is falsy' +
|
||||||
|
issue10229, function(done) {
|
||||||
|
var openapi = fs.readFileSync(issue10229, 'utf8');
|
||||||
|
Converter.convert({ type: 'string', data: openapi }, { requestParametersResolution: 'Example' },
|
||||||
|
(err, conversionResult) => {
|
||||||
|
expect(err).to.be.null;
|
||||||
|
expect(conversionResult.result).to.equal(true);
|
||||||
|
expect(conversionResult.output.length).to.equal(1);
|
||||||
|
expect(conversionResult.output[0].type).to.equal('collection');
|
||||||
|
expect(conversionResult.output[0].data).to.have.property('info');
|
||||||
|
expect(conversionResult.output[0].data).to.have.property('item');
|
||||||
|
expect(conversionResult.output[0].data.item[0].item[0].request.url.query[0].value).to.equal('0');
|
||||||
|
expect(conversionResult.output[0].data.item[0].item[0].request.url.query[1].value).to.equal('');
|
||||||
|
expect(conversionResult.output[0].data.item[0].item[0].request.url.query[2].value).to.equal('false');
|
||||||
|
expect(conversionResult.output[0].data.item[0].item[1].request.body.raw).to.equal('{\n "a": null\n}');
|
||||||
|
expect(conversionResult.output[0].data.item[0].item[1].response[1].body).to.equal('{\n "a": null\n}');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('[Github #108]- Parameters resolution option', function() {
|
describe('[Github #108]- Parameters resolution option', function() {
|
||||||
it('Should respect schema faking for root request and example for example request' +
|
it('Should respect schema faking for root request and example for example request' +
|
||||||
examplesInSchemaSpec, function(done) {
|
examplesInSchemaSpec, function(done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user