Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce OpenAPI specs #4351

Merged
merged 14 commits into from
Feb 23, 2019
Prev Previous commit
Next Next commit
Improve doc
  • Loading branch information
syuilo committed Feb 23, 2019
commit 8bb41cf3b7612d6b8da98782138feef6255644b4
9 changes: 8 additions & 1 deletion src/server/api/endpoints/drive/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ export const meta = {
type: {
validator: $.optional.str.match(/^[a-zA-Z\/\-\*]+$/)
}
}
},

res: {
type: 'array',
items: {
type: 'DriveFile',
},
},
};

export default define(meta, async (ps, user) => {
Expand Down
4 changes: 4 additions & 0 deletions src/server/api/endpoints/drive/files/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const meta = {
}
},

res: {
type: 'DriveFile',
},

errors: {
invalidFileName: {
message: 'Invalid file name.',
Expand Down
4 changes: 4 additions & 0 deletions src/server/api/endpoints/drive/files/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const meta = {
}
},

res: {
type: 'DriveFile',
},

errors: {
noSuchFile: {
message: 'No such file.',
Expand Down
73 changes: 64 additions & 9 deletions src/server/api/gen-openapi-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,25 @@ const schemas = {
},
username: {
type: 'string',
description: 'The screen name, handle, or alias that this user identifies themselves with.'
description: 'The screen name, handle, or alias that this user identifies themselves with.',
example: 'ai'
},
name: {
type: 'string',
nullable: true,
description: 'The name of the user, as they’ve defined it.'
description: 'The name of the user, as they’ve defined it.',
example: '藍'
},
host: {
type: 'string',
nullable: true
nullable: true,
example: 'misskey.example.com'
},
description: {
type: 'string',
nullable: true,
description: 'The user-defined UTF-8 string describing their account.'
description: 'The user-defined UTF-8 string describing their account.',
example: 'Hi masters, I am Ai!'
},
createdAt: {
type: 'string',
Expand All @@ -143,13 +147,16 @@ const schemas = {
description: 'The number of Notes (including renotes) issued by the user.'
},
isBot: {
type: 'boolean'
type: 'boolean',
description: 'Whether this account is a bot.'
},
isCat: {
type: 'boolean'
type: 'boolean',
description: 'Whether this account is a cat.'
},
isAdmin: {
type: 'boolean'
type: 'boolean',
description: 'Whether this account is the admin.'
},
isVerified: {
type: 'boolean'
Expand Down Expand Up @@ -208,7 +215,55 @@ const schemas = {
type: 'string'
},
},
required: ['id', 'userId']
required: ['id', 'userId', 'createdAt']
},

DriveFile: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this Drive file.'
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the Drive file was created on Misskey.'
},
name: {
type: 'string',
description: 'The file name with extension.',
example: 'lenna.jpg'
},
type: {
type: 'string',
description: 'The MIME type of this Drive file.',
example: 'image/jpeg'
},
md5: {
type: 'string',
format: 'md5',
description: 'The MD5 hash of this Drive file.',
example: '15eca7fba0480996e2245f5185bf39f2'
},
datasize: {
type: 'number',
description: 'The size of this Drive file. (bytes)',
example: 51469
},
folderId: {
type: 'string',
format: 'id',
nullable: true,
description: 'The parent folder ID of this Drive file.',
},
isSensitive: {
type: 'boolean',
description: 'Whether this Drive file is sensitive.',
},
},
required: ['id', 'createdAt', 'name', 'type', 'datasize', 'md5']
}
};

Expand Down Expand Up @@ -311,7 +366,7 @@ export function genOpenapiSpec(lang = 'ja-JP') {
function renderType(x: any) {
const res = {} as any;

if (['User', 'Note'].includes(x.type)) {
if (['User', 'Note', 'DriveFile'].includes(x.type)) {
res['$ref'] = `#/components/schemas/${x.type}`;
} else if (x.type === 'object') {
res['type'] = 'object';
Expand Down