This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


The following commit(s) were added to refs/heads/main by this push:
     new f0bf876  Fix #615
f0bf876 is described below

commit f0bf876acb4846af262ff054a318695c1932f380
Author: Marat Gubaidullin <[email protected]>
AuthorDate: Mon Jan 16 14:14:13 2023 -0500

    Fix #615
---
 karavan-vscode/src/extension.ts   |  7 +++----
 karavan-vscode/src/jbang.ts       |  6 +++---
 karavan-vscode/src/openapiView.ts | 22 ++++++++++++----------
 karavan-vscode/src/utils.ts       | 33 +++++++++++++--------------------
 4 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index 60b7ecf..3e5ce9d 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -136,14 +136,13 @@ export function activate(context: ExtensionContext) {
     context.subscriptions.push(runRuntime);
 
     // Generate REST API from OpenAPI specification command
-    const generateOptions = ["Create new CRD", "Create new YAML", "Add to 
existing file"];
+    const generateOptions = ["Create new Integration", "Add to existing 
Integration"];
     const generateRest = commands.registerCommand('karavan.generate-rest', 
async (...args: any[]) => {
         const openApi: OpenApiItem = args[0];
         window.showQuickPick(generateOptions, { title: "Select REST Generator 
options", canPickMany: false }).then((value) => {
             switch (value) {
-                case generateOptions[0]: inputFileName(true, rootPath, 
openApi); break;
-                case generateOptions[1]: inputFileName(false, rootPath, 
openApi); break;
-                case generateOptions[2]: selectFileName(rootPath, openApi); 
break;
+                case generateOptions[0]: inputFileName(rootPath, openApi); 
break;
+                case generateOptions[1]: selectFileName(rootPath, openApi); 
break;
             }
         })
     });
diff --git a/karavan-vscode/src/jbang.ts b/karavan-vscode/src/jbang.ts
index c438d52..34722e3 100644
--- a/karavan-vscode/src/jbang.ts
+++ b/karavan-vscode/src/jbang.ts
@@ -20,7 +20,7 @@ import * as shell from 'shelljs';
 import * as utils from "./utils";
 import * as exec from "./exec";
 
-export async function camelJbangGenerate(rootPath: string, openApiFullPath: 
string, fullPath: string, add: boolean, crd?: boolean, generateRoutes?: 
boolean) {
+export async function camelJbangGenerate(rootPath: string, openApiFullPath: 
string, fullPath: string, add: boolean, generateRoutes?: boolean) {
     let command = prepareCommand("generate rest -i " + openApiFullPath);
     if (generateRoutes === true) command = command + " --routes";
     executeJbangCommand(rootPath, command, (code, stdout, stderr) => {
@@ -31,11 +31,11 @@ export async function camelJbangGenerate(rootPath: string, 
openApiFullPath: stri
             if (add) {
                 utils.readFile(fullPath).then(readData => {
                     const camelYaml = Buffer.from(readData).toString('utf8');
-                    yaml = utils.createYaml(filename, stdout, camelYaml, 
undefined);
+                    yaml = utils.createYaml(filename, stdout, camelYaml);
                     utils.write(fullPath, yaml);
                 });
             } else {
-                yaml = utils.createYaml(filename, stdout, undefined, crd);
+                yaml = utils.createYaml(filename, stdout, undefined);
                 utils.write(fullPath, yaml);
             }
         } else {
diff --git a/karavan-vscode/src/openapiView.ts 
b/karavan-vscode/src/openapiView.ts
index a8dda20..21c9403 100644
--- a/karavan-vscode/src/openapiView.ts
+++ b/karavan-vscode/src/openapiView.ts
@@ -93,14 +93,14 @@ export class OpenApiItem extends TreeItem {
 /**
  * Select routes generation
  */
-export async function selectRouteGeneration(rootPath: string, openApiFullPath: 
string, fullPath: string, add: boolean, crd?: boolean) {
+export async function selectRouteGeneration(rootPath: string, openApiFullPath: 
string, fullPath: string, add: boolean) {
        const options = ["Generate REST and Routes", 'Generate REST only'];
        await window.showQuickPick(options, {
                title: "Generate route stubs for REST API",
                placeHolder: 'Select option',
        }).then(option => {
                const generateRoutes: boolean = option !== undefined && option 
=== options[0];
-               jbang.camelJbangGenerate(rootPath, openApiFullPath, fullPath, 
add, crd, generateRoutes);
+               jbang.camelJbangGenerate(rootPath, openApiFullPath, fullPath, 
add, generateRoutes);
        });
 }
 
@@ -109,13 +109,13 @@ export async function selectRouteGeneration(rootPath: 
string, openApiFullPath: s
  */
 export async function selectFileName(rootPath?: string, openApi?: OpenApiItem) 
{
        if (rootPath && openApi?.fsPath) {
-               const files = utils.getIntegrationFiles(rootPath);
+               const files = utils.getCamelYamlFiles(rootPath);
                await window.showQuickPick(files, {
                        title: "Select Integration file to add REST API",
                        placeHolder: 'Select file',
                }).then(fullPath => {
                        if (fullPath && openApi?.fsPath) {
-                               selectRouteGeneration(rootPath, openApi.fsPath, 
fullPath, true, undefined);
+                               selectRouteGeneration(rootPath, openApi.fsPath, 
fullPath, true);
                        }
                });
        }
@@ -124,22 +124,24 @@ export async function selectFileName(rootPath?: string, 
openApi?: OpenApiItem) {
 /**
  * Create new file and add REST API
  */
-export async function inputFileName(crd: boolean, rootPath?: string, openApi?: 
OpenApiItem) {
+export async function inputFileName(rootPath?: string, openApi?: OpenApiItem) {
        window.showInputBox({
                title: "Generate REST API from " + openApi?.title,
                ignoreFocusOut: true,
                prompt: "Integration file name",
                validateInput: (text: string): string | undefined => {
-                       if (!text || text.length === 0 || 
!text.endsWith(".yaml")) {
-                               return 'Name should not be empty. Extension 
should be .yaml';
+                       if (!text || text.length === 0) {
+                               return 'Name should not be empty';
                        } else {
                                return undefined;
                        }
                }
-       }).then(filename => {
-               if (filename && openApi?.fsPath && rootPath) {
+       }).then(value => {
+               if (value && openApi?.fsPath && rootPath) {
+                       const name = utils.nameFromTitle(value);
+                       const filename = 
name.toLocaleLowerCase().endsWith('.camel.yaml') ? name : name.split('.')[0] + 
'.camel.yaml';
                        const fullPath = rootPath + path.sep + filename;
-                       selectRouteGeneration(rootPath, openApi.fsPath, 
fullPath, false, crd);
+                       selectRouteGeneration(rootPath, openApi.fsPath, 
fullPath, false);
                }
        });
 }
\ No newline at end of file
diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts
index 4b8968f..4dce88e 100644
--- a/karavan-vscode/src/utils.ts
+++ b/karavan-vscode/src/utils.ts
@@ -166,6 +166,14 @@ export async function getYamlFiles(baseDir: string) {
     return result;
 }
 
+export async function getCamelYamlFiles(baseDir: string) {
+    const result: string[] = [];
+    (await getAllFiles(baseDir, [])).filter(f => 
f.endsWith(".camel.yaml")).forEach(f => {
+        result.push(f);
+    })
+    return result;
+}
+
 export async function hasApplicationProperties(baseDir: string) {
     return (await getPropertyFiles(baseDir)).includes(baseDir + path.sep + 
'application.properties');
 }
@@ -194,21 +202,6 @@ export async function getJsonFiles(baseDir: string) {
     return result;
 }
 
-export async function getIntegrationFiles(baseDir: string) {
-    const result: string[] = []
-    const files = await getYamlFiles(baseDir);
-    for (let x in files) {
-        const filename = files[x];
-        const readData = await readFile(path.resolve(filename));
-        const yaml = Buffer.from(readData).toString('utf8');
-        if (!filename.startsWith(baseDir + path.sep + "target") && 
CamelDefinitionYaml.yamlIsIntegration(yaml)) {
-            result.push(yaml);
-        }
-    }
-    return result;
-}
-
-
 export async function getProperties(rootPath?: string) {
     try {
         if (rootPath === undefined)
@@ -348,17 +341,17 @@ export async function createApplicationGitignore() {
     }
 }
 
-export function createYaml(filename: string, restYaml: string, camelYaml?: 
string, crd?: boolean): string {
+export function createYaml(filename: string, restYaml: string, camelYaml?: 
string): string {
     if (camelYaml) {
         const i = CamelDefinitionYaml.yamlToIntegration(filename, camelYaml);
         const rest = CamelDefinitionYaml.yamlToIntegration(filename, restYaml);
         i.spec.flows = i.spec.flows?.filter(f => f.dslName !== 
'RestDefinition');
         i.spec.flows?.push(...rest.spec.flows || []);
         return CamelDefinitionYaml.integrationToYaml(i);
-    } else if (crd === true) {
-        const i = CamelDefinitionYaml.yamlToIntegration(filename, restYaml);
-        i.type = 'crd';
-        return CamelDefinitionYaml.integrationToYaml(i);
+    // } else if (crd === true) {
+        // const i = CamelDefinitionYaml.yamlToIntegration(filename, restYaml);
+        // i.type = 'crd';
+        // return CamelDefinitionYaml.integrationToYaml(i);
     } else {
         return restYaml;
     }

Reply via email to