feat: pid posting option at Instrument creation#2687
Open
abdellah257 wants to merge 2 commits intoSciCatProject:masterfrom
Open
feat: pid posting option at Instrument creation#2687abdellah257 wants to merge 2 commits intoSciCatProject:masterfrom
abdellah257 wants to merge 2 commits intoSciCatProject:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
CreateInstrumentDto, consider using@ApiPropertyOptional()instead of@ApiProperty({ required: false })forpidto better reflect its optional nature in the Swagger schema. - Now that
pidis optional in the schema, verify that the service layer consistently treatsundefinedvs. an empty string/null so that the default generator is only bypassed when a truly custom PID is provided.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `CreateInstrumentDto`, consider using `@ApiPropertyOptional()` instead of `@ApiProperty({ required: false })` for `pid` to better reflect its optional nature in the Swagger schema.
- Now that `pid` is optional in the schema, verify that the service layer consistently treats `undefined` vs. an empty string/null so that the default generator is only bypassed when a truly custom PID is provided.
## Individual Comments
### Comment 1
<location path="src/instruments/dto/create-instrument.dto.ts" line_range="7-14" />
<code_context>
@ApiTags("instruments")
export class CreateInstrumentDto extends UpdateInstrumentDto {
+ @IsOptional()
+ @ApiProperty({
+ type: String,
+ required: false,
+ uniqueItems: true,
+ })
+ @IsString()
+ readonly pid: string;
+
@ApiProperty({
</code_context>
<issue_to_address>
**suggestion:** Consider preventing empty strings for `pid` so they don't override the auto-generated value with an effectively unusable PID.
Because `pid` is optional and only uses `@IsString()`, an empty string is currently accepted and will bypass the schema’s default generator. If blank/whitespace PIDs are not valid in your domain, add `@IsNotEmpty()` (and optionally trim the input) so only meaningful IDs are accepted when supplied.
Suggested implementation:
```typescript
import { ApiProperty, ApiTags } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsNotEmpty, IsOptional, IsString } from "class-validator";
import { UpdateInstrumentDto } from "./update-instrument.dto";
```
```typescript
export class CreateInstrumentDto extends UpdateInstrumentDto {
@IsOptional()
@ApiProperty({
type: String,
required: false,
uniqueItems: true,
})
@Transform(({ value }) =>
typeof value === "string" ? value.trim() : value,
)
@IsString()
@IsNotEmpty()
readonly pid: string;
```
</issue_to_address>
### Comment 2
<location path="src/instruments/dto/create-instrument.dto.ts" line_range="11" />
<code_context>
+ @ApiProperty({
+ type: String,
+ required: false,
+ uniqueItems: true,
+ })
+ @IsString()
</code_context>
<issue_to_address>
**suggestion:** `uniqueItems` is not meaningful for a scalar string property in `ApiProperty`.
`uniqueItems` in Swagger metadata only applies to array schemas, so using it on scalar `pid: string` is misleading and has no runtime effect. Please remove `uniqueItems` here and rely on the schema’s `unique: true` constraint to indicate uniqueness instead.
Suggested implementation:
```typescript
@IsOptional()
@ApiProperty({
type: String,
required: false,
})
@IsString()
readonly pid: string;
```
```typescript
@ApiProperty({
type: String,
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
pidto instrument creation DTO as optional field.Motivation
pidfor instruments.Changes:
Tests included
Documentation
official documentation info
Summary by Sourcery
Allow instruments to be created with an optional client-provided PID instead of always requiring an auto-generated one.
New Features:
Enhancements: