Skip to content

Commit

Permalink
backend spec (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi authored Jul 21, 2024
1 parent 4f25e31 commit f8bb05a
Show file tree
Hide file tree
Showing 19 changed files with 442 additions and 150 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dependencies": {
"drizzle-orm": "^0.31.4",
"express": "^4.17.0",
"express-openapi-validator": "^5.2.0",
"inversify": "^6.0.0",
"inversify-express-utils": "^6.4.0",
"pg": "^8.11.0",
Expand Down
233 changes: 233 additions & 0 deletions backend/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DatabaseService } from './services/DatabaseService';

export type AppConfig = {
port: number,
env: 'development' | 'production',
};

@injectable()
Expand Down
1 change: 1 addition & 0 deletions backend/src/container/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function setupContainer(container: Container) {
// app config
const appConfig: AppConfig = {
port: 3000,
env: 'development',
};
container.bind(TYPES.AppConfig).toConstantValue(appConfig);

Expand Down
22 changes: 22 additions & 0 deletions backend/src/controllers/api/EchoController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response } from 'express';
import { inject } from 'inversify';
import { controller, httpGet, httpPost, request, requestParam, response } from 'inversify-express-utils';
import { AccountService } from '../../services/AccountService';
import { TYPES } from '../../container/types';

@controller('/api/v1/echo')
export class EchoController {
constructor(
@inject(TYPES.AccountService) private readonly accountService: AccountService,
) {}

@httpGet('/')
async echoGet(@request() req: Request, @response() res: Response) {
return req.query;
}

@httpPost('/')
async echoPost(@request() req: Request, @response() res: Response) {
return req.body;
}
}
9 changes: 9 additions & 0 deletions backend/src/services/HttpServerService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import express from 'express';
import { Container, inject, injectable } from 'inversify';
import { InversifyExpressServer } from 'inversify-express-utils';
import { AppConfig } from '../app';
import { TYPES } from '../container/types';
import * as OpenApiValidator from 'express-openapi-validator';

// controllers
import '../controllers/RootController';
import '../controllers/api/EchoController';
import '../controllers/api/MeController';
import '../controllers/api/UsersController';

