diff --git a/nest-cli.json b/nest-cli.json index 6e477fdd4..9ae1faa63 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -2,6 +2,12 @@ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { - "plugins": ["@nestjs/swagger"] + "plugins": [{ + "name": "@nestjs/swagger", + "options": { + "dtoFileNameSuffix": [".dto.ts", "sample.schema.ts"], + "introspectComments": true + } + }] } } diff --git a/src/samples/dto/create-sample.dto.ts b/src/samples/dto/create-sample.dto.ts index 9483c0029..0dddb547b 100644 --- a/src/samples/dto/create-sample.dto.ts +++ b/src/samples/dto/create-sample.dto.ts @@ -1,14 +1,10 @@ -import { ApiProperty } from "@nestjs/swagger"; import { IsOptional, IsString } from "class-validator"; import { UpdateSampleDto } from "./update-sample.dto"; export class CreateSampleDto extends UpdateSampleDto { - @ApiProperty({ - type: String, - required: false, - description: - "Globally unique identifier of a sample. This could be provided as an input value or generated by the system.", - }) + /** + * Globally unique identifier of a sample. This could be provided as an input value or generated by the system. + */ @IsString() @IsOptional() readonly sampleId?: string; diff --git a/src/samples/dto/update-sample.dto.ts b/src/samples/dto/update-sample.dto.ts index f8166dd7e..992d6c980 100644 --- a/src/samples/dto/update-sample.dto.ts +++ b/src/samples/dto/update-sample.dto.ts @@ -1,45 +1,35 @@ -import { ApiProperty, PartialType } from "@nestjs/swagger"; +import { PartialType } from "@nestjs/swagger"; import { IsBoolean, IsObject, IsOptional, IsString } from "class-validator"; import { OwnableDto } from "../../common/dto/ownable.dto"; export class UpdateSampleDto extends OwnableDto { - @ApiProperty({ - type: String, - required: false, - description: "The owner of the sample.", - }) + /** + * The owner of the sample. + */ @IsString() @IsOptional() readonly owner?: string; - @ApiProperty({ - type: String, - required: false, - description: "A description of the sample.", - }) + /** + * A description of the sample. + */ @IsString() @IsOptional() readonly description?: string; - @ApiProperty({ - type: Object, - default: {}, - required: false, - description: "JSON object containing the sample characteristics metadata.", - }) + /** + * JSON object containing the sample characteristics metadata. + */ @IsObject() @IsOptional() - readonly sampleCharacteristics?: Record; + readonly sampleCharacteristics?: Record = {}; - @ApiProperty({ - type: Boolean, - default: false, - required: false, - description: "Flag is true when data are made publicly available.", - }) + /** + * Flag is true when data are made publicly available. + */ @IsBoolean() @IsOptional() - readonly isPublished?: boolean; + readonly isPublished?: boolean = false; } export class PartialUpdateSampleDto extends PartialType(UpdateSampleDto) {} diff --git a/src/samples/samples.service.spec.ts b/src/samples/samples.service.spec.ts index 1933161b4..707da68d9 100644 --- a/src/samples/samples.service.spec.ts +++ b/src/samples/samples.service.spec.ts @@ -43,7 +43,6 @@ const mockSample: SampleClass = { describe("SamplesService", () => { let service: SamplesService; - // eslint-disable-next-line @typescript-eslint/no-unused-vars let sampleModel: Model; beforeEach(async () => { diff --git a/src/samples/schemas/sample.schema.ts b/src/samples/schemas/sample.schema.ts index 213f62ea6..857dbf7af 100644 --- a/src/samples/schemas/sample.schema.ts +++ b/src/samples/schemas/sample.schema.ts @@ -1,5 +1,5 @@ import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; -import { ApiProperty } from "@nestjs/swagger"; +import { ApiHideProperty } from "@nestjs/swagger"; import { Document } from "mongoose"; import { Attachment } from "src/attachments/schemas/attachment.schema"; import { OwnableClass } from "src/common/schemas/ownable.schema"; @@ -16,68 +16,46 @@ export type SampleDocument = SampleClass & Document; timestamps: true, }) export class SampleClass extends OwnableClass { + @ApiHideProperty() @Prop({ type: String }) _id: string; - @ApiProperty({ - type: String, - default: () => uuidv4(), - required: true, - description: - "Globally unique identifier of a sample. This could be provided as an input value or generated by the system.", - }) + /** + * Globally unique identifier of a sample. This could be provided as an input value or generated by the system. + */ @Prop({ type: String, unique: true, required: true, default: () => uuidv4() }) sampleId: string; - @ApiProperty({ - type: String, - required: false, - description: "The owner of the sample.", - }) + /** + * The owner of the sample. + */ @Prop({ type: String, required: false }) owner?: string; - @ApiProperty({ - type: String, - required: false, - description: "A description of the sample.", - }) + /** + * A description of the sample. + */ @Prop({ type: String, required: false }) description?: string; - @ApiProperty({ - type: Object, - default: {}, - required: false, - description: "JSON object containing the sample characteristics metadata.", - }) + /** + * JSON object containing the sample characteristics metadata. + */ @Prop({ type: Object, required: false, default: {} }) - sampleCharacteristics?: Record; + sampleCharacteristics?: Record = {}; } export class SampleWithAttachmentsAndDatasets extends SampleClass { - /* - @ApiProperty({ type: "array", items: { $ref: getSchemaPath(Attachment) } }) - @Prop([AttachmentSchema])*/ + /** + * Attachments that are related to this sample. + */ // this property should not be present in the database model - @ApiProperty({ - type: Attachment, - isArray: true, - required: false, - description: "Attachments that are related to this sample.", - }) attachments?: Attachment[]; - /* - @ApiProperty({ type: "array", items: { $ref: getSchemaPath(Dataset) } }) - @Prop([DatasetSchema])*/ + /** + * Datasets that are related to this sample. + */ // this property should not be present in the database model - @ApiProperty({ - type: DatasetClass, - isArray: true, - required: false, - description: "Datasets that are related to this sample.", - }) datasets?: DatasetClass[]; }