Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use openapi cli plugin for sample dtos and schema #1611

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}]
}
}
10 changes: 4 additions & 6 deletions src/samples/dto/create-sample.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";

Check warning on line 1 in src/samples/dto/create-sample.dto.ts

View workflow job for this annotation

GitHub Actions / eslint

'ApiProperty' is defined but never used
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.",
})

Check failure on line 6 in src/samples/dto/create-sample.dto.ts

View workflow job for this annotation

GitHub Actions / eslint

Delete `⏎··`
/**
* Globally unique identifier of a sample. This could be provided as an input value or generated by the system.
*/
@IsString()
@IsOptional()
readonly sampleId?: string;
Expand Down
38 changes: 14 additions & 24 deletions src/samples/dto/update-sample.dto.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
import { ApiProperty, PartialType } from "@nestjs/swagger";

Check warning on line 1 in src/samples/dto/update-sample.dto.ts

View workflow job for this annotation

GitHub Actions / eslint

'ApiProperty' is defined but never used
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<string, unknown>;
readonly sampleCharacteristics?: Record<string, unknown> = {};

@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) {}
67 changes: 23 additions & 44 deletions src/samples/schemas/sample.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { ApiProperty } from "@nestjs/swagger";
import { ApiProperty, ApiHideProperty } from "@nestjs/swagger";

Check warning on line 2 in src/samples/schemas/sample.schema.ts

View workflow job for this annotation

GitHub Actions / eslint

'ApiProperty' is defined but never used
import { Document } from "mongoose";
import { Attachment } from "src/attachments/schemas/attachment.schema";
import { OwnableClass } from "src/common/schemas/ownable.schema";
Expand All @@ -16,68 +16,47 @@
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.",
})

Check failure on line 34 in src/samples/schemas/sample.schema.ts

View workflow job for this annotation

GitHub Actions / eslint

Delete `·`
/**
* 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<string, unknown>;
sampleCharacteristics?: Record<string, unknown> = {};
}

export class SampleWithAttachmentsAndDatasets extends SampleClass {

Check failure on line 48 in src/samples/schemas/sample.schema.ts

View workflow job for this annotation

GitHub Actions / eslint

Delete `⏎··`
/*
@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[];
}

Expand Down
Loading