Browse Source

Merge pull request #91 from shanghaikid/docs

update some docs for swagger
nameczz 4 years ago
parent
commit
7f6e5cb69d

+ 4 - 1
server/nest-cli.json

@@ -1,4 +1,7 @@
 {
 {
   "collection": "@nestjs/schematics",
   "collection": "@nestjs/schematics",
-  "sourceRoot": "src"
+  "sourceRoot": "src",
+  "compilerOptions": {
+    "plugins": ["@nestjs/swagger"]
+  }
 }
 }

+ 2 - 0
server/src/collections/collections.controller.ts

@@ -9,9 +9,11 @@ import {
   UsePipes,
   UsePipes,
   ValidationPipe,
   ValidationPipe,
 } from '@nestjs/common';
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import { CollectionsService } from './collections.service';
 import { CollectionsService } from './collections.service';
 import { CreateCollection } from './dto';
 import { CreateCollection } from './dto';
 
 
+@ApiTags('collections')
 @Controller('collections')
 @Controller('collections')
 export class CollectionsController {
 export class CollectionsController {
   constructor(private collectionsService: CollectionsService) {}
   constructor(private collectionsService: CollectionsService) {}

+ 13 - 3
server/src/collections/dto.ts

@@ -7,22 +7,32 @@ import {
   ArrayNotEmpty,
   ArrayNotEmpty,
 } from 'class-validator';
 } from 'class-validator';
 import { FieldType } from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
 import { FieldType } from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
+import { DataType } from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Common';
 import { ApiProperty } from '@nestjs/swagger';
 import { ApiProperty } from '@nestjs/swagger';
 
 
+
 export class CreateCollection {
 export class CreateCollection {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name'
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Generate ID automatically by milvus',
+    type: Boolean,
+  })
   @IsBoolean()
   @IsBoolean()
   @IsOptional()
   @IsOptional()
   readonly autoID: boolean;
   readonly autoID: boolean;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Field data type',
+    enum: DataType
+  })
   @IsArray()
   @IsArray()
   @ArrayNotEmpty()
   @ArrayNotEmpty()
   @IsNotEmpty({
   @IsNotEmpty({

+ 1 - 1
server/src/main.ts

@@ -8,7 +8,7 @@ async function bootstrap() {
   });
   });
 
 
   const config = new DocumentBuilder()
   const config = new DocumentBuilder()
-    .setTitle('Milvus admin')
+    .setTitle('Milvus insight')
     .setVersion('1.0')
     .setVersion('1.0')
     .build();
     .build();
   const document = SwaggerModule.createDocument(app, config);
   const document = SwaggerModule.createDocument(app, config);

+ 6 - 2
server/src/milvus/dto.ts

@@ -2,7 +2,9 @@ import { ApiProperty } from '@nestjs/swagger';
 import { IsNotEmpty, IsString } from 'class-validator';
 import { IsNotEmpty, IsString } from 'class-validator';
 
 
 export class ConnectMilvus {
 export class ConnectMilvus {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus url'
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'address is empty',
     message: 'address is empty',
@@ -11,7 +13,9 @@ export class ConnectMilvus {
 }
 }
 
 
 export class CheckMilvus {
 export class CheckMilvus {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus url'
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'address is empty',
     message: 'address is empty',

+ 3 - 0
server/src/milvus/milvus.controller.ts

@@ -1,7 +1,10 @@
 import { Body, Controller, Get, Post, Query, UsePipes } from '@nestjs/common';
 import { Body, Controller, Get, Post, Query, UsePipes } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import { ValidationPipe } from 'src/pipe/validation.pipe';
 import { ValidationPipe } from 'src/pipe/validation.pipe';
 import { CheckMilvus, ConnectMilvus } from './dto';
 import { CheckMilvus, ConnectMilvus } from './dto';
 import { MilvusService } from './milvus.service';
 import { MilvusService } from './milvus.service';
+
+@ApiTags('milvus')
 @Controller('milvus')
 @Controller('milvus')
 export class MilvusController {
 export class MilvusController {
   constructor(private milvusService: MilvusService) {}
   constructor(private milvusService: MilvusService) {}

+ 19 - 6
server/src/partitions/dto.ts

@@ -12,7 +12,9 @@ export enum ManageType {
   CREATE = 'create',
   CREATE = 'create',
 }
 }
 export class GetPartitionsInfo {
 export class GetPartitionsInfo {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
@@ -21,34 +23,45 @@ export class GetPartitionsInfo {
 }
 }
 
 
 export class ManagePartition {
 export class ManagePartition {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus partition name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'partition_name is empty',
     message: 'partition_name is empty',
   })
   })
   readonly partition_name: string;
   readonly partition_name: string;
 
 
-  @ApiProperty({ enum: ManageType })
+  @ApiProperty({ 
+    description: 'Type allow delete and create',
+    enum: ManageType
+  })
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   readonly type: ManageType;
   readonly type: ManageType;
 }
 }
 
 
 export class LoadPartitions {
 export class LoadPartitions {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus partition name',
+  })
   @IsArray()
   @IsArray()
   @ArrayNotEmpty()
   @ArrayNotEmpty()
   @IsNotEmpty({
   @IsNotEmpty({

+ 2 - 0
server/src/partitions/partitions.controller.ts

@@ -8,6 +8,7 @@ import {
   UsePipes,
   UsePipes,
   ValidationPipe,
   ValidationPipe,
 } from '@nestjs/common';
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import {
 import {
   GetPartitionsInfo,
   GetPartitionsInfo,
   LoadPartitions,
   LoadPartitions,
@@ -16,6 +17,7 @@ import {
 } from './dto';
 } from './dto';
 import { PartitionsService } from './partitions.service';
 import { PartitionsService } from './partitions.service';
 
 
+@ApiTags('partitions')
 @Controller('partitions')
 @Controller('partitions')
 export class PartitionsController {
 export class PartitionsController {
   constructor(private partitionsService: PartitionsService) {}
   constructor(private partitionsService: PartitionsService) {}

+ 27 - 9
server/src/schema/dto.ts

@@ -24,14 +24,18 @@ export class ManageIndex {
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   readonly type: ManageType;
   readonly type: ManageType;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'field_name is empty',
     message: 'field_name is empty',
@@ -47,49 +51,63 @@ export class ManageIndex {
 }
 }
 
 
 export class DescribeIndex {
 export class DescribeIndex {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection description',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsString()
   @IsOptional()
   @IsOptional()
   readonly field_name?: string;
   readonly field_name?: string;
 }
 }
 
 
 export class GetIndexState {
 export class GetIndexState {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsString()
   @IsOptional()
   @IsOptional()
   readonly field_name?: string;
   readonly field_name?: string;
 }
 }
 
 
 export class GetIndexProgress {
 export class GetIndexProgress {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'collection_name is empty',
     message: 'collection_name is empty',
   })
   })
   readonly collection_name: string;
   readonly collection_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'index name',
+  })
   @IsString()
   @IsString()
   @IsNotEmpty({
   @IsNotEmpty({
     message: 'index_name is empty',
     message: 'index_name is empty',
   })
   })
   readonly index_name: string;
   readonly index_name: string;
 
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsString()
   @IsOptional()
   @IsOptional()
   readonly field_name?: string;
   readonly field_name?: string;

+ 2 - 0
server/src/schema/schema.controller.ts

@@ -7,6 +7,7 @@ import {
   UsePipes,
   UsePipes,
   ValidationPipe,
   ValidationPipe,
 } from '@nestjs/common';
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import {
 import {
   DescribeIndex,
   DescribeIndex,
   GetIndexProgress,
   GetIndexProgress,
@@ -16,6 +17,7 @@ import {
 } from './dto';
 } from './dto';
 import { SchemaService } from './schema.service';
 import { SchemaService } from './schema.service';
 
 
+@ApiTags('schema')
 @Controller('schema')
 @Controller('schema')
 export class SchemaController {
 export class SchemaController {
   constructor(private schemaService: SchemaService) {}
   constructor(private schemaService: SchemaService) {}