Fixed generating API docs and Wekan Custom Fields REST API.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2021-03-07 17:57:24 +02:00
parent e16b06b44a
commit 0bb3b67075
3 changed files with 46 additions and 40 deletions

View file

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

View file

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

View file

@ -1,21 +1,15 @@
# Generate docs. # Extract the OpenAPI specification.
# extract the OpenAPI specification # Install dependencies.
sudo apt-get install python3-pip sudo apt-get install python3-pip
sudo pip3 install -U setuptools wheel sudo pip3 install -U setuptools wheel
sudo npm install -g api2html@0.3.3 sudo npm install -g api2html
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
cd ~/repos/wekan cd ~/repos/wekan
mkdir -p public/api mkdir -p public/api
# Generate docs.
python3 ./openapi/generate_openapi.py --release $(git describe --tags --abbrev=0) > ./public/api/wekan.yml 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 api2html -c ./public/logo-header.png -o ./public/api/wekan.html ./public/api/wekan.yml
# Copy docs to bundle # 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/app/
#cp -pR ./public/api ~/repos/wekan/.build/bundle/programs/web.browser.legacy/app/