Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ export class MiDiagramRpcManager implements MiDiagramAPI {

const getSwaggerName = (swaggerDefPath: string) => {
const ext = path.extname(swaggerDefPath);
return `${name}${apiVersion !== "" ? `_v${apiVersion}` : ''}${ext}`;
return `${name}${apiVersion !== "" ? `_v${apiVersion}` : ''}${ext === ".yml" ? ".yaml" : ext }`;
};
let fileName: string;
let response: GenerateAPIResponse = { apiXml: "", endpointXml: "" };
Expand Down Expand Up @@ -680,10 +680,11 @@ export class MiDiagramRpcManager implements MiDiagramAPI {
fileName = `${name}${apiVersion !== "" ? `_v${apiVersion}` : ''}`;

if (saveSwaggerDef && swaggerDefPath) {
const ext = path.extname(swaggerDefPath);
const swaggerRegPath = path.join(
this.projectUri,
SWAGGER_REL_DIR,
fileName + path.extname(swaggerDefPath)
fileName + (ext === ".yml" ? ".yaml" : ext)
);
fs.mkdirSync(path.dirname(swaggerRegPath), { recursive: true });
fs.copyFileSync(swaggerDefPath, swaggerRegPath);
Expand Down Expand Up @@ -2649,6 +2650,10 @@ ${endpointAttributes}
}

await workspace.applyEdit(edit);
const file = Uri.file(params.documentUri);
let document = workspace.textDocuments.find(doc => doc.uri.fsPath === params.documentUri)
|| await workspace.openTextDocument(file);
await document.save();

if (!params.disableFormatting) {
const formatEdits = (editRequest: ExtendedTextEdit) => {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/mi/mi-extension/src/util/fileOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export function deleteDataMapperResources(filePath: string): Promise<{ status: b
removeEntryFromArtifactXML(projectDir, artifactXmlSavePath, dmName + '_inputSchema.json');
removeEntryFromArtifactXML(projectDir, artifactXmlSavePath, dmName + '_outputSchema.json');
removeEntryFromArtifactXML(projectDir, artifactXmlSavePath, dmName + '.dmc');
workspace.fs.delete(Uri.parse(projectDirPath), { recursive: true, useTrash: true });
workspace.fs.delete(Uri.file(projectDirPath), { recursive: true, useTrash: true });
resolve({ status: true, info: "Datamapper resources removed" });
}
});
Expand Down
4 changes: 2 additions & 2 deletions workspaces/mi/mi-extension/src/util/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function escapeXml(text: string) {
.replace(/"/g, '&quot;');
};

export const LATEST_CAR_PLUGIN_VERSION = "5.4.12";
export const LATEST_CAR_PLUGIN_VERSION = "5.4.13";

export const rootPomXmlContent = (projectName: string, groupID: string, artifactID: string, projectUuid: string, version: string, miVersion: string, initialDependencies: string) => {
const addDeploymentType = compareVersions(miVersion, RUNTIME_VERSION_450) >= 0;
Expand Down Expand Up @@ -417,7 +417,7 @@ export const rootPomXmlContent = (projectName: string, groupID: string, artifact
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>synapse-unit-test-maven-plugin</artifactId>
<version>5.4.12</version>
<version>5.4.13</version>
<executions>
<execution>
<id>synapse-unit-test</id>
Expand Down
6 changes: 6 additions & 0 deletions workspaces/mi/mi-extension/src/util/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export async function replaceFullContentToFile(documentUri: string, content: str

edit.replace(Uri.file(documentUri), fullRange, content);
}

await workspace.applyEdit(edit);
const file = Uri.file(documentUri);
let document = workspace.textDocuments.find(doc => doc.uri.fsPath === documentUri)
|| await workspace.openTextDocument(file);
await document.save();

if (isNewFile) {
// Wait for the file to be fully created and accessible
const maxRetries = 5;
Expand Down
71 changes: 71 additions & 0 deletions workspaces/mi/mi-extension/src/visualizer/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,62 @@ export function activateVisualizer(context: vscode.ExtensionContext, firstProjec
generateSwagger(document.uri.fsPath);
}

const swaggerDir = path.join(projectUri!, "src", "main", "wso2mi", "resources", "api-definitions");
if (document?.uri.fsPath.includes(swaggerDir)) {
const rpcManager = new MiDiagramRpcManager(projectUri!);
const langClient = await MILanguageClient.getInstance(projectUri!);
const apiPath = path.join(apiDir, path.basename(document?.uri.fsPath, path.extname(document?.uri.fsPath)) + '.xml');
const apiName = path.basename(document?.uri.fsPath).split("_v")[0];
langClient?.getSyntaxTree({
documentIdentifier: {
uri: apiPath
}
}).then(st => {
rpcManager.compareSwaggerAndAPI({
apiName: apiName,
apiPath: apiPath
}).then(async response => {
if (response.swaggerExists && !response.isEqual) {
const confirmUpdate = await vscode.window.showInformationMessage(
'The OpenAPI definition is different from the Synapse API.',
{ modal: true },
"Update API", "Update Swagger"
);
switch (confirmUpdate) {
case "Update Swagger":
rpcManager.updateSwaggerFromAPI({
apiName: apiName,
apiPath: apiPath,
existingSwagger: response.existingSwagger,
generatedSwagger: response.generatedSwagger
});
break;
case "Update API":
const resources = getResources(st);
rpcManager.updateAPIFromSwagger({
apiName: apiName,
apiPath: apiPath,
existingSwagger: response.existingSwagger,
generatedSwagger: response.generatedSwagger,
resources: resources.map(r => ({
path: r.path,
methods: r.methods,
position: r.position
})),
insertPosition: {
line: st.syntaxTree.api.range.endTagRange.start.line,
character: st.syntaxTree.api.range.endTagRange.start.character
}
});
break;
default:
break;
}
}
})
});
}

if (currentView !== 'Connector Store Form' && document?.uri?.fsPath?.includes(artifactsDir) || currentView === MACHINE_VIEW.IdpConnectorSchemaGeneratorForm) {
refreshDiagram(projectUri!);
}
Expand Down Expand Up @@ -415,3 +471,18 @@ export const refreshDiagram = debounce(async (projectUri: string, refreshDiagram
refreshUI(projectUri);
}
}, 500);

const getResources = (st: any): any[] => {
const resources: any[] = st?.syntaxTree?.api?.resource ?? [];
return resources.map((resource) => ({
methods: resource.methods,
path: resource.uriTemplate || resource.urlMapping,
position: {
startLine: resource.range.startTagRange.start.line,
startColumn: resource.range.startTagRange.start.character,
endLine: resource.range.endTagRange.end.line,
endColumn: resource.range.endTagRange.end.character,
},
expandable: false
}));
};
Loading