Skip to content

Commit

Permalink
fix can not add/update api when api ext content is not json format (#286
Browse files Browse the repository at this point in the history
)

* fix can not apply api when api ext content is not json format

* update api doc ui

* update api button i18n
  • Loading branch information
tomsun28 authored Jun 10, 2023
1 parent ac474fa commit cbe1ae4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 47 deletions.
69 changes: 35 additions & 34 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,23 @@
"SHENYU.DIC.INPUTNAME": "DictionaryName",
"SHENYU.PERMISSION.EMPTY":
"The role of the login user is not configured with menu permissions",
"SHENYU.BUTTON.PLUGIN.RULE.ADD": "addRule",
"SHENYU.BUTTON.PLUGIN.RULE.DELETE": "deleteRule",
"SHENYU.BUTTON.PLUGIN.RULE.EDIT": "editRule",
"SHENYU.BUTTON.PLUGIN.RULE.QUERY": "queryRule",
"SHENYU.BUTTON.PLUGIN.SELECTOR.ADD": "addSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.DELETE": "deleteSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.EDIT": "editSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY": "querySelector",
"SHENYU.BUTTON.PLUGIN.SYNCHRONIZE": "synchronizeData",
"SHENYU.BUTTON.SYSTEM.ADD": "add",
"SHENYU.BUTTON.SYSTEM.LIST": "query",
"SHENYU.BUTTON.SYSTEM.DELETE": "delete",
"SHENYU.BUTTON.SYSTEM.EDIT": "modify",
"SHENYU.BUTTON.SYSTEM.SYNCHRONIZE": "synchronize",
"SHENYU.BUTTON.SYSTEM.ENABLE": "enable",
"SHENYU.BUTTON.SYSTEM.EDITRESOURCEDETAILS": "editDetails",
"SHENYU.BUTTON.SYSTEM.RESOURCE": "resource",
"SHENYU.BUTTON.PLUGIN.RULE.ADD": "AddRule",
"SHENYU.BUTTON.PLUGIN.RULE.DELETE": "DeleteRule",
"SHENYU.BUTTON.PLUGIN.RULE.EDIT": "EditRule",
"SHENYU.BUTTON.PLUGIN.RULE.QUERY": "QueryRule",
"SHENYU.BUTTON.PLUGIN.SELECTOR.ADD": "AddSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.DELETE": "DeleteSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.EDIT": "EditSelector",
"SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY": "QuerySelector",
"SHENYU.BUTTON.PLUGIN.SYNCHRONIZE": "SynchronizeData",
"SHENYU.BUTTON.SYSTEM.ADD": "Add",
"SHENYU.BUTTON.SYSTEM.LIST": "Query",
"SHENYU.BUTTON.SYSTEM.DELETE": "Delete",
"SHENYU.BUTTON.SYSTEM.EDIT": "Modify",
"SHENYU.BUTTON.SYSTEM.SYNCHRONIZE": "Synchronize",
"SHENYU.BUTTON.SYSTEM.ENABLE": "Enable",
"SHENYU.BUTTON.SYSTEM.EDITRESOURCEDETAILS": "EditDetails",
"SHENYU.BUTTON.SYSTEM.RESOURCE": "Resource",
"SHENYU.BUTTON.DATA.PERMISSION.CONFIG": "ConfigureDataPermission",
"SHENYU.MESSAGE.SESSION.INVALID": "Session is invalid",
"SHENYU.MESSAGE.SESSION.RELOGIN": "Please login in again",
Expand Down Expand Up @@ -319,23 +319,24 @@
"SHENYU.DOCUMENT.APIDOC.CONTENTS.TO.BE.SIGNED": "Contents To Be Signed",
"SHENYU.DOCUMENT.APIDOC.SIGNATURE": "Signature",
"SHENYU.DOCUMENT.APIDOC.ERROR.CODE.DETAILS": "Error Code Details",
"SHENYU.DOCUMENT.APIDOC.CONTEXTPATH": "contextPath",
"SHENYU.DOCUMENT.APIDOC.APIPATH": "apiPath",
"SHENYU.DOCUMENT.APIDOC.HTTPMETHOD": "httpMethod",
"SHENYU.DOCUMENT.APIDOC.CONSUME": "consume",
"SHENYU.DOCUMENT.APIDOC.PRODUCE": "produce",
"SHENYU.DOCUMENT.APIDOC.VERSION": "version",
"SHENYU.DOCUMENT.APIDOC.RPCTYPE": "rpcType",
"SHENYU.DOCUMENT.APIDOC.STATE": "state",
"SHENYU.DOCUMENT.APIDOC.EXT": "ext",
"SHENYU.DOCUMENT.APIDOC.APIOWNER": "apiOwner",
"SHENYU.DOCUMENT.APIDOC.APIDESC": "apiDesc",
"SHENYU.DOCUMENT.APIDOC.APISOURCE": "apiSource",
"SHENYU.DOCUMENT.APIDOC.DOCUMENT": "document",
"SHENYU.DOCUMENT.TAG.NAME": "name",
"SHENYU.DOCUMENT.TAG.DESC": "tagDesc",
"SHENYU.DOCUMENT.TAG.PARENT.ID": "parentTagId",
"SHENYU.DOCUMENT.TAG.ext": "ext",
"SHENYU.DOCUMENT.APIDOC.CONTEXTPATH": "Context Path",
"SHENYU.DOCUMENT.APIDOC.APIPATH": "Api Path",
"SHENYU.DOCUMENT.APIDOC.HTTPMETHOD": "Http Method",
"SHENYU.DOCUMENT.APIDOC.CONSUME": "Consume",
"SHENYU.DOCUMENT.APIDOC.PRODUCE": "Produce",
"SHENYU.DOCUMENT.APIDOC.VERSION": "Version",
"SHENYU.DOCUMENT.APIDOC.RPCTYPE": "Rpc Type",
"SHENYU.DOCUMENT.APIDOC.STATE": "State",
"SHENYU.DOCUMENT.APIDOC.EXT": "Extent Param",
"SHENYU.DOCUMENT.APIDOC.EXT.INFO": "Extend param content need json format",
"SHENYU.DOCUMENT.APIDOC.APIOWNER": "Api Owner",
"SHENYU.DOCUMENT.APIDOC.APIDESC": "Api Desc",
"SHENYU.DOCUMENT.APIDOC.APISOURCE": "Api Source",
"SHENYU.DOCUMENT.APIDOC.DOCUMENT": "Document",
"SHENYU.DOCUMENT.TAG.NAME": "Tag Name",
"SHENYU.DOCUMENT.TAG.DESC": "Tag Desc",
"SHENYU.DOCUMENT.TAG.PARENT.ID": "ParentTagId",
"SHENYU.DOCUMENT.TAG.ext": "Ext",
"SHENYU.COMMON.REQUIRED": "Required",
"SHENYU.COMMON.MAX.LENGTH": "Max Length",
"SHENYU.COMMON.MAX.EXAMPLE": "Example",
Expand Down
15 changes: 8 additions & 7 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,18 @@
"SHENYU.DOCUMENT.APIDOC.SIGNATURE": "签名(sign)",
"SHENYU.DOCUMENT.APIDOC.ERROR.CODE.DETAILS": "错误代码",
"SHENYU.DOCUMENT.APIDOC.CONTEXTPATH": "上下文路径",
"SHENYU.DOCUMENT.APIDOC.APIPATH": "api路径",
"SHENYU.DOCUMENT.APIDOC.HTTPMETHOD": "http方法",
"SHENYU.DOCUMENT.APIDOC.APIPATH": "Api路径",
"SHENYU.DOCUMENT.APIDOC.HTTPMETHOD": "Http方法",
"SHENYU.DOCUMENT.APIDOC.CONSUME": "消费",
"SHENYU.DOCUMENT.APIDOC.PRODUCE": "生产",
"SHENYU.DOCUMENT.APIDOC.VERSION": "版本",
"SHENYU.DOCUMENT.APIDOC.RPCTYPE": "rpc类型",
"SHENYU.DOCUMENT.APIDOC.RPCTYPE": "Rpc类型",
"SHENYU.DOCUMENT.APIDOC.STATE": "状态",
"SHENYU.DOCUMENT.APIDOC.EXT": "ext",
"SHENYU.DOCUMENT.APIDOC.APIOWNER": "api持有者",
"SHENYU.DOCUMENT.APIDOC.APIDESC": "api描述",
"SHENYU.DOCUMENT.APIDOC.APISOURCE": "api来源",
"SHENYU.DOCUMENT.APIDOC.EXT": "扩展参数",
"SHENYU.DOCUMENT.APIDOC.EXT.INFO": "扩展参数需要为JSON格式",
"SHENYU.DOCUMENT.APIDOC.APIOWNER": "Api持有者",
"SHENYU.DOCUMENT.APIDOC.APIDESC": "Api描述",
"SHENYU.DOCUMENT.APIDOC.APISOURCE": "Api来源",
"SHENYU.DOCUMENT.APIDOC.DOCUMENT": "文档说明",
"SHENYU.DOCUMENT.TAG.NAME": "标签名称",
"SHENYU.DOCUMENT.TAG.DESC": "标签描述",
Expand Down
27 changes: 21 additions & 6 deletions src/routes/Document/components/AddAndUpdateApiDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,29 @@ class AddAndUpdateApiDoc extends Component {
formLoaded?.(form);
}


