-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using example values instead of faking schema #125
using example values instead of faking schema #125
Conversation
@Dhroov7 Is useExamplesValue an option you're exposing? If so, there needs to be a test for that too. |
…openapi-to-postman into feature/respecting_examples_in_request_body
…ostman into feature/respecting_examples_in_request_body
var prop, | ||
schema = deref.resolveRefs(oldSchema, bodyTypeOption, components); | ||
|
||
if (resolveTo === 'schema') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the copy for the jsdoc descriptions. tells to
is incorrect. Every enum option should:
- Describe what it does
- Explain each of the options
- Mention the default
@param {string} resolveTo The desired JSON-generation mechanism (schema: prefer using the JSONschema to generate a fake object, example: use specified examples as-is). Default: schema
Even the desc for bodyTypeOption doesn't read well. Specifies whether the schema being faked is from a request or response.
. Also, explain how this affects the output.
lib/util.js
Outdated
if (requestType === REQUEST_TYPE.ROOT) { | ||
resolveTo = this.options.requestParametersResolution; | ||
} | ||
else if (requestType === REQUEST_TYPE.EXAMPLE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else?
is there a default? what happens if I send something other than root/example to the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of resolveTo
is an empty string which means if I send something other than root/example then the JSON-schema-faker
will fake the schema properties instead of using examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default value of resolveTo should be schema
or example
. Why do we have a blank string?
lib/util.js
Outdated
|
||
if (bodyObj.example) { | ||
if (bodyObj.example && (this.options.requestParametersResolution === 'example' || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simplified a bit? This is in direct violation of item #5 in the code
section of our internal guidelines
lib/util.js
Outdated
}); | ||
} | ||
catch (e) { | ||
thisOriginalRequest.url.queryParam = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exceptions do you expect?
lib/util.js
Outdated
thisOriginalRequest.url += '?'; | ||
_.forEach(reqParams.query, (queryParam) => { | ||
this.convertToPmQueryParameters(queryParam, REQUEST_TYPE.EXAMPLE).forEach((pmParam) => { | ||
thisOriginalRequest.url += pmParam.key + '=' + pmParam.value + '&'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this lead to an extra &
in the end? prefer _.map + _.join
test/unit/base.test.js
Outdated
@@ -161,6 +163,43 @@ describe('CONVERT FUNCTION TESTS ', function() { | |||
done(); | |||
}); | |||
}); | |||
describe('[Github #108]- Use example values instead of faking schema', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Violation of #4 in the basic
section of our internal code guidelines
lib/util.js
Outdated
|
||
if (header.hasOwnProperty('schema')) { | ||
if (!this.options.schemaFaker) { | ||
fakeData = ''; | ||
} | ||
else { | ||
fakeData = safeSchemaFaker(header.schema || {}, this.components, SCHEMA_FORMATS.DEFAULT); | ||
fakeData = safeSchemaFaker(header.schema || {}, resolveTo, '', this.components, SCHEMA_FORMATS.DEFAULT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the request/response-ness should be passed here
parameterSource, maybe?
lib/util.js
Outdated
@@ -1109,7 +1167,7 @@ module.exports = { | |||
encoding[key].headers[key] = getRefObject(encoding[key].headers[key].$ref); | |||
} | |||
encoding[key].headers[key].name = key; | |||
formHeaders.push(this.convertToPmHeader(encoding[key].headers[key])); | |||
formHeaders.push(this.convertToPmHeader(encoding[key].headers[key], REQUEST_TYPE.ROOT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment explaining the hard-coded value
lib/util.js
Outdated
this.convertToPmQueryParameters(queryParam, REQUEST_TYPE.EXAMPLE).forEach((pmParam) => { | ||
requestQueryParams.push(pmParam.key + '=' + pmParam.value); | ||
}); | ||
thisOriginalRequest.url += requestQueryParams.join('&'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs testing
lib/util.js
Outdated
* @param {*} reqParams openapi query params object | ||
* @returns {*} array of all query params | ||
*/ | ||
setQueryParamsToUrl: function(reqParams) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.example shouldn't be hard-coded here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrectly named
lib/util.js
Outdated
@@ -1475,15 +1541,27 @@ module.exports = { | |||
thisOriginalRequest.url = ''; | |||
} | |||
try { | |||
thisOriginalRequest.header = item.request.headers.toJSON(); | |||
thisOriginalRequest.url += '?'; | |||
requestQueryParams = this.setQueryParamsToUrl(reqParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra var not needed
Solving #108