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} 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 },
});
},
);

View file

@ -1,7 +1,6 @@
#!/bin/env python3
import argparse
import esprima
import json
import logging
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 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/