Node.js based forum software built for the modern web
refactor: update swagger parser to 13.0.0 (#14771)
Barış Uşaklıe683f0fb6cec
diff --git a/install/package.json b/install/package.jsonindex 846ae3d63f..bdb0f9a07b 100644--- a/install/package.json+++ b/install/package.json@@ -167,7 +167,7 @@"zxcvbn": "4.4.2"},"devDependencies": {- "@apidevtools/swagger-parser": "10.1.0",+ "@apidevtools/swagger-parser": "13.0.0","@commitlint/cli": "21.2.2","@commitlint/config-angular": "21.2.2","coveralls": "3.1.1",diff --git a/public/openapi/components/schemas/Chats.yaml b/public/openapi/components/schemas/Chats.yamlindex 02b27f0462..caef0eb06e 100644--- a/public/openapi/components/schemas/Chats.yaml+++ b/public/openapi/components/schemas/Chats.yaml@@ -2,7 +2,9 @@ RoomObject:type: objectproperties:roomId:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdescription: unique identifier for the chat roomroomName:type: string@@ -42,7 +44,9 @@ MessageObject:fromuid:type: numberroomId:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdeleted:type: numbersystem:diff --git a/public/openapi/components/schemas/FlagObject.yaml b/public/openapi/components/schemas/FlagObject.yamlindex 31fef07c21..611c9373ac 100644--- a/public/openapi/components/schemas/FlagObject.yaml+++ b/public/openapi/components/schemas/FlagObject.yaml@@ -85,7 +85,9 @@ FlagHistoryObject:type: objectproperties:uid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdescription: A user identifierfields:type: objectdiff --git a/public/openapi/components/schemas/PostObject.yaml b/public/openapi/components/schemas/PostObject.yamlindex 60e0672538..3c0083531b 100644--- a/public/openapi/components/schemas/PostObject.yaml+++ b/public/openapi/components/schemas/PostObject.yaml@@ -3,7 +3,9 @@ PostObject:type: objectproperties:pid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringtid:type: numberdescription: A topic identifier@@ -107,9 +109,14 @@ PostObject:description: The post id of the first post in this topic (also called the"original post")teaserPid:- type: [number, string]+ anyOf:+ - type: number+ - type: string+ - type: string+ nullable: true+ enum:+ - nulldescription: The post id of the teaser (the most recent post, depending on settings)- nullable: truetitleRaw:type: stringoldTitle:diff --git a/public/openapi/components/schemas/PostsObject.yaml b/public/openapi/components/schemas/PostsObject.yamlindex 546ff704f1..5f2847dc9d 100644--- a/public/openapi/components/schemas/PostsObject.yaml+++ b/public/openapi/components/schemas/PostsObject.yaml@@ -8,7 +8,9 @@ PostsObject:description: Optional properties that may or may not be present (except for `pid`, which is always present, and is only here as a hack to pass validation)properties:pid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdescription: A post identifierattachments:type: arraydiff --git a/public/openapi/components/schemas/TopicObject.yaml b/public/openapi/components/schemas/TopicObject.yamlindex 2d1aa9dcf6..b6149797f9 100644--- a/public/openapi/components/schemas/TopicObject.yaml+++ b/public/openapi/components/schemas/TopicObject.yaml@@ -210,17 +210,22 @@ TopicObjectSlim:votes:type: numberteaserPid:- oneOf:+ anyOf:- type: number- type: string- - type: 'null'+ - type: string+ nullable: true+ enum:+ - nullthumbs:type: arrayitems:type: objectproperties:id:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdescription: The topic idname:type: stringdiff --git a/public/openapi/read/admin/advanced/cache/dump.yaml b/public/openapi/read/admin/advanced/cache/dump.yamlindex 2fc47d7fc7..49cc7344d5 100644--- a/public/openapi/read/admin/advanced/cache/dump.yaml+++ b/public/openapi/read/admin/advanced/cache/dump.yaml@@ -13,6 +13,7 @@ get:example: 'post'responses:"200":+ description: System cache informationcontent:application/json:schema:diff --git a/public/openapi/read/admin/manage/privileges/cid.yaml b/public/openapi/read/admin/manage/privileges/cid.yamlindex 50e8ceb8ff..bbee7ecc73 100644--- a/public/openapi/read/admin/manage/privileges/cid.yaml+++ b/public/openapi/read/admin/manage/privileges/cid.yaml@@ -88,7 +88,9 @@ get:type: objectproperties:cid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringdescription: A category identifiername:type: stringdiff --git a/public/openapi/read/post-queue.yaml b/public/openapi/read/post-queue.yamlindex b28ecbe83c..044f7fe010 100644--- a/public/openapi/read/post-queue.yaml+++ b/public/openapi/read/post-queue.yaml@@ -125,8 +125,13 @@ get:type: numberdescription: A topic identifiertoPid:- type: [number, string]- nullable: true+ anyOf:+ - type: number+ - type: string+ - type: string+ nullable: true+ enum:+ - nulluser:type: objectproperties:diff --git a/public/openapi/write/chats/roomId/messages/mid/ip.yaml b/public/openapi/write/chats/roomId/messages/mid/ip.yamlindex fa16cf9a25..f75e6cad52 100644--- a/public/openapi/write/chats/roomId/messages/mid/ip.yaml+++ b/public/openapi/write/chats/roomId/messages/mid/ip.yaml@@ -32,5 +32,6 @@ get:type: objectproperties:ip:- type: ['string', 'null']+ type: string+ nullable: truedescription: message IP address, or null if not available\ No newline at end of filediff --git a/public/openapi/write/posts/pid/diffs.yaml b/public/openapi/write/posts/pid/diffs.yamlindex 929e92e543..0b07dbfdc8 100644--- a/public/openapi/write/posts/pid/diffs.yaml+++ b/public/openapi/write/posts/pid/diffs.yaml@@ -27,7 +27,9 @@ get:uid:type: numberpid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringtimestamps:type: arrayitems:@@ -42,7 +44,9 @@ get:username:type: stringuid:- type: [number, string]+ oneOf:+ - type: number+ - type: stringeditable:type: booleandeletable:diff --git a/public/openapi/write/posts/pid/replies.yaml b/public/openapi/write/posts/pid/replies.yamlindex bf4140f80b..070ce6062d 100644--- a/public/openapi/write/posts/pid/replies.yaml+++ b/public/openapi/write/posts/pid/replies.yaml@@ -155,8 +155,13 @@ get:type: stringdescription: HTML that is injected into `topic.tpl` of themes that support custom profile infoeditor:- type: [number, string]- nullable: true+ anyOf:+ - type: number+ - type: string+ - type: string+ nullable: true+ enum:+ - nullbookmarked:type: booleanupvoted:diff --git a/test/api.js b/test/api.jsindex 960ba08c8c..6bdfbf0954 100644--- a/test/api.js+++ b/test/api.js@@ -3,48 +3,35 @@const _ = require('lodash');const assert = require('assert');const path = require('path');-const fs = require('fs');const SwaggerParser = require('@apidevtools/swagger-parser');-const nconf = require('nconf');-const jwt = require('jsonwebtoken');-const util = require('util');--const wait = util.promisify(setTimeout);--const db = require('./mocks/databasemock');-const request = require('../src/request');-const helpers = require('./helpers');-const meta = require('../src/meta');const file = require('../src/file');-const user = require('../src/user');-const groups = require('../src/groups');-const categories = require('../src/categories');-const topics = require('../src/topics');-const posts = require('../src/posts');-const plugins = require('../src/plugins');-const flags = require('../src/flags');-const messaging = require('../src/messaging');-const activitypub = require('../src/activitypub');-const notifications = require('../src/notifications');-const utils = require('../src/utils');-const api = require('../src/api');// Bootstrap schema test dataconst { execSync } = require('child_process');execSync('node ./test/api/schema-bootstrap.mjs');+async function runWithoutWindow(fn, filePath) {+ const window = global.window;+ try {+ delete global.window;+ return await fn(filePath);+ } finally {+ global.window = window;+ }+}+describe('API', async () => {before(async function () {this.readApiPath = path.resolve(__dirname, '../public/openapi/read.yaml');this.writeApiPath = path.resolve(__dirname, '../public/openapi/write.yaml');- this.readApi = await SwaggerParser.dereference(this.readApiPath);- this.writeApi = await SwaggerParser.dereference(this.writeApiPath);+ this.readApi = await runWithoutWindow(SwaggerParser.dereference, this.readApiPath);+ this.writeApi = await runWithoutWindow(SwaggerParser.dereference, this.writeApiPath);});- it.skip('should pass OpenAPI v3 validation', async function () {+ it('should pass OpenAPI v3 validation', async function () {try {- await SwaggerParser.validate(this.readApiPath);- await SwaggerParser.validate(this.writeApiPath);+ await runWithoutWindow(SwaggerParser.validate, this.readApiPath);+ await runWithoutWindow(SwaggerParser.validate, this.writeApiPath);} catch (e) {assert.ifError(e);}diff --git a/test/api/routes.js b/test/api/routes.jsindex b03f66c6bd..5a5f7c6b05 100644--- a/test/api/routes.js+++ b/test/api/routes.js@@ -11,12 +11,22 @@ const db = require('../mocks/databasemock');let readApi;let writeApi;+async function parseApi(filePath) {+ const window = global.window;+ try {+ delete global.window;+ return await SwaggerParser.dereference(filePath);+ } finally {+ global.window = window;+ }+}+describe('routes', function () {before(async function () {const readApiPath = path.resolve(__dirname, '../../public/openapi/read.yaml');const writeApiPath = path.resolve(__dirname, '../../public/openapi/write.yaml');- readApi = await SwaggerParser.dereference(readApiPath);- writeApi = await SwaggerParser.dereference(writeApiPath);+ readApi = await parseApi(readApiPath);+ writeApi = await parseApi(writeApiPath);});it('should grab all mounted routes and ensure a schema exists', async function () {