mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-28 00:00:06 +00:00
added swagger + outputs module
This commit is contained in:
+3
-1
@@ -28,10 +28,12 @@
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/microservices": "^8.2.4",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
"@nestjs/swagger": "^5.1.5",
|
||||
"grpc": "^1.24.11",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.2.0"
|
||||
"rxjs": "^7.2.0",
|
||||
"swagger-ui-express": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^8.0.0",
|
||||
|
||||
+6
-1
@@ -1,9 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { InputGrpcClientModule } from './inputs/input-grpc-client.module';
|
||||
import { UsersGrpcClientModule } from './users-grpc-client/users-grpc-client.module';
|
||||
import { OutputsModule } from './outputs/outputs.module';
|
||||
import { EnrichmentModule } from './enrichment/enrichment.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersGrpcClientModule, InputGrpcClientModule],
|
||||
imports: [
|
||||
InputGrpcClientModule,
|
||||
OutputsModule, EnrichmentModule
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
|
||||
@@ -6,8 +6,8 @@ export const GrpcClientConfiguration: ClientOptions = {
|
||||
options: {
|
||||
//url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
|
||||
url: `127.0.0.1:50052`,
|
||||
package: 'user',
|
||||
protoPath: join(__dirname, '..', 'proto', 'user.proto'),
|
||||
package: 'input',
|
||||
protoPath: join(__dirname, '..', 'proto', 'input.proto'),
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
|
||||
export class CreateInputGrpcClientDto {
|
||||
|
||||
|
||||
@ApiProperty()
|
||||
cron:string;
|
||||
|
||||
@ApiProperty({
|
||||
description:"Name of the input",
|
||||
example:"Test Name"
|
||||
})
|
||||
name:string;
|
||||
|
||||
@ApiProperty()
|
||||
plugin:string;
|
||||
|
||||
@ApiProperty()
|
||||
values:string;
|
||||
|
||||
@ApiProperty()
|
||||
operation:string;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,4 @@ import { CreateInputGrpcClientDto } from './create-input-grpc-client.dto';
|
||||
|
||||
export class UpdateInputGrpcClientDto extends PartialType(
|
||||
CreateInputGrpcClientDto,
|
||||
) {
|
||||
id: number;
|
||||
}
|
||||
) {}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
export class InputGrpcClient {
|
||||
|
||||
id:string;
|
||||
|
||||
cron:string;
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
|
||||
import { InputGrpcClientService } from './input-grpc-client.service';
|
||||
import { GrpcClientConfiguration } from './config/grpc-client';
|
||||
import { TestConnectionDTO } from './dto/test-connection-grpc-client.dto';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@Controller('input-grpc-client')
|
||||
@ApiTags('inputs')
|
||||
@Controller('input')
|
||||
export class InputGrpcClientController implements OnModuleInit {
|
||||
@Client(GrpcClientConfiguration)
|
||||
private inputServiceClient: ClientGrpc;
|
||||
|
||||
@@ -8,7 +8,7 @@ import "google/protobuf/timestamp.proto";
|
||||
|
||||
|
||||
service InputService {
|
||||
rpc Create(CreateInputRequest) returns (InputResponse) {}
|
||||
rpc Create(CreateInputRequest) returns (Input) {}
|
||||
rpc Show(IdRequest) returns (Input) {}
|
||||
rpc List(Empty) returns (ListResponse){}
|
||||
rpc Update(UpdateInputRequest) returns (Input){}
|
||||
@@ -32,11 +32,12 @@ message UpdateInputRequest{
|
||||
}
|
||||
|
||||
message Input {
|
||||
string cronFormated = 1;
|
||||
string name = 2;
|
||||
string plugin = 3;
|
||||
string values = 4;
|
||||
string operation = 5;
|
||||
string id = 1;
|
||||
string cronFormated = 2;
|
||||
string name = 3;
|
||||
string plugin = 4;
|
||||
string values = 5;
|
||||
string operation = 6;
|
||||
}
|
||||
|
||||
message CreateInputRequest {
|
||||
|
||||
+16
-1
@@ -1,8 +1,23 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = NestFactory.create(AppModule);
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Maestro Grpc Documentation')
|
||||
.setDescription('Documentation for Maestro gateway')
|
||||
.setVersion('1.0')
|
||||
.addTag('inputs')
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
writeFileSync('./swagger.json', JSON.stringify(document));
|
||||
SwaggerModule.setup('api', app, document);
|
||||
|
||||
|
||||
await (await app).listen(3001);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { join } from 'path';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
|
||||
export const GrpcClientConfiguration: ClientOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
//url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
|
||||
url: `127.0.0.1:50053`,
|
||||
package: 'output',
|
||||
protoPath: join(__dirname, '..', 'proto', 'output.proto'),
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
export class CreateOutputDto {
|
||||
|
||||
name:string;
|
||||
plugin:string;
|
||||
values:string;
|
||||
operation:string;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateOutputDto } from './create-output.dto';
|
||||
|
||||
export class UpdateOutputDto extends PartialType(CreateOutputDto) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export class Output {
|
||||
|
||||
id:string;
|
||||
name:string;
|
||||
plugin:string;
|
||||
values:string;
|
||||
operation:string;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OutputsController } from './outputs.controller';
|
||||
import { OutputGrpcClientService } from './outputs.service';
|
||||
|
||||
describe('OutputsController', () => {
|
||||
let controller: OutputsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [OutputsController],
|
||||
providers: [OutputGrpcClientService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<OutputsController>(OutputsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Controller, Delete, Get, OnModuleInit, Param, Post, Put } from '@nestjs/common';
|
||||
import { Client, ClientGrpc, MessagePattern, Payload } from '@nestjs/microservices';
|
||||
import { OutputGrpcClientService } from './outputs.service';
|
||||
import { CreateOutputDto } from './dto/create-output.dto';
|
||||
import { UpdateOutputDto } from './dto/update-output.dto';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { GrpcClientConfiguration } from './config/grpc-client';
|
||||
|
||||
@ApiTags('outputs')
|
||||
@Controller('output')
|
||||
export class OutputsController implements OnModuleInit{
|
||||
|
||||
@Client(GrpcClientConfiguration)
|
||||
private outputServiceClient: ClientGrpc;
|
||||
|
||||
private outputService: OutputGrpcClientService;
|
||||
|
||||
onModuleInit() {
|
||||
this.outputService =
|
||||
this.outputServiceClient.getService<OutputGrpcClientService>('OutputService');
|
||||
}
|
||||
@Post()
|
||||
create(@Payload() createOutputDto: CreateOutputDto) {
|
||||
return this.outputService.create(createOutputDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
list() {
|
||||
return this.outputService.list();
|
||||
}
|
||||
|
||||
@Get()
|
||||
show(@Payload() id: string) {
|
||||
return this.outputService.show(id);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
update(@Param() id:string,@Payload() updateOutputDto: UpdateOutputDto) {
|
||||
return this.outputService.update(id, updateOutputDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param() id: string) {
|
||||
return this.outputService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { OutputGrpcClientService } from './outputs.service';
|
||||
import { OutputsController } from './outputs.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [OutputsController],
|
||||
providers: [OutputGrpcClientService]
|
||||
})
|
||||
export class OutputsModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OutputsService } from './outputs.service';
|
||||
|
||||
describe('OutputsService', () => {
|
||||
let service: OutputsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [OutputsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<OutputsService>(OutputsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateOutputDto } from './dto/create-output.dto';
|
||||
import { UpdateOutputDto } from './dto/update-output.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OutputGrpcClientService {
|
||||
create(createOutputDto: CreateOutputDto) {
|
||||
return 'This action adds a new output';
|
||||
}
|
||||
|
||||
list() {
|
||||
return `This action returns all outputs`;
|
||||
}
|
||||
|
||||
show(id: string) {
|
||||
return `This action returns a #${id} output`;
|
||||
}
|
||||
|
||||
update(id: string, updateOutputDto: UpdateOutputDto) {
|
||||
return `This action updates a #${id} output`;
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
return `This action removes a #${id} output`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package output;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
|
||||
service OutputService{
|
||||
rpc Create(CreateOutputRequest) returns (Output) {}
|
||||
rpc Show(IdRequest) returns (Output) {}
|
||||
rpc List(Empty) returns (ListResponse){}
|
||||
rpc Update(UpdateOutputRequest) returns (Output){}
|
||||
rpc Remove(IdRequest) returns (Empty){}
|
||||
}
|
||||
|
||||
|
||||
message Empty {}
|
||||
|
||||
message IdRequest{
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message Output {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string plugin = 3;
|
||||
string values = 4;
|
||||
string operation = 5;
|
||||
}
|
||||
|
||||
message CreateOutputRequest {
|
||||
string name = 1;
|
||||
string plugin = 2;
|
||||
string values = 3;
|
||||
string operation = 4;
|
||||
}
|
||||
|
||||
message UpdateOutputRequest{
|
||||
string id = 1;
|
||||
string name = 3;
|
||||
string plugin = 4;
|
||||
string values = 5;
|
||||
string operation = 6;
|
||||
}
|
||||
|
||||
message ListResponse {
|
||||
repeated Output outputs = 1;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"openapi":"3.0.0","paths":{"/input":{"post":{"operationId":"InputGrpcClientController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateInputGrpcClientDto"}}}},"responses":{"201":{"description":""}},"tags":["inputs"]},"get":{"operationId":"InputGrpcClientController_list","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/{id}":{"get":{"operationId":"InputGrpcClientController_show","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]},"put":{"operationId":"InputGrpcClientController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateInputGrpcClientDto"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]},"delete":{"operationId":"InputGrpcClientController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["inputs"]}},"/input/test-connection":{"get":{"operationId":"InputGrpcClientController_testConnection","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestConnectionDTO"}}}},"responses":{"200":{"description":""}},"tags":["inputs"]}},"/output":{"post":{"operationId":"OutputsController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOutputDto"}}}},"responses":{"201":{"description":""}},"tags":["outputs"]},"get":{"operationId":"OutputsController_show","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string"}}}},"responses":{"200":{"description":""}},"tags":["outputs"]}},"/output/{id}":{"put":{"operationId":"OutputsController_update","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateOutputDto"}}}},"responses":{"200":{"description":""}},"tags":["outputs"]},"delete":{"operationId":"OutputsController_remove","parameters":[],"responses":{"200":{"description":""}},"tags":["outputs"]}}},"info":{"title":"Maestro Grpc Documentation","description":"Documentation for Maestro gateway","version":"1.0","contact":{}},"tags":[{"name":"inputs","description":""}],"servers":[],"components":{"schemas":{"CreateInputGrpcClientDto":{"type":"object","properties":{"cron":{"type":"string"},"name":{"type":"string","description":"Name of the input","example":"Test Name"},"plugin":{"type":"string"},"values":{"type":"string"},"operation":{"type":"string"}},"required":["cron","name","plugin","values","operation"]},"UpdateInputGrpcClientDto":{"type":"object","properties":{}},"TestConnectionDTO":{"type":"object","properties":{}},"CreateOutputDto":{"type":"object","properties":{}},"UpdateOutputDto":{"type":"object","properties":{}}}}}
|
||||
Reference in New Issue
Block a user