handleSubmit = () => {
const { form, onOk } = this.props;
form.validateFieldsAndScroll(async (err, values) => {
function isJsonStr(str) {
try {
let obj = JSON.parse(str);
return !!(typeof obj === 'object' && obj);
} catch(e) {
return false;
}
}
if (!err) {
const { id } = values;
let res = {};
values.state = parseInt(values.state);
values.apiSource = parseInt(values.apiSource);
values.httpMethod = parseInt(values.httpMethod);
// validate ext
if (!isJsonStr(values.ext)) {
message.error(getIntlContent("SHENYU.DOCUMENT.APIDOC.EXT.INFO"));
return;
}
if (!id) {
res = await addApi({
...values
Expand Down Expand Up @@ -103,7 +117,7 @@ class AddAndUpdateApiDoc extends Component {
version = "",
rpcType = "",
state = "",
ext = "",
ext = "{}",
apiOwner = "",
apiDesc = "",
apiSource = "",
Expand All @@ -113,10 +127,10 @@ class AddAndUpdateApiDoc extends Component {
const { getFieldDecorator } = form;
const formItemLayout = {
labelCol: {
sm: { span: 5 }
sm: { span: 6 }
},
wrapperCol: {
sm: { span: 19 }
sm: { span: 18 }
}
};

Expand Down Expand Up @@ -290,7 +304,7 @@ class AddAndUpdateApiDoc extends Component {
</Radio.Button>
);
})}

</Radio.Group>
)}
</Form.Item>
Expand All @@ -302,13 +316,14 @@ class AddAndUpdateApiDoc extends Component {
rules: [
{
required: true,
message: getIntlContent("SHENYU.DOCUMENT.APIDOC.EXT")
message: getIntlContent("SHENYU.DOCUMENT.APIDOC.EXT.INFO")
}
],
initialValue: ext
})(
<Input
placeholder={getIntlContent("SHENYU.DOCUMENT.APIDOC.EXT")}
size="large"
placeholder={getIntlContent("SHENYU.DOCUMENT.APIDOC.EXT.INFO")}
/>
)}
</Form.Item>
Expand Down

0 comments on commit cbe1ae4

Please sign in to comment.