You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/10/25 15:38:46 UTC

[camel-karavan] branch main updated: Rest generator for YAML menu

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 2283b7a  Rest generator for YAML menu
2283b7a is described below

commit 2283b7a47bacdb3997a2665ea3e0a0b4ffaac881
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Tue Oct 25 11:38:29 2022 -0400

    Rest generator for YAML menu
---
 karavan-vscode/package.json       |  2 +-
 karavan-vscode/src/openapiView.ts | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index a752b27..a2f3b59 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -339,7 +339,7 @@
         },
         {
           "command": "karavan.generate-rest",
-          "when": "resourceExtname == .json",
+          "when": "resourceExtname == .json || resourceExtname == .yaml",
           "group": "karavan@9"
         }
       ],
diff --git a/karavan-vscode/src/openapiView.ts b/karavan-vscode/src/openapiView.ts
index 437cdd5..a8dda20 100644
--- a/karavan-vscode/src/openapiView.ts
+++ b/karavan-vscode/src/openapiView.ts
@@ -18,6 +18,7 @@ import { Command, EventEmitter, ProviderResult, TreeDataProvider, TreeItem, Tree
 import * as path from "path";
 import * as utils from "./utils";
 import * as jbang from "./jbang";
+import * as yaml from 'js-yaml';
 import { ThemeIcon } from "vscode";
 import { DesignerView } from "./designerView";
 
@@ -53,6 +54,17 @@ export class OpenApiView implements TreeDataProvider<OpenApiItem> {
 				result.push(new OpenApiItem(basename, filename, api?.info?.title, { command: 'karavan.open-file', title: 'Open file', arguments: [{ fsPath: filename }] }));
 			}
 		}
+		const yfiles = await utils.getYamlFiles(dir);
+		for (let x in yfiles){
+			const filename = yfiles[x];
+			const readData = await utils.readFile(path.resolve(filename));
+			const text = Buffer.from(readData).toString('utf8');
+			const api: any = yaml.load(text);
+			if (api.openapi) {
+				const basename = path.basename(filename);
+				result.push(new OpenApiItem(basename, filename, api?.info?.title, { command: 'karavan.open-file', title: 'Open file', arguments: [{ fsPath: filename }] }));
+			}
+		}
 		return result;
 	}