Skip to content

Commit

Permalink
feat: openapi spec for /v1/user/@me
Browse files Browse the repository at this point in the history
  • Loading branch information
TheClashFruit committed Aug 1, 2024
1 parent e3009a0 commit 409df9e
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
94 changes: 93 additions & 1 deletion data/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
}
},
"405": {
"description": "Not Acceptable",
"description": "Method Not Allowed",
"content": {
"application/json": {
"schema": {
Expand All @@ -93,6 +93,23 @@
}
}
}
},
"/v1/user/@me": {
"get": {
"description": "User info.",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -160,6 +177,81 @@
"type": "string"
}
}
},
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"username": {
"type": "string"
},
"displayName": {
"type": "string"
},
"email": {
"type": "string"
},
"avatar": {
"type": "string"
},
"banner": {
"type": "string"
},
"badges": {
"type": "array",
"items": {
"type": "integer"
}
},
"connections": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"url": {
"type": "string"
},
"createdAt": {
"type": "integer"
}
}
}
},
"streamTitle": {
"type": "string"
},
"streamKeys": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"key": {
"type": "string"
},
"createdAt": {
"type": "integer"
}
}
}
},
"lastLive": {
"type": "string"
},
"createdAt": {
"type": "integer"
},
"updatedAt": {
"type": "integer"
}
}
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/routes/v1/user/@me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import { User } from '../../../interfaces/user';

import { verify } from 'jsonwebtoken';

import {
OpenApiBuilder,
OpenApiMethod,
OpenApiResponse
} from '../../../util/openapi_builder';

import Database from '../../../util/database';

import type { OpenApi } from '../../../util/openapi_builder';

interface ZleedJWT {
id: bigint;
email: string;
Expand All @@ -16,6 +24,58 @@ interface ZleedJWT {
exp: number;
}

export const openapi = (): OpenApi => {
return new OpenApiBuilder()
.addMethod(
Method.GET,
new OpenApiMethod().description('User info.').addResponse(
Status.OK,
new OpenApiResponse<User>()
.description('Ok')
.name('User')
.schema({
type: 'object',
properties: {
id: { type: 'integer' },
username: { type: 'string' },
displayName: { type: 'string' },
email: { type: 'string' },
avatar: { type: 'string' },
banner: { type: 'string' },
badges: { type: 'array', items: { type: 'integer' } },
connections: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'integer' },
url: { type: 'string' },
createdAt: { type: 'integer' }
}
}
},
streamTitle: { type: 'string' },
streamKeys: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'integer' },
key: { type: 'string' },
createdAt: { type: 'integer' }
}
}
},
lastLive: { type: 'string' },
createdAt: { type: 'integer' },
updatedAt: { type: 'integer' }
}
})
)
)
.build();
};

export default function handler(req: Request, res: Response<User>) {
const jwtToken = req.getHeader('Authorization');

Expand Down

0 comments on commit 409df9e

Please sign in to comment.