Bläddra i källkod

Fixed generating API docs and Wekan Custom Fields REST API.

Thanks to xet7 !
Lauri Ojansivu 4 år sedan
förälder
incheckning
0bb3b67075
3 ändrade filer med 46 tillägg och 40 borttagningar
  1. 41 28
      models/customFields.js
  2. 0 1
      openapi/generate_openapi.py
  3. 5 11
      releases/rebuild-docs-install-deps.sh

+ 41 - 28
models/customFields.js

@@ -307,7 +307,8 @@ if (Meteor.isServer) {
    *
    * @param {string} boardID the ID of the board
    * @param {string} customFieldId the ID of the custom field
-   * @return_type CustomFields
+   * @return_type [{_id: string,
+   *                boardIds: string}]
    */
   JsonRoutes.add(
     'GET',
@@ -377,9 +378,9 @@ if (Meteor.isServer) {
    * @param {string} name the name of the custom field
    * @param {string} type the type of the custom field
    * @param {string} settings the settings object of the custom field
-   * @param {boolean} showOnCard should we show the custom field on cards?
-   * @param {boolean} automaticallyOnCard should the custom fields automatically be added on cards?
-   * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards?
+   * @param {boolean} showOnCard should we show the custom field on cards
+   * @param {boolean} automaticallyOnCard should the custom fields automatically be added on cards
+   * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards
    * @return_type {_id: string}
    */
   JsonRoutes.add(
@@ -444,7 +445,7 @@ if (Meteor.isServer) {
    * @operation add_custom_field_dropdown_items
    * @summary Update a Custom Field's dropdown items
    *
-   * @param {string[]} items names of the custom field
+   * @param {string} [items] names of the custom field
    * @return_type {_id: string}
    */
   JsonRoutes.add(
@@ -453,27 +454,32 @@ if (Meteor.isServer) {
     (req, res) => {
       Authentication.checkUserId(req.userId);
 
-      if (req.body.hasOwnProperty('items') && Array.isArray(req.body.items)) {
-        CustomFields.direct.update(
-          { _id: req.params.customFieldId },
-          {
-            $push: {
-              'settings.dropdownItems': {
-                $each: req.body.items
-                  .filter(name => typeof name === 'string')
-                  .map(name => ({
-                    _id: Random.id(6),
-                    name,
-                  })),
+      const paramCustomFieldId = req.params.customFieldId;
+      const paramItems = req.body.items;
+
+      if (req.body.hasOwnProperty('items')) {
+        if (Array.isArray(paramItems)) {
+          CustomFields.direct.update(
+            { _id: paramCustomFieldId },
+            {
+              $push: {
+                'settings.dropdownItems': {
+                  $each: paramItems
+                    .filter(name => typeof name === 'string')
+                    .map(name => ({
+                      _id: Random.id(6),
+                      name,
+                    })),
+                },
               },
             },
-          },
-        );
+          );
+        }
       }
 
       JsonRoutes.sendResult(res, {
         code: 200,
-        data: { _id: req.params.customFieldId },
+        data: { _id: paramCustomFieldId },
       });
     },
   );
@@ -491,17 +497,21 @@ if (Meteor.isServer) {
     (req, res) => {
       Authentication.checkUserId(req.userId);
 
+      const paramDropdownItemId = req.params.dropdownItemId;
+      const paramCustomFieldId = req.params.customFieldId;
+      const paramName = req.body.name;
+
       if (req.body.hasOwnProperty('name')) {
         CustomFields.direct.update(
           {
-            _id: req.params.customFieldId,
-            'settings.dropdownItems._id': req.params.dropdownItemId,
+            _id: paramCustomFieldId,
+            'settings.dropdownItems._id': paramDropdownItemId,
           },
           {
             $set: {
               'settings.dropdownItems.$': {
-                _id: req.params.dropdownItemId,
-                name: req.body.name,
+                _id: paramDropdownItemId,
+                name: paramName,
               },
             },
           },
@@ -510,7 +520,7 @@ if (Meteor.isServer) {
 
       JsonRoutes.sendResult(res, {
         code: 200,
-        data: { _id: req.params.customFieldId },
+        data: { _id: customFieldId },
       });
     },
   );
@@ -528,18 +538,21 @@ if (Meteor.isServer) {
     (req, res) => {
       Authentication.checkUserId(req.userId);
 
+      paramCustomFieldId = req.params.customFieldId;
+      paramDropdownItemId = req.params.dropdownItemId;
+
       CustomFields.direct.update(
-        { _id: req.params.customFieldId },
+        { _id: paramCustomFieldId },
         {
           $pull: {
-            'settings.dropdownItems': { _id: req.params.dropdownItemId },
+            'settings.dropdownItems': { _id: paramDropdownItemId },
           },
         },
       );
 
       JsonRoutes.sendResult(res, {
         code: 200,
-        data: { _id: req.params.customFieldId },
+        data: { _id: paramCustomFieldId },
       });
     },
   );

+ 0 - 1
openapi/generate_openapi.py

@@ -1,7 +1,6 @@
 #!/bin/env python3
 
 import argparse
-import esprima
 import json
 import logging
 import os

+ 5 - 11
releases/rebuild-docs-install-deps.sh

@@ -1,21 +1,15 @@
-# Generate docs.
+# Extract the OpenAPI specification.
 
-# extract the OpenAPI specification
+# Install dependencies.
 sudo apt-get install python3-pip
 sudo pip3 install -U setuptools wheel
-sudo npm install -g api2html@0.3.3
-sudo npm install -g --unsafe-perm api2html@0.3.0
-sudo npm install -g --unsafe-perm mkdirp
-mkdir -p ~/python
-cd ~/python
-git clone --depth 1 -b master https://github.com/Kronuz/esprima-python
-cd ~/python/esprima-python
-sudo python3 setup.py install --record files.txt
+sudo npm install -g api2html
 cd ~/repos/wekan
 mkdir -p public/api
+
+# Generate docs.
 python3 ./openapi/generate_openapi.py --release $(git describe --tags --abbrev=0) > ./public/api/wekan.yml
 api2html -c ./public/logo-header.png -o ./public/api/wekan.html ./public/api/wekan.yml
 
 # Copy docs to bundle
 #cp -pR ./public/api ~/repos/wekan/.build/bundle/programs/web.browser/app/
-#cp -pR ./public/api ~/repos/wekan/.build/bundle/programs/web.browser.legacy/app/