Skip to content

Commit 4bc8618

Browse files
committed
Merge commit 'refs/pull/5/head' of https://github.com/hackolade/OpenAPI
2 parents d95fff7 + 191ab93 commit 4bc8618

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

forward_engineering/helpers/typeHelper.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,22 @@ function getRef({ $ref: ref }) {
9090
}
9191

9292
const schemaIndex = path.indexOf('schema');
93-
const schemaPath = schemaIndex === -1 ? [] : path.slice(schemaIndex);
94-
const pathWithoutProperties = path.slice(0, schemaIndex).filter(item => item !== 'properties');
95-
const bucketWithRequest = (path[1] === 'definitions') ? path[1] : pathWithoutProperties.slice(0,2);
96-
93+
const hasSchema = schemaIndex !== -1;
94+
const isComponents = (path[1] === 'definitions');
95+
const schemaPath = !hasSchema ? [] : path.slice(schemaIndex);
96+
const pathWithoutProperties = (hasSchema ? path.slice(0, schemaIndex) : path).filter(item => item !== 'properties');
97+
const bucketWithRequest = isComponents ? ['components'] : pathWithoutProperties.slice(0,2);
98+
const parentElementName = isComponents ? 'components' : 'paths';
9799
if (pathWithoutProperties[3] !== 'response') {
98100
if (pathWithoutProperties[2] !== 'requestBody') {
99-
return { $ref: `${pathToFile}#/paths/${[ ...pathWithoutProperties, ...schemaPath].join('/')}` };
101+
if (isComponents) {
102+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties.slice(2), ...schemaPath].join('/')}` };
103+
}
104+
105+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties , ...schemaPath].join('/')}` };
100106
}
101107

102-
return { $ref: `${pathToFile}#/paths/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` };
108+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` };
103109
}
104110

105111
const response = pathWithoutProperties[2];

0 commit comments

Comments
 (0)