Browse Source

🐛 (openapi): 生成器解析 `Default:` 时不再在小数点处截断

`Default: 0.8` 原来被当成句号截成 0,余下的 `.8` 跑进参数说明;生成的客户端会把 0 当默认值发出去。
「.」后面紧跟数字时视为小数点。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 1 day ago
parent
commit
b6f407c7da

+ 0 - 198
dashboard-v6/src/components/anthology/AnthologyInfoEdit.tsx

@@ -1,198 +0,0 @@
-import { Form, message } from "antd";
-import { useIntl } from "react-intl";
-import {
-  ProForm,
-  ProFormSelect,
-  ProFormText,
-  type RequestOptionsType,
-} from "@ant-design/pro-components";
-import MDEditor from "@uiw/react-md-editor";
-
-import { get, put } from "../../request";
-import type {
-  IAnthologyDataRequest,
-  IAnthologyDataResponse,
-  IAnthologyResponse,
-} from "../../api/article";
-import LangSelect from "../general/LangSelect";
-import PublicitySelect from "../studio/PublicitySelect";
-import { useState } from "react";
-import type { DefaultOptionType } from "antd/lib/select";
-import type { IApiResponseChannelList } from "../../api/channel";
-import { useAppSelector } from "../../hooks";
-import { currentUser } from "../../reducers/current-user";
-
-interface IFormData {
-  title: string;
-  subtitle: string;
-  summary?: string;
-  lang: string;
-  status: number;
-  defaultChannel?: string;
-}
-
-interface IWidget {
-  anthologyId?: string;
-  studioName?: string;
-  onLoad?: (data: IAnthologyDataResponse) => void;
-}
-const AnthologyInfoEditWidget = ({
-  studioName,
-  anthologyId,
-  onLoad,
-}: IWidget) => {
-  const intl = useIntl();
-  const [channelOption, setChannelOption] = useState<DefaultOptionType[]>([]);
-  const [currChannel, setCurrChannel] = useState<RequestOptionsType>();
-  const [data, setData] = useState<IAnthologyDataResponse>();
-
-  const user = useAppSelector(currentUser);
-
-  return anthologyId ? (
-    <ProForm<IFormData>
-      onFinish={async (values: IFormData) => {
-        const url = `/api/v2/anthology/${anthologyId}`;
-        console.log("url", url);
-        console.log("values", values);
-        const res = await put<IAnthologyDataRequest, IAnthologyResponse>(url, {
-          title: values.title,
-          subtitle: values.subtitle,
-          summary: values.summary,
-          status: values.status,
-          lang: values.lang,
-          default_channel: values.defaultChannel,
-        });
-        console.log(res);
-        if (res.ok) {
-          if (typeof onLoad !== "undefined") {
-            onLoad(res.data);
-          }
-          message.success(
-            intl.formatMessage({
-              id: "flashes.success",
-            })
-          );
-        } else {
-          message.error(res.message);
-        }
-      }}
-      request={async () => {
-        const url = `/api/v2/anthology/${anthologyId}`;
-        console.log("url", url);
-        const res = await get<IAnthologyResponse>(url);
-        console.log("文集get", res);
-        if (res.ok) {
-          setData(res.data);
-          if (typeof onLoad !== "undefined") {
-            onLoad(res.data);
-          }
-          if (res.data.default_channel) {
-            const channel = {
-              value: res.data.default_channel.id,
-              label: res.data.default_channel.name,
-            };
-            setCurrChannel(channel);
-            setChannelOption([channel]);
-          }
-
-          return {
-            title: res.data.title,
-            subtitle: res.data.subtitle,
-            summary: res.data.summary ? res.data.summary : undefined,
-            lang: res.data.lang,
-            status: res.data.status,
-            defaultChannel: res.data.default_channel?.id,
-          };
-        } else {
-          return {
-            title: "",
-            subtitle: "",
-            summary: "",
-            lang: "",
-            status: 0,
-            defaultChannel: "",
-          };
-        }
-      }}
-    >
-      <ProForm.Group>
-        <ProFormText
-          width="md"
-          name="title"
-          required
-          label={intl.formatMessage({
-            id: "forms.fields.title.label",
-          })}
-          rules={[
-            {
-              required: true,
-              message: intl.formatMessage({
-                id: "forms.message.title.required",
-              }),
-            },
-          ]}
-        />
-        <ProFormText
-          width="md"
-          name="subtitle"
-          label={intl.formatMessage({
-            id: "forms.fields.subtitle.label",
-          })}
-        />
-      </ProForm.Group>
-
-      <ProForm.Group>
-        <LangSelect width="md" />
-        <PublicitySelect
-          width="md"
-          disable={["public_no_list"]}
-          readonly={
-            user?.roles?.includes("basic") ||
-            data?.studio.roles?.includes("basic")
-              ? true
-              : false
-          }
-        />
-      </ProForm.Group>
-      <ProForm.Group>
-        <ProFormSelect
-          options={channelOption}
-          width="md"
-          name="defaultChannel"
-          label={"默认版本"}
-          showSearch
-          debounceTime={300}
-          request={async ({ keyWords }) => {
-            console.log("keyWord", keyWords);
-            if (typeof keyWords === "undefined") {
-              return currChannel ? [currChannel] : [];
-            }
-            const url = `/api/v2/channel?view=studio&name=${studioName}`;
-            console.log("url", url);
-            const json = await get<IApiResponseChannelList>(url);
-            const textbookList = json.data.rows.map((item) => {
-              return {
-                value: item.uid,
-                label: `${item.studio.nickName}/${item.name}`,
-              };
-            });
-            console.log("json", textbookList);
-            return textbookList;
-          }}
-        />
-      </ProForm.Group>
-      <ProForm.Group>
-        <Form.Item
-          name="summary"
-          label={intl.formatMessage({ id: "forms.fields.summary.label" })}
-        >
-          <MDEditor />
-        </Form.Item>
-      </ProForm.Group>
-    </ProForm>
-  ) : (
-    <></>
-  );
-};
-
-export default AnthologyInfoEditWidget;

