This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): swagger platform (#188)
- Loading branch information
Showing
27 changed files
with
2,319 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Controller } from '@server'; | ||
import { Get } from '@server/http'; | ||
|
||
@Controller() | ||
export class AppController { | ||
@Get('get') | ||
get() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@server'; | ||
|
||
import { AppController } from './app.controller'; | ||
|
||
@Module({ | ||
controllers: [AppController], | ||
}) | ||
export class AppModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Application, HttpStatus, Module } from '@server'; | ||
import { ExpressAdapter } from '@server/express'; | ||
import { HttpModule } from '@server/http'; | ||
import { SwaggerModule } from '@server/swagger'; | ||
import * as request from 'supertest'; | ||
|
||
import { AppModule } from '../src/app.module'; | ||
|
||
@Module({ | ||
modules: [ | ||
HttpModule.create(ExpressAdapter), | ||
SwaggerModule.forRoot(), | ||
AppModule, | ||
], | ||
}) | ||
class TestModule { } | ||
|
||
describe('Express Swagger Route', () => { | ||
let app: Application; | ||
let module: HttpModule; | ||
|
||
beforeEach(async () => { | ||
app = await Application.create(TestModule); | ||
module = await app.inject<HttpModule>(HttpModule); | ||
|
||
await module.listen(); | ||
}); | ||
|
||
afterEach(() => module.close()); | ||
|
||
it('registers swagger file', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/swagger/swagger.json') | ||
.expect(HttpStatus.OK); | ||
}); | ||
|
||
it('registers swagger-ui page', async () => { | ||
return request(module.getHttpServer()) | ||
.get('/swagger') | ||
.expect(301); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.test.json" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { OpenAPIV3_1 } from 'openapi-types'; | ||
|
||
import { Decorate } from '../../../core'; | ||
import { METHOD_API_OPERATION_METADATA } from '../helpers'; | ||
|
||
export function ApiOperation(operation: OpenAPIV3_1.OperationObject) { | ||
return Decorate(METHOD_API_OPERATION_METADATA, operation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { OpenAPIV3_1 } from 'openapi-types'; | ||
|
||
import { Decorate } from '../../../core'; | ||
import { PROPERTY_API_PARAMETER_METADATA } from '../helpers'; | ||
|
||
export function ApiParameter(parameter: Pick<OpenAPIV3_1.ParameterObject, 'description'>) { | ||
return Decorate(PROPERTY_API_PARAMETER_METADATA, parameter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ClassConstructor, Decorate } from '../../../core'; | ||
import { METHOD_API_RESPONSE_METADATA, METHOD_API_RESPONSES_METADATA } from '../helpers'; | ||
import { ApiBasicResponse, ApiResponses } from '../types'; | ||
|
||
export function ApiResponse(description: string, type?: ClassConstructor) { | ||
return Decorate(METHOD_API_RESPONSE_METADATA, { | ||
description, type, | ||
} as ApiBasicResponse); | ||
} | ||
|
||
export function ApiResponseSchema(responses: ApiResponses) { | ||
return Decorate(METHOD_API_RESPONSES_METADATA, responses); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { OpenAPIV3_1 } from 'openapi-types'; | ||
|
||
import { Decorate } from '../../../core'; | ||
import { METHOD_API_SECURITY_METADATA } from '../helpers'; | ||
|
||
export function ApiSecurity(security: OpenAPIV3_1.SecuritySchemeObject) { | ||
return Decorate(METHOD_API_SECURITY_METADATA, security); | ||
} | ||
|
||
export function ApiBearerAuth() { | ||
return Decorate(METHOD_API_SECURITY_METADATA, { | ||
scheme: 'bearer', | ||
type: 'http', | ||
} as OpenAPIV3_1.SecuritySchemeObject); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { ApiOperation } from './api-operation'; | ||
export { ApiParameter } from './api-parameter'; | ||
export { ApiResponse } from './api-response'; | ||
export * from './api-security'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const METHOD_API_OPERATION_METADATA = '__swagger__:method:api-operation'; | ||
export const METHOD_API_RESPONSE_METADATA = '__swagger__:method:api-response'; | ||
export const METHOD_API_RESPONSES_METADATA = '__swagger__:method:api-responses'; | ||
export const METHOD_API_SECURITY_METADATA = '__swagger__:method:template'; | ||
export const PROPERTY_API_PARAMETER_METADATA = '__swagger__:property:api-parameter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants'; | ||
export * from './injectables'; |
3 changes: 3 additions & 0 deletions
3
server/src/platforms/swagger/helpers/constants/injectables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { InjectionToken } from '@decorators/di'; | ||
|
||
export const SWAGGER_CONFIG = new InjectionToken('__swagger__:config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants'; | ||
export * from './swagger-ui'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { SwaggerDocument } from './swagger-document'; | ||
export { SwaggerResolver } from './swagger-resolver'; |
Oops, something went wrong.