diff --git a/forward_engineering/helpers/typeHelper.js b/forward_engineering/helpers/typeHelper.js index 51ddbf2..34f052f 100644 --- a/forward_engineering/helpers/typeHelper.js +++ b/forward_engineering/helpers/typeHelper.js @@ -90,16 +90,22 @@ function getRef({ $ref: ref }) { } const schemaIndex = path.indexOf('schema'); - const schemaPath = schemaIndex === -1 ? [] : path.slice(schemaIndex); - const pathWithoutProperties = path.slice(0, schemaIndex).filter(item => item !== 'properties'); - const bucketWithRequest = (path[1] === 'definitions') ? path[1] : pathWithoutProperties.slice(0,2); - + const hasSchema = schemaIndex !== -1; + const isComponents = (path[1] === 'definitions'); + const schemaPath = !hasSchema ? [] : path.slice(schemaIndex); + const pathWithoutProperties = (hasSchema ? path.slice(0, schemaIndex) : path).filter(item => item !== 'properties'); + const bucketWithRequest = isComponents ? ['components'] : pathWithoutProperties.slice(0,2); + const parentElementName = isComponents ? 'components' : 'paths'; if (pathWithoutProperties[3] !== 'response') { if (pathWithoutProperties[2] !== 'requestBody') { - return { $ref: `${pathToFile}#/paths/${[ ...pathWithoutProperties, ...schemaPath].join('/')}` }; + if (isComponents) { + return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties.slice(2), ...schemaPath].join('/')}` }; + } + + return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties , ...schemaPath].join('/')}` }; } - return { $ref: `${pathToFile}#/paths/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` }; + return { $ref: `${pathToFile}#/${parentElementName}/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` }; } const response = pathWithoutProperties[2];