-
Notifications
You must be signed in to change notification settings - Fork 206
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
[AB-290]-Extracting-type-information from OAS #834
Conversation
libV2/index.js
Outdated
@@ -91,16 +92,19 @@ module.exports = { | |||
// generate the request form the node | |||
let request = {}, | |||
collectionVariables = [], | |||
requestObject = {}; | |||
requestObject = {}, | |||
extractedTypesObject = {}; |
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.
P2: Can we name the variable typesObject
instead of extracted types object ?
libV2/schemaUtils.js
Outdated
if (requiredProperties.has(key) || parentRequired.has(key)) { | ||
schemaDetails.required.push(key); | ||
} | ||
if (prop.$ref) { |
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.
Where are we dereferencing this ? I can see we're calling processSchema
again in this case, but this function doesn't seems to handle ref
anywhere else. Am I missing something 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.
my bad, this is not required as the $ref would be already resolved by resolvedSchema.
libV2/schemaUtils.js
Outdated
}; | ||
} | ||
propertyDetails = { keyName, properties }; | ||
if (keyName && param.schema && param.schema.type) { |
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.
Combine this if check with the above one.
libV2/schemaUtils.js
Outdated
minLength: prop.minLength !== undefined ? prop.minLength : undefined, | ||
maxLength: prop.maxLength !== undefined ? prop.maxLength : undefined, | ||
minimum: prop.minimum !== undefined ? prop.minimum : undefined, | ||
maximum: prop.maximum !== undefined ? prop.maximum : undefined, | ||
pattern: prop.pattern || undefined, | ||
example: prop.example || undefined, |
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.
This should also check for undefined
since example can also be false
or 0
or some other falsy value
libV2/schemaUtils.js
Outdated
resolvedResponseBodyResult = resolveBodyData( | ||
context, responseContent[bodyType], bodyType, true, code, requestBodyExamples); | ||
allBodyData = resolvedResponseBodyResult.generatedBody; | ||
resolvedResponseBodyTypes = resolvedResponseBodyResult ? |
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.
This check is not needed
libV2/schemaUtils.js
Outdated
requestIdentifier, | ||
requestBlock, | ||
typesObject = {}; | ||
if (requestBody && requestBody.resolvedSchemaTypeObject) { |
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.
This is not needed
libV2/schemaUtils.js
Outdated
{ pathVariables, collectionVariables } = filterCollectionAndPathVariables(url, pathParams), | ||
requestBody = resolveRequestBodyForPostmanRequest(context, operationItem[method]), | ||
bodyTypes = requestBody && requestBody.resolvedSchemaTypeObject, |
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.
bodyTypes
-> requestBodyTypes
libV2/schemaUtils.js
Outdated
} = resolveResponseForPostmanRequest(context, operationItem[method], request); | ||
|
||
requestIdentifier = method + path; | ||
requestBlock = { request: unifiedRequestTypes, response: unifiedResponseTypes }; |
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.
This is not needed, we can add this directly rather than using another variable
libV2/schemaUtils.js
Outdated
{ alwaysInheritAuthentication } = context.computedOptions, | ||
requestIdentifier, | ||
requestBlock, | ||
typesObject = {}; |
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.
This can be called requestTypesObject
libV2/schemaUtils.js
Outdated
@@ -2396,7 +2645,22 @@ module.exports = { | |||
auth: alwaysInheritAuthentication ? undefined : authHelper | |||
}; | |||
|
|||
const { responses, acceptHeader } = resolveResponseForPostmanRequest(context, operationItem[method], request); | |||
const unifiedRequestTypes = { |
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.
requestTypes
libV2/schemaUtils.js
Outdated
* Processes and resolves types from Nested JSON schema structure. | ||
* | ||
* @param {Object} resolvedSchema - The resolved JSON schema to process. | ||
* @param {Set<string>} [parentRequired=new Set()] - A set of parent-required property keys to inherit. |
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.
This needs to be removed
libV2/schemaUtils.js
Outdated
processSchema = (resolvedSchema) => { | ||
if (resolvedSchema.type === 'object' && resolvedSchema.properties) { | ||
const schemaDetails = { | ||
type: resolvedSchema.type || 'unknown', |
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 unknown
needs to be removed
libV2/schemaUtils.js
Outdated
} | ||
else if (resolvedSchema.type === 'array' && resolvedSchema.items) { | ||
const arrayDetails = { | ||
type: resolvedSchema.type || 'unknown', |
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.
Remove the unknown
from here
libV2/schemaUtils.js
Outdated
schemaDetails.required.push(key); | ||
} | ||
if (prop.properties) { | ||
let res = processSchema(prop); |
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.
Please use descriptive variable names
libV2/schemaUtils.js
Outdated
return arrayDetails; | ||
} | ||
return { | ||
type: resolvedSchema.type || 'unknown' |
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.
unknown
needs to be removed
libV2/schemaUtils.js
Outdated
@@ -1630,13 +1727,23 @@ let QUERYPARAM = 'query', | |||
mode: 'formdata', | |||
formdata: formDataParams | |||
}, | |||
resolvedBody; | |||
resolvedBody, | |||
result, |
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.
Use more descriptive name
libV2/schemaUtils.js
Outdated
resolvedBody = resolveBodyData(context, requestBodyContent.schema)[0]; | ||
result = resolveBodyData(context, requestBodyContent.schema); | ||
resolvedBody = | ||
result && Array.isArray(result.generatedBody) && result.generatedBody.length > 0 ? |
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.
These condition checks needs to be simplified, refer the above comment
libV2/schemaUtils.js
Outdated
minLength: schema.minLength !== undefined ? schema.minLength : undefined, | ||
maxLength: schema.maxLength !== undefined ? schema.maxLength : undefined, | ||
minimum: schema.minimum !== undefined ? schema.minimum : undefined, | ||
maximum: schema.maximum !== undefined ? schema.maximum : undefined, |
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.
These checks are unnecessary and can be removed
libV2/schemaUtils.js
Outdated
|
||
if (headerData && headerData.name && headerData.schema && headerData.schema.type) { | ||
const { name, schema } = headerData; | ||
keyName = name; |
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.
keyName variable is not needed
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.
Let's remove this please ^
libV2/schemaUtils.js
Outdated
resolvedBody = | ||
|
||
resolvedBodyResult && Array.isArray(resolvedBodyResult.generatedBody) && | ||
resolvedBodyResult.generatedBody[0] ? |
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.
This check needs to be simplified 😞
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.
This was simplified based on your comment
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.
I meant we don't need the ternary operator here 🤦
libV2/schemaUtils.js
Outdated
undefined; | ||
|
||
resolvedSchemaTypeObject = resolvedBodyResult && | ||
resolvedBodyResult.resolvedSchemaType ? resolvedBodyResult.resolvedSchemaType : undefined; |
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.
Same as above
libV2/schemaUtils.js
Outdated
resolvedBody = resolveBodyData(context, requestBodyContent.schema)[0]; | ||
resolvedBodyResult = resolveBodyData(context, requestBodyContent.schema); | ||
resolvedBody = | ||
resolvedBodyResult && Array.isArray(resolvedBodyResult.generatedBody) && |
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.
Same as above comment, please take care of these in all the places where you have added such checks
libV2/schemaUtils.js
Outdated
resolvedBodyResult = resolveBodyData(context, requestContent[bodyType], bodyType); | ||
resolvedBody = | ||
resolvedBodyResult && Array.isArray(resolvedBodyResult.generatedBody) && | ||
resolvedBodyResult.generatedBody[0] ? | ||
resolvedBodyResult.generatedBody[0] : | ||
undefined; | ||
|
||
resolvedSchemaTypeObject = | ||
resolvedBodyResult && resolvedBodyResult.resolvedSchemaType ? | ||
resolvedBodyResult.resolvedSchemaType : | ||
undefined; | ||
|
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.
Same as above
libV2/schemaUtils.js
Outdated
}, | ||
|
||
resolvePathParamsForPostmanRequest = (context, operationItem, method) => { | ||
const params = resolvePathItemParams(context, operationItem[method].parameters, operationItem.parameters), | ||
pmParams = []; | ||
let pathParamTypes = []; |
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.
This can be combined with the above const declaration
resolvedExamplesObject = resolvedExamples[0] && resolvedExamples[0].resolvedResponseBodyTypes; | ||
responseBodyHeaderObj = | ||
{ | ||
body: JSON.stringify(resolvedExamplesObject, null, 2), |
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.
Q: Do we really need to stringify
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.
yes, we are not doing it again
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.
I meant what is the use of this stringify ? keeping it as JS object also works right ?
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.
yes, but i wanted to export the object in such a way that it can be used by collection0definition as it is. so stringified it. and changing it right now might be risky as all the tests would start to break.
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.
Let's remove all these stringify calls since they aren't necessary when we're picking up the E2E test ticket.
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.
https://postmanlabs.atlassian.net/browse/AB-293?focusedCommentId=823082 -> Tracking it here
test/unit/convertV2WithTypes.test.js
Outdated
// Disabling max Length for better visibility of the expectedExtractedTypes | ||
|
||
/* eslint-disable one-var */ | ||
// Disabling as we want the checks to run in order of their declaration |
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.
This doesn't explain / mean anything when I'm reading this 😢
test/unit/convertV2WithTypes.test.js
Outdated
}; | ||
|
||
|
||
describe('convertV2WithTypes should generate collection confirming to collection 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.
typo confirming
-> conforming
test/unit/convertV2WithTypes.test.js
Outdated
); | ||
}); | ||
|
||
it('should validate the schema' + testSpec1, 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.
What does validate the schema mean here ? The function being tested does not validate the schema right ? 🤔
test/unit/convertV2WithTypes.test.js
Outdated
|
||
const element = Object.values(conversionResult.extractedTypes)[0]; | ||
const { response } = element; | ||
// Get the schema from the response |
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.
This comment is unnecessary
@AyushShri Types are not being generated for responses when the response code is defined as Screen.Recording.2025-01-08.at.11.23.18.AM.mov |
The changes aims to extract type information along with collection generation from OAS
Sample Type Information Structure
"extractedTypes": { "get/pets": { "request": { "headers": "[]", "pathParam": "[]", "queryParam": "[\n {\n \"keyName\": \"limit1\",\n \"properties\": {\n \"type\": \"integer\",\n \"default\": \"<integer>\",\n \"required\": false,\n \"deprecated\": false\n }\n }\n]" }, "response": { "default": { "body": "{\n \"type\": \"object\",\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"deprecated\": false\n },\n \"message\": {\n \"type\": \"string\",\n \"deprecated\": false\n }\n },\n \"required\": [\n \"code\",\n \"message\"\n ]\n}", "headers": "[]" } } } }