enhance: api.jsonのレスポンスの内容を実際の内容に合わせる (#12723)

* Create packedAdSchema

* admin/emoji/add

* admin/get-user-ips

* admin/roles/users

* admin/get-index-stats

* admin/accounts/find-by-email

* fix type of admin/ad/list

* federation/stats

* endpoints

* get-online-users-count

* i/2fa/register-key

* i/2fa/key-done

* i/2fa/register

* i/apps

* i/authorized-apps

* i/registry/get-all

* i/registry/get

* i/registry/get-detail

* i/registry/key-with-type

* i/registry/scopes-with-domain

* i/update-email

* i/move

* i/webhooks/create

* fix miss type

* i/webhooks/show

* i/webhooks/list

* flash/create

* roles/users

* server-info

* test

* users/lists/get-memberships

* users/achievements

* fetch-rss

* fetch-external-resources
This commit is contained in:
GrapeApple0 2023-12-21 16:57:05 +09:00 committed by GitHub
parent 07d4632cd7
commit 79ca93cefb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 822 additions and 7 deletions

View File

@ -38,6 +38,7 @@ import { packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
import { packedSigninSchema } from '@/models/json-schema/signin.js';
import { packedRoleLiteSchema, packedRoleSchema } from '@/models/json-schema/role.js';
import { packedAdSchema } from '@/models/json-schema/ad.js';
export const refs = {
UserLite: packedUserLiteSchema,
@ -49,6 +50,7 @@ export const refs = {
User: packedUserSchema,
UserList: packedUserListSchema,
Ad: packedAdSchema,
Announcement: packedAnnouncementSchema,
App: packedAppSchema,
Note: packedNoteSchema,

View File

@ -0,0 +1,64 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
export const packedAdSchema = {
type: 'object',
properties: {
id: {
type: 'string',
optional: false,
nullable: false,
format: 'id',
example: 'xxxxxxxxxx',
},
expiresAt: {
type: 'string',
optional: false,
nullable: false,
format: 'date-time',
},
startsAt: {
type: 'string',
optional: false,
nullable: false,
format: 'date-time',
},
place: {
type: 'string',
optional: false,
nullable: false,
},
priority: {
type: 'string',
optional: false,
nullable: false,
},
ratio: {
type: 'number',
optional: false,
nullable: false,
},
url: {
type: 'string',
optional: false,
nullable: false,
},
imageUrl: {
type: 'string',
optional: false,
nullable: false,
},
memo: {
type: 'string',
optional: false,
nullable: false,
},
dayOfWeek: {
type: 'integer',
optional: false,
nullable: false,
},
},
} as const;

View File

@ -25,6 +25,11 @@ export const meta = {
id: 'cb865949-8af5-4062-a88c-ef55e8786d1d',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'User',
},
} as const;
export const paramDef = {

View File

@ -17,6 +17,12 @@ export const meta = {
requireCredential: true,
requireModerator: true,
res: {
type: 'object',
optional: false,
nullable: false,
ref: 'Ad',
},
} as const;
export const paramDef = {
@ -63,7 +69,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
ad: ad,
});
return ad;
return {
id: ad.id,
expiresAt: ad.expiresAt.toISOString(),
startsAt: ad.startsAt.toISOString(),
dayOfWeek: ad.dayOfWeek,
url: ad.url,
imageUrl: ad.imageUrl,
priority: ad.priority,
ratio: ad.ratio,
place: ad.place,
memo: ad.memo,
};
});
}
}

View File

@ -16,6 +16,17 @@ export const meta = {
requireCredential: true,
requireModerator: true,
res: {
type: 'array',
optional: false,
nullable: false,
items: {
type: 'object',
optional: false,
nullable: false,
ref: 'Ad',
},
},
} as const;
export const paramDef = {
@ -46,7 +57,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const ads = await query.limit(ps.limit).getMany();
return ads;
return ads.map(ad => ({
id: ad.id,
expiresAt: ad.expiresAt.toISOString(),
startsAt: ad.startsAt.toISOString(),
dayOfWeek: ad.dayOfWeek,
url: ad.url,
imageUrl: ad.imageUrl,
memo: ad.memo,
place: ad.place,
priority: ad.priority,
ratio: ad.ratio,
}));
});
}
}

View File

@ -31,6 +31,8 @@ export const meta = {
id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975',
},
},
ref: 'EmojiDetailed',
} as const;
export const paramDef = {

View File

@ -15,6 +15,16 @@ export const meta = {
kind: 'read:admin',
tags: ['admin'],
res: {
type: 'array',
items: {
type: 'object',
properties: {
tablename: { type: 'string' },
indexname: { type: 'string' },
},
},
},
} as const;
export const paramDef = {

View File

@ -16,6 +16,25 @@ export const meta = {
requireCredential: true,
requireModerator: true,
res: {
type: 'array',
optional: false,
nullable: false,
items: {
type: 'object',
optional: false,
nullable: false,
properties: {
ip: { type: 'string' },
createdAt: {
type: 'string',
optional: false,
nullable: false,
format: 'date-time',
},
},
},
}
} as const;
export const paramDef = {

View File

@ -28,6 +28,20 @@ export const meta = {
id: '224eff5e-2488-4b18-b3e7-f50d94421648',
},
},
res: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },
createdAt: { type: 'string', format: 'date-time' },
user: { ref: 'UserDetailed' },
expiresAt: { type: 'string', format: 'date-time', nullable: true },
},
required: ['id', 'createdAt', 'user'],
},
}
} as const;
export const paramDef = {
@ -80,7 +94,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
id: assign.id,
createdAt: this.idService.parse(assign.id).date.toISOString(),
user: await this.userEntityService.pack(assign.user!, me, { detail: true }),
expiresAt: assign.expiresAt,
expiresAt: assign.expiresAt?.toISOString() ?? null,
})));
});
}

View File

@ -11,6 +11,23 @@ export const meta = {
requireCredential: false,
tags: ['meta'],
res: {
type: 'object',
nullable: true,
properties: {
params: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
type: { type: 'string' },
},
},
},
},
},
} as const;
export const paramDef = {

View File

@ -18,6 +18,92 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
res: {
type: 'object',
optional: false,
nullable: false,
properties: {
topSubInstances: {
type: 'array',
optional: false,
nullable: false,
items: {
properties: {
id: { type: 'string' },
firstRetrievedAt: { type: 'string' },
host: { type: 'string' },
usersCount: { type: 'number' },
notesCount: { type: 'number' },
followingCount: { type: 'number' },
followersCount: { type: 'number' },
isNotResponding: { type: 'boolean' },
isSuspended: { type: 'boolean' },
isBlocked: { type: 'boolean' },
softwareName: { type: 'string' },
softwareVersion: { type: 'string' },
openRegistrations: { type: 'boolean' },
name: { type: 'string' },
description: { type: 'string' },
maintainerName: { type: 'string' },
maintainerEmail: { type: 'string' },
isSilenced: { type: 'boolean' },
iconUrl: { type: 'string' },
faviconUrl: { type: 'string' },
themeColor: { type: 'string' },
infoUpdatedAt: {
type: 'string',
nullable: true,
},
latestRequestReceivedAt: {
type: 'string',
nullable: true,
},
}
},
},
otherFollowersCount: { type: 'number' },
topPubInstances: {
type: 'array',
optional: false,
nullable: false,
items: {
properties: {
id: { type: 'string' },
firstRetrievedAt: { type: 'string' },
host: { type: 'string' },
usersCount: { type: 'number' },
notesCount: { type: 'number' },
followingCount: { type: 'number' },
followersCount: { type: 'number' },
isNotResponding: { type: 'boolean' },
isSuspended: { type: 'boolean' },
isBlocked: { type: 'boolean' },
softwareName: { type: 'string' },
softwareVersion: { type: 'string' },
openRegistrations: { type: 'boolean' },
name: { type: 'string' },
description: { type: 'string' },
maintainerName: { type: 'string' },
maintainerEmail: { type: 'string' },
isSilenced: { type: 'boolean' },
iconUrl: { type: 'string' },
faviconUrl: { type: 'string' },
themeColor: { type: 'string' },
infoUpdatedAt: {
type: 'string',
nullable: true,
},
latestRequestReceivedAt: {
type: 'string',
nullable: true,
},
}
},
},
otherFollowingCount: { type: 'number' },
},
}
} as const;
export const paramDef = {

View File

@ -32,6 +32,18 @@ export const meta = {
id: '693ba8ba-b486-40df-a174-72f8279b56a4',
},
},
res: {
type: 'object',
properties: {
type: {
type: 'string',
},
data: {
type: 'string',
},
},
},
} as const;
export const paramDef = {

View File

@ -16,6 +16,18 @@ export const meta = {
requireCredential: false,
allowGet: true,
cacheSec: 60 * 3,
res: {
type: 'object',
properties: {
items: {
type: 'array',
items: {
type: 'object',
},
}
}
},
} as const;
export const paramDef = {

View File

@ -27,6 +27,12 @@ export const meta = {
errors: {
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Flash',
},
} as const;
export const paramDef = {

View File

@ -16,6 +16,16 @@ export const meta = {
requireCredential: false,
allowGet: true,
cacheSec: 60 * 1,
res: {
type: 'object',
optional: false, nullable: false,
properties: {
count: {
type: 'number',
nullable: false,
},
},
},
} as const;
export const paramDef = {

View File

@ -32,6 +32,16 @@ export const meta = {
id: '798d6847-b1ed-4f9c-b1f9-163c42655995',
},
},
res: {
type: 'object',
nullable: false,
optional: false,
properties: {
id: { type: 'string' },
name: { type: 'string' },
},
},
} as const;
export const paramDef = {

View File

@ -36,6 +36,140 @@ export const meta = {
id: 'bf32b864-449b-47b8-974e-f9a5468546f1',
},
},
res: {
type: 'object',
nullable: false,
optional: false,
properties: {
rp: {
type: 'object',
properties: {
id: {
type: 'string',
nullable: true,
},
},
},
user: {
type: 'object',
properties: {
id: {
type: 'string',
},
name: {
type: 'string',
},
displayName: {
type: 'string',
},
},
},
challenge: {
type: 'string',
},
pubKeyCredParams: {
type: 'array',
items: {
type: 'object',
properties: {
type: {
type: 'string',
},
alg: {
type: 'number',
},
},
},
},
timeout: {
type: 'number',
nullable: true,
},
excludeCredentials: {
type: 'array',
nullable: true,
items: {
type: 'object',
properties: {
id: {
type: 'string',
},
type: {
type: 'string',
},
transports: {
type: 'array',
items: {
type: 'string',
enum: [
"ble",
"cable",
"hybrid",
"internal",
"nfc",
"smart-card",
"usb",
],
},
},
},
},
},
authenticatorSelection: {
type: 'object',
nullable: true,
properties: {
authenticatorAttachment: {
type: 'string',
enum: [
"cross-platform",
"platform",
],
},
requireResidentKey: {
type: 'boolean',
},
userVerification: {
type: 'string',
enum: [
"discouraged",
"preferred",
"required",
],
},
},
},
attestation: {
type: 'string',
nullable: true,
enum: [
"direct",
"enterprise",
"indirect",
"none",
],
},
extensions: {
type: 'object',
nullable: true,
properties: {
appid: {
type: 'string',
nullable: true,
},
credProps: {
type: 'boolean',
nullable: true,
},
hmacCreateSecret: {
type: 'boolean',
nullable: true,
},
},
},
},
},
} as const;
export const paramDef = {

View File

@ -26,6 +26,19 @@ export const meta = {
id: '78d6c839-20c9-4c66-b90a-fc0542168b48',
},
},
res: {
type: 'object',
nullable: false,
optional: false,
properties: {
qr: { type: 'string' },
url: { type: 'string' },
secret: { type: 'string' },
label: { type: 'string' },
issuer: { type: 'string' },
},
},
} as const;
export const paramDef = {

View File

@ -13,6 +13,37 @@ export const meta = {
requireCredential: true,
secure: true,
res: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id',
},
name: {
type: 'string',
},
createdAt: {
type: 'string',
format: 'date-time',
},
lastUsedAt: {
type: 'string',
format: 'date-time',
},
permission: {
type: 'array',
uniqueItems: true,
items: {
type: 'string'
},
}
},
},
},
} as const;
export const paramDef = {
@ -50,7 +81,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
id: token.id,
name: token.name ?? token.app?.name,
createdAt: this.idService.parse(token.id).date.toISOString(),
lastUsedAt: token.lastUsedAt,
lastUsedAt: token.lastUsedAt?.toISOString(),
permission: token.permission,
})));
});

