Skip to content

Commit

Permalink
skip sub-resource generation if ids have the same names
Browse files Browse the repository at this point in the history
per #124
  • Loading branch information
kshychko committed May 3, 2020
1 parent 3d7dc90 commit ce199ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
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.20",
"version": "0.3.20",
"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.21",
"version": "0.3.21",
"engines": {
"staruml": ">=3.0.0"
},
Expand Down
33 changes: 20 additions & 13 deletions src/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Paths {

/*
1. Write Simple path : Generate query type paramters for 'GET' method if non-id parameters (Issue : #6)
2. Write Simple path :
2. Write Simple path :
Pattern : (GET/POST) : '/{pathname}'
*/
this.writeSimplePathObject(pathsObject, mOperations, objInterfaceRealization);
Expand Down Expand Up @@ -307,9 +307,12 @@ class Paths {

let end1Interface = interfaceAssociation.end1; //source example : imprtDeclarations
let end2Interface = interfaceAssociation.end2; //target : CargoLines
if (end2Interface.reference.name == 'travelDocuments') {
console.log("yes");
}

if (end1Interface.reference.attributes[0].name == end2Interface.reference.attributes[0].name) {
app.dialogs.showAlertDialog('The interface "' + end2Interface.reference.name + '" has the same name "' + end1Interface.reference.attributes[0].name + '" for `id` attribute as the interface "' + end1Interface.reference.name + '", they must be different to generate the paths for sub-resource.');
return;
}

let uIR = app.repository.select("@UMLInterfaceRealization");
let resUIR = uIR.filter(irealization => {
return end2Interface.reference._id == irealization.target._id;
Expand All @@ -323,7 +326,11 @@ class Paths {
let wOperationObject = {};
let refCName = '';
if (objOperation.name.toUpperCase() == constant.GET) {
let mICPath = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name;



let mICPath = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name;
// let mICPath = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name;
// let mICPath = "/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}/" + end1Interface.reference.name;
//test
if (mainPathsObject.hasOwnProperty(mICPath)) {
Expand Down Expand Up @@ -351,7 +358,7 @@ class Paths {
let objSchema = {};
objSchema.type = 'string';

let name = end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name;
let name = end1Interface.reference.attributes[0].name;
let description = (end1Interface.reference.attributes[0].documentation ? utils.buildDescription(end1Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION);
/* let name = end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name;
let description = (end2Interface.reference.attributes[0].documentation ? utils.buildDescription(end2Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION); */
Expand Down Expand Up @@ -393,7 +400,7 @@ class Paths {

/* Get single element record */

let mICPath1 = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}";
let mICPath1 = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.attributes[0].name + "}";
// let mICPath1 = "/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}";

let pathsSingleObject = {};
Expand Down Expand Up @@ -425,7 +432,7 @@ class Paths {
let objSingleSchema = {};
objSingleSchema.type = 'string';

let name1 = end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name;
let name1 = end1Interface.reference.attributes[0].name;
let description1 = (end1Interface.reference.attributes[0].documentation ? utils.buildDescription(end1Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION);

// let name1 = end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name;
Expand All @@ -441,7 +448,7 @@ class Paths {
objSingleSchema = {};
objSingleSchema.type = 'string';

let name2 = end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name;
let name2 = end2Interface.reference.attributes[0].name;
let description2 = (end2Interface.reference.attributes[0].documentation ? utils.buildDescription(end2Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION);
utils.buildParameter(name2, "path", description2, true, objSingleSchema, paramsSingleObject);

Expand Down Expand Up @@ -497,7 +504,7 @@ class Paths {

} else if (objOperation.name.toUpperCase() == constant.DELETE) {

let mICPath = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}";
let mICPath = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.attributes[0].name + "}";
// let mICPath = "/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}";
if (mainPathsObject.hasOwnProperty(mICPath)) {
pathsObject = mainPathsObject[mICPath];
Expand All @@ -512,7 +519,7 @@ class Paths {

/* Get single element record */

let mICPath1 = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}";
let mICPath1 = "/" + end1Interface.reference.name + "/{" + end1Interface.reference.attributes[0].name + "}/" + end2Interface.reference.name + "/{" + end2Interface.reference.attributes[0].name + "}";
// let mICPath1 = "/" + end2Interface.reference.name + "/{" + end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name + "}/" + end1Interface.reference.name + "/{" + end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name + "}";
let pathsSingleObject = {};
if (mainPathsObject.hasOwnProperty(mICPath1)) {
Expand Down Expand Up @@ -542,7 +549,7 @@ class Paths {
let objSingleSchema = {};
objSingleSchema.type = 'string';

let name1 = end1Interface.reference.name + "_" + end1Interface.reference.attributes[0].name;
let name1 = end1Interface.reference.attributes[0].name;
let description1 = (end1Interface.reference.attributes[0].documentation ? utils.buildDescription(end1Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION);

// let name1 = end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name;
Expand All @@ -558,7 +565,7 @@ class Paths {
objSingleSchema = {};
objSingleSchema.type = 'string';

let name2 = end2Interface.reference.name + "_" + end2Interface.reference.attributes[0].name;
let name2 = end2Interface.reference.attributes[0].name;
let description2 = (end2Interface.reference.attributes[0].documentation ? utils.buildDescription(end2Interface.reference.attributes[0].documentation) : constant.STR_MISSING_DESCRIPTION);
utils.buildParameter(name2, "path", description2, true, objSingleSchema, paramsSingleObject);

Expand Down

0 comments on commit ce199ca

Please sign in to comment.