Expand All @@ -19,6 +22,12 @@ export class HttpServerService {
const server = new InversifyExpressServer(this.container);

server.setConfig(app => {
app.use(express.json());
// app.use(OpenApiValidator.middleware({
// apiSpec: '../spec/generated/openapi.yaml',
// validateRequests: true,
// validateResponses: false,
// }));
});
server.setErrorConfig(app => {
app.use((req, res) => {
Expand Down
140 changes: 64 additions & 76 deletions spec/generated/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ openapi: 3.0.0
info:
title: Frost
version: 0.1.0
tags: []
tags:
- name: Account
- name: ChatRoom
- name: Echo
- name: Timeline
- name: User
paths:
/api/v1/accounts:
post:
operationId: Accounts_registerAccount
tags:
- Account
operationId: RegisterAccount
parameters: []
responses:
'200':
Expand All @@ -23,7 +30,9 @@ paths:
$ref: '#/components/schemas/Api.v1.NewAccount'
/api/v1/chatrooms:
post:
operationId: ChatRooms_createChatRoom
tags:
- ChatRoom
operationId: CreateChatRoom
parameters: []
responses:
'200':
Expand All @@ -40,7 +49,9 @@ paths:
$ref: '#/components/schemas/Api.v1.NewChatRoom'
/api/v1/chatrooms/{chatRoomId}:
delete:
operationId: ChatRooms_deleteChatRoom
tags:
- ChatRoom
operationId: DeleteChatRoom
parameters:
- name: chatRoomId
in: path
Expand All @@ -52,7 +63,9 @@ paths:
description: 'There is no content to send for this request, but the headers may be useful. '
/api/v1/chatrooms/{chatRoomId}/members:
get:
operationId: ChatRoomMembers_listChatRoomMember
tags:
- ChatRoom
operationId: ListChatRoomMember
parameters:
- name: chatRoomId
in: path
Expand All @@ -70,7 +83,9 @@ paths:
$ref: '#/components/schemas/Api.v1.ChatRoomMember'
/api/v1/chatrooms/{chatRoomId}/members/{userId}:
post:
operationId: ChatRoomMembers_createChatRoomMember
tags:
- ChatRoom
operationId: CreateChatRoomMember
parameters:
- name: chatRoomId
in: path
Expand All @@ -90,7 +105,9 @@ paths:
schema:
$ref: '#/components/schemas/Api.v1.ChatRoomMember'
delete:
operationId: ChatRoomMembers_deleteChatRoomMember
tags:
- ChatRoom
operationId: DeleteChatRoomMember
parameters:
- name: chatRoomId
in: path
Expand All @@ -107,7 +124,9 @@ paths:
description: 'There is no content to send for this request, but the headers may be useful. '
/api/v1/chatrooms/{chatRoomId}/posts:
post:
operationId: ChatRoomPosts_createChatRoomPost
tags:
- ChatRoom
operationId: CreateChatRoomPost
parameters:
- name: chatRoomId
in: path
Expand All @@ -120,53 +139,18 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.ChatRoomPost'
$ref: '#/components/schemas/Api.v1.Post'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.NewChatRoomPost'
/api/v1/chatrooms/{chatRoomId}/posts/{postId}:
get:
operationId: ChatRoomPosts_getChatRoomPost
parameters:
- name: chatRoomId
in: path
required: true
schema:
type: string
- name: postId
in: path
required: true
schema:
type: string
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.ChatRoomPost'
delete:
operationId: ChatRoomPosts_deleteChatRoomPost
parameters:
- name: chatRoomId
in: path
required: true
schema:
type: string
- name: postId
in: path
required: true
schema:
type: string
responses:
'204':
description: 'There is no content to send for this request, but the headers may be useful. '
/api/v1/echo:
get:
operationId: Echo_echoGet
tags:
- Echo
operationId: EchoGet
parameters:
- name: query
in: query
Expand All @@ -177,7 +161,9 @@ paths:
'200':
description: The request has succeeded.
post:
operationId: Echo_echoPost
tags:
- Echo
operationId: EchoPost
parameters: []
responses:
'200':
Expand All @@ -190,7 +176,9 @@ paths:
type: object
/api/v1/me:
get:
operationId: Me_getMe
tags:
- Account
operationId: GetMe
parameters: []
responses:
'200':
Expand All @@ -199,26 +187,31 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.Account'
/api/v1/timelines/posts:
/api/v1/posts:
post:
operationId: TimelinePosts_createTimelinePost
tags:
- Timeline
operationId: CreateTimelinePost
parameters: []
responses:
'200':
description: The request has succeeded.
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.TimelinePost'
$ref: '#/components/schemas/Api.v1.Post'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.NewTimelinePost'
/api/v1/timelines/posts/{postId}:
/api/v1/posts/{postId}:
get:
operationId: TimelinePosts_getTimelinePost
tags:
- Timeline
- ChatRoom
operationId: GetPost
parameters:
- name: postId
in: path
Expand All @@ -231,9 +224,12 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Api.v1.TimelinePost'
$ref: '#/components/schemas/Api.v1.Post'
delete:
operationId: TimelinePosts_deleteTimelinePost
tags:
- Timeline
- ChatRoom
operationId: DeletePost
parameters:
- name: postId
in: path
Expand All @@ -245,7 +241,9 @@ paths:
description: 'There is no content to send for this request, but the headers may be useful. '
/api/v1/users:
post:
operationId: Users_createUser
tags:
- User
operationId: CreateUser
parameters: []
responses:
'200':
Expand All @@ -262,7 +260,9 @@ paths:
$ref: '#/components/schemas/Api.v1.NewUser'
/api/v1/users/{userId}:
get:
operationId: Users_getUser
tags:
- User
operationId: GetUser
parameters:
- name: userId
in: path
Expand All @@ -277,7 +277,9 @@ paths:
schema:
$ref: '#/components/schemas/Api.v1.User'
delete:
operationId: Users_deleteUser
tags:
- User
operationId: DeleteUser
parameters:
- name: userId
in: path
Expand Down Expand Up @@ -327,22 +329,6 @@ components:
type: string
chatRoomId:
type: string
Api.v1.ChatRoomPost:
type: object
required:
- postId
- chatRoomId
- userId
- content
properties:
postId:
type: string
chatRoomId:
type: string
userId:
type: string
content:
type: string
Api.v1.NewAccount:
type: object
required:
Expand Down Expand Up @@ -384,7 +370,7 @@ components:
type: string
displayName:
type: string
Api.v1.TimelinePost:
Api.v1.Post:
type: object
required:
- postId
Expand All @@ -393,6 +379,8 @@ components:
properties:
postId:
type: string
chatRoomId:
type: string
userId:
type: string
content:
Expand Down
1 change: 1 addition & 0 deletions spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@typespec/compiler": "latest",
"@typespec/http": "latest",
"@typespec/rest": "latest",
"@typespec/openapi": "latest",
"@typespec/openapi3": "latest"
},
"private": true
Expand Down
3 changes: 3 additions & 0 deletions spec/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f8bb05a

Please sign in to comment.