Skip to content

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.json
index 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.yaml
index 02b27f0462..caef0eb06e 100644
--- a/public/openapi/components/schemas/Chats.yaml
+++ b/public/openapi/components/schemas/Chats.yaml
@@ -2,7 +2,9 @@ RoomObject:
type: object
properties:
roomId:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
description: unique identifier for the chat room
roomName:
type: string
@@ -42,7 +44,9 @@ MessageObject:
fromuid:
type: number
roomId:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
deleted:
type: number
system:
diff --git a/public/openapi/components/schemas/FlagObject.yaml b/public/openapi/components/schemas/FlagObject.yaml
index 31fef07c21..611c9373ac 100644
--- a/public/openapi/components/schemas/FlagObject.yaml
+++ b/public/openapi/components/schemas/FlagObject.yaml
@@ -85,7 +85,9 @@ FlagHistoryObject:
type: object
properties:
uid:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
description: A user identifier
fields:
type: object
diff --git a/public/openapi/components/schemas/PostObject.yaml b/public/openapi/components/schemas/PostObject.yaml
index 60e0672538..3c0083531b 100644
--- a/public/openapi/components/schemas/PostObject.yaml
+++ b/public/openapi/components/schemas/PostObject.yaml
@@ -3,7 +3,9 @@ PostObject:
type: object
properties:
pid:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
tid:
type: number
description: 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:
+ - null
description: The post id of the teaser (the most recent post, depending on settings)
- nullable: true
titleRaw:
type: string
oldTitle:
diff --git a/public/openapi/components/schemas/PostsObject.yaml b/public/openapi/components/schemas/PostsObject.yaml
index 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: string
description: A post identifier
attachments:
type: array
diff --git a/public/openapi/components/schemas/TopicObject.yaml b/public/openapi/components/schemas/TopicObject.yaml
index 2d1aa9dcf6..b6149797f9 100644
--- a/public/openapi/components/schemas/TopicObject.yaml
+++ b/public/openapi/components/schemas/TopicObject.yaml
@@ -210,17 +210,22 @@ TopicObjectSlim:
votes:
type: number
teaserPid:
- oneOf:
+ anyOf:
- type: number
- type: string
- - type: 'null'
+ - type: string
+ nullable: true
+ enum:
+ - null
thumbs:
type: array
items:
type: object
properties:
id:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
description: The topic id
name:
type: string
diff --git a/public/openapi/read/admin/advanced/cache/dump.yaml b/public/openapi/read/admin/advanced/cache/dump.yaml
index 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 information
content:
application/json:
schema:
diff --git a/public/openapi/read/admin/manage/privileges/cid.yaml b/public/openapi/read/admin/manage/privileges/cid.yaml
index 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: object
properties:
cid:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
description: A category identifier
name:
type: string
diff --git a/public/openapi/read/post-queue.yaml b/public/openapi/read/post-queue.yaml
index b28ecbe83c..044f7fe010 100644
--- a/public/openapi/read/post-queue.yaml
+++ b/public/openapi/read/post-queue.yaml
@@ -125,8 +125,13 @@ get:
type: number
description: A topic identifier
toPid:
- type: [number, string]
- nullable: true
+ anyOf:
+ - type: number
+ - type: string
+ - type: string
+ nullable: true
+ enum:
+ - null
user:
type: object
properties:
diff --git a/public/openapi/write/chats/roomId/messages/mid/ip.yaml b/public/openapi/write/chats/roomId/messages/mid/ip.yaml
index 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: object
properties:
ip:
- type: ['string', 'null']
+ type: string
+ nullable: true
description: message IP address, or null if not available
\ No newline at end of file
diff --git a/public/openapi/write/posts/pid/diffs.yaml b/public/openapi/write/posts/pid/diffs.yaml
index 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: number
pid:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
timestamps:
type: array
items:
@@ -42,7 +44,9 @@ get:
username:
type: string
uid:
- type: [number, string]
+ oneOf:
+ - type: number
+ - type: string
editable:
type: boolean
deletable:
diff --git a/public/openapi/write/posts/pid/replies.yaml b/public/openapi/write/posts/pid/replies.yaml
index 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: string
description: HTML that is injected into `topic.tpl` of themes that support custom profile info
editor:
- type: [number, string]
- nullable: true
+ anyOf:
+ - type: number
+ - type: string
+ - type: string
+ nullable: true
+ enum:
+ - null
bookmarked:
type: boolean
upvoted:
diff --git a/test/api.js b/test/api.js
index 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 data
const { 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.js
index 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 () {