wip
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
project: ['./tsconfig.json', './test/tsconfig.json'],
|
||||
},
|
||||
extends: [
|
||||
'../shared/.eslintrc.js',
|
||||
|
@@ -26,6 +26,7 @@
|
||||
"@types/node": "18.16.3",
|
||||
"@typescript-eslint/eslint-plugin": "5.59.5",
|
||||
"@typescript-eslint/parser": "5.59.5",
|
||||
"ajv": "8.12.0",
|
||||
"eslint": "8.40.0",
|
||||
"jest": "29.5.0",
|
||||
"jest-fetch-mock": "3.0.3",
|
||||
|
@@ -446,3 +446,17 @@ export const endpoints = {
|
||||
}],
|
||||
},
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) {
|
||||
const endpoint = endpoints[key];
|
||||
const schemas = endpoint.defines.map(d => d[reqres]).filter(d => d !== undefined);
|
||||
if (schemas.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (schemas.length === 1) {
|
||||
return schemas[0];
|
||||
}
|
||||
return {
|
||||
oneOf: schemas,
|
||||
};
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ import Stream, { Connection } from './streaming.js';
|
||||
import { Channels } from './streaming.types.js';
|
||||
import { Acct } from './acct.js';
|
||||
import type { Packed, Def } from './schemas.js';
|
||||
import { refs as _refs } from './schemas.js';
|
||||
import * as consts from './consts.js';
|
||||
|
||||
export {
|
||||
@@ -15,8 +14,6 @@ export {
|
||||
Packed, Def,
|
||||
};
|
||||
|
||||
export const refs = _refs;
|
||||
|
||||
export const permissions = consts.permissions;
|
||||
export const notificationTypes = consts.notificationTypes;
|
||||
export const obsoleteNotificationTypes = consts.obsoleteNotificationTypes;
|
||||
|
@@ -1,5 +1,31 @@
|
||||
import { enableFetchMocks } from 'jest-fetch-mock';
|
||||
import { APIClient, isAPIError } from '../src/api';
|
||||
import Ajv from 'ajv';
|
||||
import { endpoints, getEndpointSchema } from '../src/endpoints';
|
||||
import { Endpoints } from '@/endpoints.types';
|
||||
|
||||
describe('schemas', () => {
|
||||
describe.each(Object.keys(endpoints))('validate schema of %s', async (key) => {
|
||||
const ajv = new Ajv({
|
||||
useDefaults: true,
|
||||
});
|
||||
|
||||
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
|
||||
|
||||
const endpoint = (endpoints as any)[key] as unknown as Endpoints[keyof Endpoints];
|
||||
test('each schemas', async () => {
|
||||
for (const def of endpoint.defines) {
|
||||
if (def.res === undefined) continue;
|
||||
ajv.compile(def.req);
|
||||
}
|
||||
});
|
||||
|
||||
test('jointed schema (oneOf)', () => {
|
||||
const req = getEndpointSchema('req', key as keyof Endpoints);
|
||||
if (req) ajv.compile(req);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
enableFetchMocks();
|
||||
|
||||
|
42
packages/misskey-js/test/tsconfig.json
Normal file
42
packages/misskey-js/test/tsconfig.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"noEmitOnError": false,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedParameters": false,
|
||||
"noUnusedLocals": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"declaration": false,
|
||||
"sourceMap": true,
|
||||
"target": "es2021",
|
||||
"module": "es2020",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@/*": ["../src/*"]
|
||||
},
|
||||
"typeRoots": [
|
||||
"../node_modules/@types",
|
||||
"../src/@types"
|
||||
],
|
||||
"lib": [
|
||||
"esnext"
|
||||
],
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"compileOnSave": false,
|
||||
"include": [
|
||||
"./**/*.ts",
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user