View File

@ -14,6 +14,36 @@ export const meta = {
requireCredential: true,
secure: true,
res: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id',
},
name: {
type: 'string',
},
callbackUrl: {
type: 'string',
nullable: true,
},
permission: {
type: 'array',
uniqueItems: true,
items: {
type: 'string'
},
},
isAuthorized: {
type: 'boolean',
},
},
},
},
} as const;
export const paramDef = {

View File

@ -64,6 +64,10 @@ export const meta = {
id: 'b234a14e-9ebe-4581-8000-074b3c215962',
},
},
res: {
type: 'object',
},
} as const;
export const paramDef = {

View File

@ -9,6 +9,10 @@ import { RegistryApiService } from '@/core/RegistryApiService.js';
export const meta = {
requireCredential: true,
res: {
type: 'object',
},
} as const;
export const paramDef = {

View File

@ -18,6 +18,10 @@ export const meta = {
id: '97a1e8e7-c0f7-47d2-957a-92e61256e01a',
},
},
res: {
type: 'object',
}
} as const;
export const paramDef = {

View File

@ -18,6 +18,10 @@ export const meta = {
id: 'ac3ed68a-62f0-422b-a7bc-d5e09e8f6a6a',
},
},
res: {
type: 'object',
}
} as const;
export const paramDef = {

View File

@ -9,6 +9,10 @@ import { RegistryApiService } from '@/core/RegistryApiService.js';
export const meta = {
requireCredential: true,
res: {
type: 'object',
},
} as const;
export const paramDef = {

View File

@ -10,6 +10,28 @@ import { RegistryApiService } from '@/core/RegistryApiService.js';
export const meta = {
requireCredential: true,
secure: true,
res: {
type: 'array',
items: {
type: 'object',
properties: {
scopes: {
type: 'array',
items: {
type: 'array',
items: {
type: 'string',
}
}
},
domain: {
type: 'string',
nullable: true,
},
},
},
}
} as const;
export const paramDef = {

View File

@ -40,6 +40,11 @@ export const meta = {
id: 'a2defefb-f220-8849-0af6-17f816099323',
},
},
res: {
type: 'object',
ref: 'UserDetailed',
},
} as const;
export const paramDef = {

View File

@ -27,6 +27,33 @@ export const meta = {
id: '87a9bb19-111e-4e37-81d3-a3e7426453b0',
},
},
res: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id'
},
userId: {
type: 'string',
format: 'misskey:id',
},
name: { type: 'string' },
on: {
type: 'array',
items: {
type: 'string',
enum: webhookEventTypes,
}
},
url: { type: 'string' },
secret: { type: 'string' },
active: { type: 'boolean' },
latestSentAt: { type: 'string', format: 'date-time', nullable: true },
latestStatus: { type: 'integer', nullable: true },
},
},
} as const;
export const paramDef = {
@ -73,7 +100,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.globalEventService.publishInternalEvent('webhookCreated', webhook);
return webhook;
return {
id: webhook.id,
userId: webhook.userId,
name: webhook.name,
on: webhook.on,
url: webhook.url,
secret: webhook.secret,
active: webhook.active,
latestSentAt: webhook.latestSentAt?.toISOString(),
latestStatus: webhook.latestStatus,
};
});
}
}

View File