+ 0 - 84
dashboard-v6/src/components/channel/ChannelList.tsx

@@ -1,84 +0,0 @@
-import { useIntl } from "react-intl";
-import { useState, useEffect } from "react";
-import { Card, List, message, Space, Tag } from "antd";
-
-import type { IChannelApiData } from "../../api/channel";
-
-import { get } from "../../request";
-import ChannelListItem from "./ChannelListItem";
-import type { IStudio } from "../../api/Auth";
-import type { IApiResponseChannelList } from "../../api/progress";
-
-export interface ChannelFilterProps {
-  chapterProgress: number;
-  lang: string;
-  channelType: string;
-}
-interface IChannelList {
-  channel: IChannelApiData;
-  studio: IStudio;
-  count: number;
-}
-interface IWidgetChannelList {
-  filter?: ChannelFilterProps;
-}
-const defaultChannelFilterProps: ChannelFilterProps = {
-  chapterProgress: 0.9,
-  lang: "zh",
-  channelType: "translation",
-};
-
-const ChannelListWidget = ({
-  filter = defaultChannelFilterProps,
-}: IWidgetChannelList) => {
-  const [tableData, setTableData] = useState<IChannelList[]>([]);
-  const intl = useIntl();
-
-  useEffect(() => {
-    const url = `/api/v2/progress?view=channel&channel_type=${filter.channelType}&lang=${filter.lang}&progress=${filter.chapterProgress}`;
-    get<IApiResponseChannelList>(url).then(function (json) {
-      if (json.ok) {
-        console.log("channel", json.data);
-        const newData: IChannelList[] = json.data.rows.map((item) => {
-          return {
-            channel: {
-              name: item.channel.name,
-              id: item.channel.uid,
-              type: item.channel.type,
-            },
-            studio: item.studio,
-            count: item.count,
-          };
-        });
-        setTableData(newData);
-      } else {
-        message.error(json.message);
-      }
-    });
-  }, [filter]);
-
-  return (
-    <Card
-      title={intl.formatMessage({
-        id: `columns.studio.channel.title`,
-      })}
-      size="small"
-    >
-      <List
-        itemLayout="vertical"
-        size="small"
-        dataSource={tableData}
-        renderItem={(item) => (
-          <List.Item>
-            <Space>
-              <ChannelListItem channel={item.channel} studio={item.studio} />
-              <Tag>{item.count}</Tag>
-            </Space>
-          </List.Item>
-        )}
-      />
-    </Card>
-  );
-};
-
-export default ChannelListWidget;

+ 2 - 1
openapi/scripts/generate.php

@@ -317,7 +317,8 @@ function parseDocTags(array $tagLines): array
             $entry['enum'] = array_values(array_filter(array_map('trim', explode(',', $e[1]))));
             $rest = trim(str_replace($e[0], '', $rest));
         }
-        if (preg_match('/\bDefault:\s*((?:(?!\bExample:)[^.。\n])+)/u', $rest, $d)) {
+        // 「.」后面紧跟数字时是小数点不是句号(Default: 0.8),不能在那里截断
+        if (preg_match('/\bDefault:\s*((?:(?!\bExample:)(?:[^.。\n]|\.(?=\d)))+)/u', $rest, $d)) {
             $entry['default'] = castToType(trim($d[1]), $entry['type']);
             $rest = trim(str_replace($d[0], '', $rest));
         }