From 4ffba239b57537dbcb8067c249192d92f9be2626 Mon Sep 17 00:00:00 2001 From: Orchard Date: Mon, 4 Sep 2023 20:19:34 +0800 Subject: [PATCH] fix: unable to generate typescript when opens local swagger json file --- CHANGELOG.md | 6 ++++++ webview/src/pages/WebviewPage.tsx | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d21e6..7f0191c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to the "tswagger" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [Unreleased] + +### Fixed + +- Unable to generate typescript when opens local swagger json file + ## [1.0.3] - 2023-08-22 ### Added diff --git a/webview/src/pages/WebviewPage.tsx b/webview/src/pages/WebviewPage.tsx index ee44e6a..305e529 100644 --- a/webview/src/pages/WebviewPage.tsx +++ b/webview/src/pages/WebviewPage.tsx @@ -48,6 +48,7 @@ const WebviewPage: React.FC = (props) => { const [currentApiGroup, setCurrentApiGroup] = useState([]); const [swaggerDocs, setSwaggerDocs] = useState(); + const [searchPanelKey, setSearchPanelKey] = useState(PARSE_METHOD_DOCS); const _this = useRef<{ apiGroup?: ApiGroupByTag[]; V2Document?: OpenAPIV2.Document }>({}).current; const [form] = useForm(); @@ -166,7 +167,9 @@ const WebviewPage: React.FC = (props) => { ); const generateTypescript = useMemoizedFn(async () => { - await form.validateFields(); + if (searchPanelKey === PARSE_METHOD_DOCS) { + await form.validateFields(); + } startGenerateLoading(); const result = await generateV2Typescript(); stopGenerateLoading(); @@ -226,6 +229,12 @@ const WebviewPage: React.FC = (props) => { refreshSwaggerSchema(); }, [currentSwaggerUrl]); + useEffect(() => { + if (searchPanelKey) { + resetPageWhenChange(); + } + }, [searchPanelKey]); + useMount(() => { handleExtInfo(); form.setFieldValue('outputOptions', ['responseBody', 'requestParams', 'service']); @@ -249,7 +258,9 @@ const WebviewPage: React.FC = (props) => {
{ + setSearchPanelKey(key); + }} items={[ { key: PARSE_METHOD_DOCS,