فهرست منبع

Merge pull request #230 from smiclea/required-default

Set default value if field is required CORWEB-172
Dorin Paslaru 8 سال پیش
والد
کامیت
db6ade19f9
2فایلهای تغییر یافته به همراه7 افزوده شده و 1 حذف شده
  1. 1 1
      src/components/pages/EndpointsPage/index.jsx
  2. 6 0
      src/plugins/endpoint/default/SchemaPlugin.js

+ 1 - 1
src/components/pages/EndpointsPage/index.jsx

@@ -253,7 +253,7 @@ class EndpointsPage extends React.Component<{}, State> {
     if ((filterItem !== 'all' && (endpoint.type !== filterItem)) ||
       (endpoint.name.toLowerCase().indexOf(filterText || '') === -1 &&
         // $FlowIssue
-        endpoint.description.toLowerCase().indexOf(filterText) === -1)
+        (!endpoint.description || endpoint.description.toLowerCase().indexOf(filterText) === -1))
     ) {
       return false
     }

+ 6 - 0
src/plugins/endpoint/default/SchemaPlugin.js

@@ -83,6 +83,12 @@ export const fieldsToPayload = (data: { [string]: mixed }, schema: SchemaPropert
   Object.keys(schema.properties).forEach(fieldName => {
     if (data[fieldName] && typeof data[fieldName] !== 'object') {
       info[fieldName] = data[fieldName]
+    } else if (
+      !data[fieldName] &&
+      schema.required && schema.required.find(f => f === fieldName) &&
+      schema.properties[fieldName].default
+    ) {
+      info[fieldName] = schema.properties[fieldName].default
     }
   })