Skip to content
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

Merged
merged 18 commits into from
Nov 21, 2019

Conversation

Dhroov7
Copy link
Contributor

@Dhroov7 Dhroov7 commented Nov 6, 2019

Solving #108

@abhijitkane
Copy link
Member

@Dhroov7 Is useExamplesValue an option you're exposing? If so, there needs to be a test for that too.

var prop,
schema = deref.resolveRefs(oldSchema, bodyTypeOption, components);

if (resolveTo === 'schema') {
Copy link
Member

@abhijitkane abhijitkane Nov 19, 2019

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:

  1. Describe what it does
  2. Explain each of the options
  3. 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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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' ||
Copy link
Member

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 Show resolved Hide resolved
lib/util.js Outdated
});
}
catch (e) {
thisOriginalRequest.url.queryParam = {};
Copy link
Member

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 + '&';
Copy link
Member

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

@@ -161,6 +163,43 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});
describe('[Github #108]- Use example values instead of faking schema', function() {
Copy link
Member

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);
Copy link
Member

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));
Copy link
Member

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('&');
Copy link
Member

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) {
Copy link
Member

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

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra var not needed

@abhijitkane abhijitkane merged commit 884ac9f into develop Nov 21, 2019
@umeshp7 umeshp7 deleted the feature/respecting_examples_in_request_body branch January 22, 2020 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants