mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Delete bad imp of value prop
Delete bad imp of value prop
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
* utils.js contains other util functions
|
||||
*/
|
||||
|
||||
const { formatDataPath, checkIsCorrectType, isKnownType,
|
||||
formatSchemaPathFromAJVErrorToConvertToDataPath } = require('./common/schemaUtilsCommon.js'),
|
||||
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
|
||||
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
|
||||
async = require('async'),
|
||||
sdk = require('postman-collection'),
|
||||
@@ -1364,39 +1363,6 @@ module.exports = {
|
||||
return example;
|
||||
},
|
||||
|
||||
/**
|
||||
* Identifies if the example.value should be used as value of the body
|
||||
* This is needed because there are cases that the example object has a property
|
||||
* called value like: example = { id: 1, value: "someValue" }
|
||||
* In this case the body value should be the whole example object and not the property called value
|
||||
* The property value belongs to the example object not the example OAS spec property
|
||||
* @param {*} schema bodyObject (media type) schema to use
|
||||
* @param {*} example - Exampel took from the bodyObject
|
||||
* @param {object} components - components defined in the OAS spec.
|
||||
* @returns {boolean} Wheter to use the property value of the example as the value of the
|
||||
* body data
|
||||
*/
|
||||
useExampleValuePropAsValue(schema, example, components) {
|
||||
let schemaProperties = [],
|
||||
schemaObject,
|
||||
schemaDataPath = '',
|
||||
exampleProperties = [];
|
||||
if (!schema) {
|
||||
return true;
|
||||
}
|
||||
if (schema.$ref) {
|
||||
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(schema.$ref));
|
||||
schemaObject = _.get(components, schemaDataPath);
|
||||
}
|
||||
else {
|
||||
schemaObject = schema;
|
||||
}
|
||||
|
||||
schemaProperties = Object.keys(schemaObject.properties).sort();
|
||||
exampleProperties = Object.keys(example.value).sort();
|
||||
return JSON.stringify(schemaProperties) === JSON.stringify(exampleProperties);
|
||||
},
|
||||
|
||||
/**
|
||||
* converts one of the eamples or schema in Media Type object to postman data
|
||||
* @param {*} bodyObj is MediaTypeObject
|
||||
@@ -1447,8 +1413,7 @@ module.exports = {
|
||||
}
|
||||
bodyData = bodyObj.example;
|
||||
// return example value if present else example is returned
|
||||
if (bodyData.hasOwnProperty('value') &&
|
||||
this.useExampleValuePropAsValue(bodyObj.schema, bodyObj.example, components)) {
|
||||
if (bodyData.hasOwnProperty('value')) {
|
||||
bodyData = bodyData.value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
version: '1.1.1'
|
||||
title: 'ExampleYaml'
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: 'localhost:3000'
|
||||
paths:
|
||||
/user:
|
||||
get:
|
||||
summary: 'Sample endpoint: Returns details about a particular user'
|
||||
operationId: listUser
|
||||
tags:
|
||||
- user
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
description: ID of the user
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: 'Sample response: Details about a user by ID'
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/User'
|
||||
example:
|
||||
id: "5789-6378-6372-6372"
|
||||
name: Vani
|
||||
tag: true
|
||||
value: QA
|
||||
lastmodifieddate: "2022-03-30T07:01:46"
|
||||
lastmodifiedBy: VM
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
/pet:
|
||||
get:
|
||||
summary: 'Sample endpoint: Returns details about a particular pet'
|
||||
operationId: listPet
|
||||
tags:
|
||||
- pet
|
||||
parameters:
|
||||
- name: id
|
||||
in: query
|
||||
description: ID of the pet
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: 'Sample response: Details about a pet by ID'
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
value:
|
||||
type: string
|
||||
example:
|
||||
id: "5789-6378-6372-6372"
|
||||
value: QA
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
components:
|
||||
schemas:
|
||||
User:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- tag
|
||||
- value
|
||||
- lastmodifieddate
|
||||
- lastmodifiedBy
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
lastmodifieddate:
|
||||
type: integer
|
||||
format: int64
|
||||
lastmodifiedBy:
|
||||
type: string
|
||||
Error:
|
||||
type: object
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
securitySchemes:
|
||||
BasicAuth:
|
||||
type: http
|
||||
scheme: basic
|
||||
security:
|
||||
- BasicAuth: []
|
||||
@@ -48,8 +48,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
||||
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
|
||||
parameterExamples = path.join(__dirname, VALID_OPENAPI_PATH + '/parameteres_with_examples.yaml'),
|
||||
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');
|
||||
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml');
|
||||
|
||||
|
||||
it('Should add collection level auth with type as `bearer`' +
|
||||
@@ -1112,21 +1111,6 @@ describe('CONVERT FUNCTION TESTS ', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('[Github #10752]: Should convert value property in example' +
|
||||
valuePropInExample, function(done) {
|
||||
var openapi = fs.readFileSync(valuePropInExample, 'utf8');
|
||||
Converter.convert({ type: 'string', data: openapi },
|
||||
{ schemaFaker: true, requestParametersResolution: 'Example' }, (err, conversionResult) => {
|
||||
expect(err).to.be.null;
|
||||
expect(conversionResult.result).to.equal(true);
|
||||
expect(conversionResult.output[0].data.item[0].response[0]
|
||||
.body).to.include('"value": "QA"');
|
||||
expect(conversionResult.output[0].data.item[1].response[0]
|
||||
.body).to.include('"value": "QA"');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('Converting swagger 2.0 files', function() {
|
||||
it('should convert path paramters to postman-compatible paramters', function (done) {
|
||||
|
||||
Reference in New Issue
Block a user