فهرست منبع

validation and swagger

itizawa 6 سال پیش
والد
کامیت
119fab093b
1فایلهای تغییر یافته به همراه34 افزوده شده و 2 حذف شده
  1. 34 2
      src/server/routes/apiv3/security-setting.js

+ 34 - 2
src/server/routes/apiv3/security-setting.js

@@ -20,6 +20,12 @@ const validator = {
     body('hideRestrictedByOwner').isBoolean(),
     body('hideRestrictedByGroup').isBoolean(),
   ],
+  authenticationSetting: [
+    body('isEnabled').isBoolean(),
+    body('target').isString().isIn([
+      'local', 'ldap', 'saml', 'oidc', 'basic', 'google', 'github', 'twitter',
+    ]),
+  ],
   localSetting: [
     body('isLocalEnabled').isBoolean(),
     body('registrationMode').isString(),
@@ -393,8 +399,34 @@ module.exports = (crowi) => {
     return res.apiv3({ securityParams });
   });
 
-  // TODO swagger
-  router.put('/authentication', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+  /**
+   * @swagger
+   *
+   *    /_api/v3/security-setting/authentication:
+   *      put:
+   *        tags: [SecuritySetting]
+   *        description: Update authentication isEnabled
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schema:
+   *                type: object
+   *                properties:
+   *                  isEnabled:
+   *                    type: boolean
+   *                  target:
+   *                    type: string
+   *        responses:
+   *          200:
+   *            description: Succeeded to enable authentication
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  type: object
+   *                  description: updated param
+   */
+  router.put('/authentication', loginRequiredStrictly, adminRequired, csrf, validator.authenticationSetting, ApiV3FormValidator, async(req, res) => {
     const { isEnabled, target } = req.body;
 
     let setupStrategies = await crowi.passportService.getSetupStrategies();