Skip to content

Commit

Permalink
#113 treat referenced type classes in the same way as composition ass…
Browse files Browse the repository at this point in the history
…ociation targets
  • Loading branch information
faizanvahevaria committed Apr 16, 2020
1 parent 4a5b6fb commit e9aaee9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion menus/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}, {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
6 changes: 6 additions & 0 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand Down
71 changes: 63 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
} */
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -719,4 +771,7 @@ module.exports.initCoreTypes = initCoreTypes;
module.exports.initJsonRuleType = initJsonRuleType;
module.exports.initJsonldRuleType = initJsonldRuleType;
module.exports.getJsonldRuleType = getJsonldRuleType;
module.exports.isStringCoreType = isStringCoreType;
module.exports.isStringCoreType = isStringCoreType;
module.exports.buildRequestBodyForSubResource = buildRequestBodyForSubResource;
module.exports.resetClassTypeAttribute = resetClassTypeAttribute;
module.exports.getClassTypeAttribute = getClassTypeAttribute;

0 comments on commit e9aaee9

Please sign in to comment.