diff --git a/menus/openapi.json b/menus/openapi.json index 10d27c6..5902f99 100644 --- a/menus/openapi.json +++ b/menus/openapi.json @@ -17,7 +17,7 @@ "id": "tools.openapi.testallextension", "command": "openapi:test-entire-package" }, { - "label": "Extension version : 0.3.7", + "label": "Extension version : 0.3.13", "id": "tools.openapi.version", "command": "generate:show-version-dialog" }, { diff --git a/package-lock.json b/package-lock.json index a72c548..c01f382 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gs-gs.staruml-cefact", - "version": "0.3.12", + "version": "0.3.13", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8493a6b..a2bc34b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "gs-gs.staruml-cefact", "title": "OpenAPI3.0 Generator", - "description": "StarUML Extension for generating OpenAPI 3.0 Specs from the UML Diagrams. \nImplementation Rules are according to https://edi3.org/uml-profile/ \nExtension Source Code: https://github.com/gs-gs/staruml-cefact \nExtension version: 0.3.7", - "version": "0.3.12", + "description": "StarUML Extension for generating OpenAPI 3.0 Specs from the UML Diagrams. \nImplementation Rules are according to https://edi3.org/uml-profile/ \nExtension Source Code: https://github.com/gs-gs/staruml-cefact \nExtension version: 0.3.13", + "version": "0.3.13", "engines": { "staruml": ">=3.0.0" }, diff --git a/src/component.js b/src/component.js index 3289f0d..74d6456 100644 --- a/src/component.js +++ b/src/component.js @@ -86,6 +86,12 @@ class Component { classEleOrViews = mClassesView; } + utils.resetClassTypeAttribute(); + let classTypeAttribute = utils.getClassTypeAttribute(classEleOrViews); + if(classTypeAttribute.length > 0){ + classEleOrViews = classEleOrViews.concat(classTypeAttribute); + } + console.log("classTypeAttribute : ",classTypeAttribute); /** * Iterate through all classes **/ diff --git a/src/utils.js b/src/utils.js index 5a5c0c1..3b72d40 100644 --- a/src/utils.js +++ b/src/utils.js @@ -221,7 +221,10 @@ function isString(s) { function addAttributeType(itemsObj, attr) { let attributeType = attr.type; - if (isCoreDataType(attributeType)) { + if (attributeType instanceof type.UMLClass) { + addReferenceTypeRuleClass(itemsObj, attributeType); + //notAvailElement.addInvalidAttributeType(attr._parent.name, attr, attributeType.name); + }else if (isCoreDataType(attributeType)) { /* Added reference in allOf object when attribute type is among the Core Data Type */ let coreType = getCoreDataType(attributeType); @@ -236,7 +239,23 @@ function addAttributeType(itemsObj, attr) { addJsonRuleType(attr, attributeType, itemsObj); } } - +/** + * @function addReferenceTypeRuleClass + * @description adds reference of compound type to attribute + * @param {Object} itemsObj + * @param {UMLClass} coreType + * @memberof Utils + */ +function addReferenceTypeRuleClass(itemsObj, coreType) { + let itemObj = {}; + let ref=''; + let sName=''; + itemsObj.items = itemObj; + sName=coreType.name; + ref=constant.getReference() + sName; + itemObj['$ref'] = ref; + itemsObj.type = 'array'; +} /** * @function addReferenceTypeRule * @description adds reference of compound type to attribute @@ -419,15 +438,17 @@ function addJsonRuleType(attr, attributeType, itemsObj) { } } else if (result.length == 0) { - itemsObj.type = 'string'; - + if (isString(attributeType) && isStringCoreType(attributeType)) { + itemsObj.type = 'string'; notAvailElement.addNotLinkedType(attr._parent.name, attr, attributeType); } else if (isString(attributeType)) { notAvailElement.addInvalidAttributeType(attr._parent.name, attr, attributeType); - } else if (attributeType instanceof type.UMLClass) { - notAvailElement.addInvalidAttributeType(attr._parent.name, attr, attributeType.name); - } + itemsObj.type = 'string'; + }/* else if (attributeType instanceof type.UMLClass) { + addReferenceTypeRule(itemsObj, attributeType); + //notAvailElement.addInvalidAttributeType(attr._parent.name, attr, attributeType.name); + } */ } } @@ -694,7 +715,38 @@ function getCoreTypes() { return mCoreTypes; } +let varClassTypeAttribute = []; +function resetClassTypeAttribute(){ + varClassTypeAttribute = []; + +} + +function getClassTypeAttribute(classEleOrViews){ + + + classEleOrViews.forEach(mCorView => { + let mClass ; + if (openAPI.isModelPackage()) { + mClass = mCorView; + } else if (openAPI.isModelDiagram()) { + mClass = mCorView.model; + } + + let attributes = mClass.attributes; + attributes.forEach(attr => { + if(attr.type instanceof type.UMLClass){ + let resFilter = varClassTypeAttribute.filter(resFilter => { + return resFilter._id == attr.type._id; + }); + if(resFilter.length == 0){ + varClassTypeAttribute.push(attr.type); + } + } + }); + }); + return varClassTypeAttribute; +} module.exports.getViewFromOther = getViewFromOther; module.exports.isCoreDataType = isCoreDataType; module.exports.getCoreDataType = getCoreDataType; @@ -719,4 +771,7 @@ module.exports.initCoreTypes = initCoreTypes; module.exports.initJsonRuleType = initJsonRuleType; module.exports.initJsonldRuleType = initJsonldRuleType; module.exports.getJsonldRuleType = getJsonldRuleType; -module.exports.isStringCoreType = isStringCoreType; \ No newline at end of file +module.exports.isStringCoreType = isStringCoreType; +module.exports.buildRequestBodyForSubResource = buildRequestBodyForSubResource; +module.exports.resetClassTypeAttribute = resetClassTypeAttribute; +module.exports.getClassTypeAttribute = getClassTypeAttribute; \ No newline at end of file