Skip to content

Commit

Permalink
fix: unable to generate typescript when opens local swagger json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchardxyz committed Sep 4, 2023
1 parent dfeb02a commit 4ffba23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions webview/src/pages/WebviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const WebviewPage: React.FC<WebviewPageProps> = (props) => {

const [currentApiGroup, setCurrentApiGroup] = useState<ApiGroupByTag[]>([]);
const [swaggerDocs, setSwaggerDocs] = useState<OpenAPIV2.Document>();
const [searchPanelKey, setSearchPanelKey] = useState<string>(PARSE_METHOD_DOCS);
const _this = useRef<{ apiGroup?: ApiGroupByTag[]; V2Document?: OpenAPIV2.Document }>({}).current;

const [form] = useForm();
Expand Down Expand Up @@ -166,7 +167,9 @@ const WebviewPage: React.FC<WebviewPageProps> = (props) => {
);

const generateTypescript = useMemoizedFn(async () => {
await form.validateFields();
if (searchPanelKey === PARSE_METHOD_DOCS) {
await form.validateFields();
}
startGenerateLoading();
const result = await generateV2Typescript();
stopGenerateLoading();
Expand Down Expand Up @@ -226,6 +229,12 @@ const WebviewPage: React.FC<WebviewPageProps> = (props) => {
refreshSwaggerSchema();
}, [currentSwaggerUrl]);

useEffect(() => {
if (searchPanelKey) {
resetPageWhenChange();
}
}, [searchPanelKey]);

useMount(() => {
handleExtInfo();
form.setFieldValue('outputOptions', ['responseBody', 'requestParams', 'service']);
Expand All @@ -249,7 +258,9 @@ const WebviewPage: React.FC<WebviewPageProps> = (props) => {
<Form form={form} layout="vertical" {...formItemLayout} style={{ overflow: 'hidden', height: expand ? 'unset' : 0 }}>
<Tabs
defaultActiveKey={PARSE_METHOD_DOCS}
onChange={resetPageWhenChange}
onChange={(key) => {
setSearchPanelKey(key);
}}
items={[
{
key: PARSE_METHOD_DOCS,
Expand Down

0 comments on commit 4ffba23

Please sign in to comment.