Fix value resolution.

- When value is not below the properties key, it will be resolved inline
- Avoiding to overwrite the already created references when they are called again from a different node
This commit is contained in:
Erik Mendoza
2022-07-06 15:24:29 -05:00
parent b402ab2eac
commit 4bf664e80a
8 changed files with 97 additions and 72 deletions

View File

@@ -288,10 +288,11 @@ function handleLocalCollisions(trace, initialMainKeys) {
* @param {object} rootMainKeys - A dictionary with the component keys in local components object and its mainKeys
* @param {string} commonPathFromData - The common path in the file's paths
* @param {Array} allData - array of { path, content} objects
* @param {object} globalReferences - The accumulated global references from all nodes
* @returns {object} - The references in current node and the new content from the node
*/
function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, version, rootMainKeys,
commonPathFromData, allData) {
commonPathFromData, allData, globalReferences) {
let referencesInNode = [],
nodeReferenceDirectory = {},
mainKeys = {};
@@ -349,17 +350,19 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, ve
inline = true;
}
nodeReferenceDirectory[tempRef] = {
local,
keyInComponents: nodeTrace,
node: newValue,
reference: inline ? newRefInDoc : referenceInDocument,
traceToParent,
parentNodeKey: parentFilename,
mainKeyInTrace: nodeTrace[nodeTrace.length - 1],
refHasContent,
inline
};
if (_.isNil(globalReferences[tempRef])) {
nodeReferenceDirectory[tempRef] = {
local,
keyInComponents: nodeTrace,
node: newValue,
reference: inline ? newRefInDoc : referenceInDocument,
traceToParent,
parentNodeKey: parentFilename,
mainKeyInTrace: nodeTrace[nodeTrace.length - 1],
refHasContent,
inline
};
}
mainKeys[componentKey] = tempRef;
@@ -381,9 +384,11 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename, ve
* @param {string} version - The current version
* @param {object} rootMainKeys - A dictionary with the component keys in local components object and its mainKeys
* @param {string} commonPathFromData - The common path in the file's paths
* @param {object} globalReferences - The accumulated global refernces from all nodes
* @returns {object} - Detect root files result object
*/
function getNodeContentAndReferences (currentNode, allData, specRoot, version, rootMainKeys, commonPathFromData) {
function getNodeContentAndReferences (currentNode, allData, specRoot, version, rootMainKeys,
commonPathFromData, globalReferences) {
let graphAdj = [],
missingNodes = [],
nodeContent,
@@ -408,7 +413,8 @@ function getNodeContentAndReferences (currentNode, allData, specRoot, version, r
version,
rootMainKeys,
commonPathFromData,
allData
allData,
globalReferences
);
referencesInNode.forEach((reference) => {
@@ -640,8 +646,16 @@ module.exports = {
commonPathFromData = Utils.findCommonSubpath(allData.map((fileData) => {
return fileData.fileName;
}));
rootContextData = algorithm.traverseAndBundle(specRoot, (currentNode) => {
return getNodeContentAndReferences(currentNode, allData, specRoot, version, initialMainKeys, commonPathFromData);
rootContextData = algorithm.traverseAndBundle(specRoot, (currentNode, globalReferences) => {
return getNodeContentAndReferences(
currentNode,
allData,
specRoot,
version,
initialMainKeys,
commonPathFromData,
globalReferences
);
});
components = generateComponentsWrapper(
specRoot.parsed.oasObject,

View File

@@ -12,7 +12,8 @@ const SCHEMA_CONTAINERS = [
responses: 'responses'
},
INLINE = [
'examples'
'examples',
'value'
],
COMPONENTS_KEYS = [
'definitions',

View File

@@ -8,8 +8,7 @@ const SCHEMA_CONTAINERS = [
'schema'
],
EXAMPLE_CONTAINERS = [
'example',
'value'
'example'
],
REQUEST_BODY_CONTAINER = [
'requestBody'
@@ -26,7 +25,10 @@ const SCHEMA_CONTAINERS = [
properties: 'schemas',
links: 'links'
},
INLINE = ['properties'],
INLINE = [
'properties',
'value'
],
ROOT_CONTAINERS_KEYS = [
'components'
],

View File

@@ -8,8 +8,7 @@ const SCHEMA_CONTAINERS = [
'schema'
],
EXAMPLE_CONTAINERS = [
'example',
'value'
'example'
],
REQUEST_BODY_CONTAINER = [
'requestBody'
@@ -27,7 +26,10 @@ const SCHEMA_CONTAINERS = [
links: 'links',
paths: 'pathItems'
},
INLINE = ['properties'],
INLINE = [
'properties',
'value'
],
ROOT_CONTAINERS_KEYS = [
'components'
],

View File

@@ -48,7 +48,7 @@ class DFS {
nodeContent,
nodeReferenceDirectory,
nodeName
} = getAdjacentAndBundle(node);
} = getAdjacentAndBundle(node, globalReferences);
nodeContents[nodeName] = nodeContent;
Object.entries(nodeReferenceDirectory).forEach(([key, data]) => {
globalReferences[key] = data;

View File

@@ -33,7 +33,11 @@
"examples": {
"WIFI": {
"value": {
"$ref": "#/components/examples/_responses_maps_http_geolocation_wifi_response.yml"
"location": {
"lat": 37.421925,
"lng": -122.0841293
},
"accuracy": 30
}
}
}
@@ -69,7 +73,34 @@
"examples": {
"WIFI": {
"value": {
"$ref": "#/components/examples/_requests_maps_http_geolocation_wifi_request.yml"
"considerIp": "false",
"wifiAccessPoints": [
{
"macAddress": "84:d4:7e:09:a5:f1",
"signalStrength": -43,
"signalToNoiseRatio": 0
},
{
"macAddress": "44:48:c1:a6:f3:d0",
"signalStrength": -55,
"signalToNoiseRatio": 0
}
]
}
},
"Cell Towers": {
"value": {
"cellTowers": [
{
"cellId": 170402199,
"locationAreaCode": 35632,
"mobileCountryCode": 310,
"mobileNetworkCode": 410,
"age": 0,
"signalStrength": -60,
"timingAdvance": 15
}
]
}
}
}
@@ -121,7 +152,6 @@
],
"properties": {
"location": {
"description": "The users estimated latitude and longitude, in degrees.",
"$ref": "#/components/schemas/_schemas_LatLngLiteral.yml"
},
"accuracy": {
@@ -130,7 +160,11 @@
}
},
"example": {
"$ref": "#/components/examples/_responses_maps_http_geolocation_wifi_response.yml"
"location": {
"lat": 37.421925,
"lng": -122.0841293
},
"accuracy": 30
}
},
"_schemas_test.yml": {
@@ -219,7 +253,17 @@
}
},
"example": {
"$ref": "#/components/examples/_requests_maps_http_geolocation_celltowers_request.yml"
"cellTowers": [
{
"cellId": 170402199,
"locationAreaCode": 35632,
"mobileCountryCode": 310,
"mobileNetworkCode": 410,
"age": 0,
"signalStrength": -60,
"timingAdvance": 15
}
]
}
},
"Bounds": {
@@ -232,11 +276,9 @@
],
"properties": {
"northeast": {
"description": "The users estimated latitude and longitude, in degrees.",
"$ref": "#/components/schemas/_schemas_LatLngLiteral.yml"
},
"southwest": {
"description": "The users estimated latitude and longitude, in degrees.",
"$ref": "#/components/schemas/_schemas_LatLngLiteral.yml"
}
}
@@ -248,43 +290,6 @@
"in": "query",
"name": "key"
}
},
"examples": {
"_responses_maps_http_geolocation_wifi_response.yml": {
"location": {
"lat": 37.421925,
"lng": -122.0841293
},
"accuracy": 30
},
"_requests_maps_http_geolocation_wifi_request.yml": {
"considerIp": "false",
"wifiAccessPoints": [
{
"macAddress": "84:d4:7e:09:a5:f1",
"signalStrength": -43,
"signalToNoiseRatio": 0
},
{
"macAddress": "44:48:c1:a6:f3:d0",
"signalStrength": -55,
"signalToNoiseRatio": 0
}
]
},
"_requests_maps_http_geolocation_celltowers_request.yml": {
"cellTowers": [
{
"cellId": 170402199,
"locationAreaCode": 35632,
"mobileCountryCode": 310,
"mobileNetworkCode": 410,
"age": 0,
"signalStrength": -60,
"timingAdvance": 15
}
]
}
}
},
"security": [

View File

@@ -71,9 +71,9 @@ requestBody:
WIFI:
value:
$ref: ../requests/maps_http_geolocation_wifi_request.yml
# Cell Towers:
# value:
# $ref: ../requests/maps_http_geolocation_celltowers_request.yml
Cell Towers:
value:
$ref: ../requests/maps_http_geolocation_celltowers_request.yml
# IP Only:
# value:
# $ref: ../requests/maps_http_geolocation_ip_request.yml

View File

@@ -2600,7 +2600,8 @@ describe('getReferences method when node does not have any reference', function(
'3.0',
{},
'',
[]
[],
{}
);
expect(result.nodeReferenceDirectory).to.be.an('object');
expect(Object.keys(result.nodeReferenceDirectory).length).to.equal(1);