@ -5,6 +5,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { webhookEventTypes } from '@/models/Webhook.js';
import type { WebhooksRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
@ -14,6 +15,36 @@ export const meta = {
requireCredential: true,
kind: 'read:account',
res: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id'
},
userId: {
type: 'string',
format: 'misskey:id',
},
name: { type: 'string' },
on: {
type: 'array',
items: {
type: 'string',
enum: webhookEventTypes,
}
},
url: { type: 'string' },
secret: { type: 'string' },
active: { type: 'boolean' },
latestSentAt: { type: 'string', format: 'date-time', nullable: true },
latestStatus: { type: 'integer', nullable: true },
},
}
}
} as const;
export const paramDef = {
@ -33,7 +64,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
userId: me.id,
});
return webhooks;
return webhooks.map(webhook => (
{
id: webhook.id,
userId: webhook.userId,
name: webhook.name,
on: webhook.on,
url: webhook.url,
secret: webhook.secret,
active: webhook.active,
latestSentAt: webhook.latestSentAt?.toISOString(),
latestStatus: webhook.latestStatus,
}
));
});
}
}

View File

@ -5,6 +5,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { webhookEventTypes } from '@/models/Webhook.js';
import type { WebhooksRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js';
@ -23,6 +24,33 @@ export const meta = {
id: '50f614d9-3047-4f7e-90d8-ad6b2d5fb098',
},
},
res: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id'
},
userId: {
type: 'string',
format: 'misskey:id',
},
name: { type: 'string' },
on: {
type: 'array',
items: {
type: 'string',
enum: webhookEventTypes,
}
},
url: { type: 'string' },
secret: { type: 'string' },
active: { type: 'boolean' },
latestSentAt: { type: 'string', format: 'date-time', nullable: true },
latestStatus: { type: 'integer', nullable: true },
},
},
} as const;
export const paramDef = {
@ -49,7 +77,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchWebhook);
}
return webhook;
return {
id: webhook.id,
userId: webhook.userId,
name: webhook.name,
on: webhook.on,
url: webhook.url,
secret: webhook.secret,
active: webhook.active,
latestSentAt: webhook.latestSentAt?.toISOString(),
latestStatus: webhook.latestStatus,
};
});
}
}

View File

@ -24,6 +24,25 @@ export const meta = {
id: '30aaaee3-4792-48dc-ab0d-cf501a575ac5',
},
},
res: {
type: 'array',
items: {
type: 'object',
nullable: false,
properties: {
id: {
type: 'string',
format: 'misskey:id'
},
user: {
type: 'object',
ref: 'User'
},
},
required: ['id', 'user'],
},
},
} as const;
export const paramDef = {

View File

@ -15,6 +15,53 @@ export const meta = {
cacheSec: 60 * 1,
tags: ['meta'],
res: {
type: 'object',
optional: false, nullable: false,
properties: {
machine: {
type: 'string',
nullable: false,
},
cpu: {
type: 'object',
nullable: false,
properties: {
model: {
type: 'string',
nullable: false,
},
cores: {
type: 'number',
nullable: false,
},
},
},
mem: {
type: 'object',
properties: {
total: {
type: 'number',
nullable: false,
},
},
},
fs: {
type: 'object',
nullable: false,
properties: {
total: {
type: 'number',
nullable: false,
},
used: {
type: 'number',
nullable: false,
},
},
},
},
},
} as const;
export const paramDef = {

View File

@ -12,6 +12,30 @@ export const meta = {
description: 'Endpoint for testing input validation.',
requireCredential: false,
res: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'misskey:id'
},
required: {
type: 'boolean',
},
string: {
type: 'string',
},
default: {
type: 'string',
},
nullableDefault: {
type: 'string',
default: 'hello',
nullable: true,
},
}
}
} as const;
export const paramDef = {

View File

@ -10,6 +10,21 @@ import { DI } from '@/di-symbols.js';
export const meta = {
requireCredential: true,
res: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
unlockedAt: {
type: 'number',
},
},
},
}
} as const;
export const paramDef = {

View File

@ -25,6 +25,35 @@ export const meta = {
id: '7bc05c21-1d7a-41ae-88f1-66820f4dc686',
},
},
res: {
type: 'array',
items: {
type: 'object',
nullable: false,
properties: {
id: {
type: 'string',
format: 'misskey:id',
},
createdAt: {
type: 'string',
format: 'date-time',
},
userId: {
type: 'string',
format: 'misskey:id',
},
user: {
type: 'object',
ref: 'User',
},
withReplies: {
type: 'boolean',
},
},
},
},
} as const;
export const paramDef = {