Merge pull request #766 from hedgedoc/feat/dto-docs

This commit is contained in:
David Mehren 2021-01-25 23:16:02 +01:00 committed by GitHub
commit f8757d0e5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 248 additions and 1 deletions

View file

@ -2,6 +2,13 @@
"collection": "@nestjs/schematics", "collection": "@nestjs/schematics",
"sourceRoot": "src", "sourceRoot": "src",
"compilerOptions": { "compilerOptions": {
"plugins": ["@nestjs/swagger/plugin"] "plugins": [
{
"name": "@nestjs/swagger",
"options": {
"introspectComments": true
}
}
]
} }
} }

View file

@ -7,6 +7,9 @@
import { IsBoolean } from 'class-validator'; import { IsBoolean } from 'class-validator';
export class HistoryEntryUpdateDto { export class HistoryEntryUpdateDto {
/**
* True if the note should be pinned
*/
@IsBoolean() @IsBoolean()
pinStatus: boolean; pinStatus: boolean;
} }

View file

@ -8,8 +8,16 @@ import { IsBoolean, ValidateNested } from 'class-validator';
import { NoteMetadataDto } from '../notes/note-metadata.dto'; import { NoteMetadataDto } from '../notes/note-metadata.dto';
export class HistoryEntryDto { export class HistoryEntryDto {
/**
* Metadata of this note
*/
@ValidateNested() @ValidateNested()
metadata: NoteMetadataDto; metadata: NoteMetadataDto;
/**
* True if this note is pinned
* @example false
*/
@IsBoolean() @IsBoolean()
pinStatus: boolean; pinStatus: boolean;
} }

View file

@ -8,16 +8,41 @@ import { IsDate, IsNumber, IsString, Min } from 'class-validator';
import { UserInfoDto } from '../users/user-info.dto'; import { UserInfoDto } from '../users/user-info.dto';
export class NoteAuthorshipDto { export class NoteAuthorshipDto {
/**
* Username of the user who authored this section
* @example "john.smith"
*/
@IsString() @IsString()
userName: UserInfoDto['userName']; userName: UserInfoDto['userName'];
/**
* Character index of the start of this section
* @example 102
*/
@IsNumber() @IsNumber()
@Min(0) @Min(0)
startPos: number; startPos: number;
/**
* Character index of the end of this section
* Must be greater than {@link startPos}
* @example 154
*/
@IsNumber() @IsNumber()
@Min(0) @Min(0)
endPos: number; endPos: number;
/**
* Datestring of the time this section was created
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
createdAt: Date; createdAt: Date;
/**
* Datestring of the last time this section was edited
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
updatedAt: Date; updatedAt: Date;
} }

View file

@ -8,6 +8,7 @@ import {
IsArray, IsArray,
IsDate, IsDate,
IsNumber, IsNumber,
IsOptional,
IsString, IsString,
ValidateNested, ValidateNested,
} from 'class-validator'; } from 'class-validator';
@ -15,37 +16,107 @@ import { UserInfoDto } from '../users/user-info.dto';
import { NotePermissionsDto } from './note-permissions.dto'; import { NotePermissionsDto } from './note-permissions.dto';
export class NoteMetadataDto { export class NoteMetadataDto {
/**
* ID of the note
*/
@IsString() @IsString()
id: string; id: string;
/**
* Alias of the note
* Can be null
*/
@IsString() @IsString()
@IsOptional()
alias: string; alias: string;
/**
* Title of the note
* Does not contain any markup but might be empty
* @example "Shopping List"
*/
@IsString() @IsString()
title: string; title: string;
/**
* Description of the note
* Does not contain any markup but might be empty
* @example Everything I want to buy
*/
@IsString() @IsString()
description: string; description: string;
/**
* List of tags assigned to this note
* @example "['shopping', 'personal']
*/
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
tags: string[]; tags: string[];
/**
* Datestring of the last time this note was updated
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
updateTime: Date; updateTime: Date;
/**
* User that last edited the note
*/
@ValidateNested() @ValidateNested()
updateUser: UserInfoDto; updateUser: UserInfoDto;
/**
* Counts how many times the published note has been viewed
* @example 42
*/
@IsNumber() @IsNumber()
viewCount: number; viewCount: number;
/**
* Datestring of the time this note was created
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
createTime: Date; createTime: Date;
/**
* List of usernames that edited the note
* @example "['john.smith', 'jane.smith']"
*/
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
editedBy: UserInfoDto['userName'][]; editedBy: UserInfoDto['userName'][];
/**
* Permissions currently in effect for the note
*/
@ValidateNested() @ValidateNested()
permissions: NotePermissionsDto; permissions: NotePermissionsDto;
} }
export class NoteMetadataUpdateDto { export class NoteMetadataUpdateDto {
/**
* New title of the note
* Can not contain any markup and might be empty
* @example "Shopping List"
*/
@IsString() @IsString()
title: string; title: string;
/**
* New description of the note
* Can not contain any markup but might be empty
* @example Everything I want to buy
*/
@IsString() @IsString()
description: string; description: string;
/**
* New list of tags assigned to this note
* @example "['shopping', 'personal']
*/
@IsArray() @IsArray()
@IsString({ each: true }) @IsString({ each: true })
tags: string[]; tags: string[];

View file

@ -8,57 +8,124 @@ import { IsArray, IsBoolean, IsString, ValidateNested } from 'class-validator';
import { UserInfoDto } from '../users/user-info.dto'; import { UserInfoDto } from '../users/user-info.dto';
export class NoteUserPermissionEntryDto { export class NoteUserPermissionEntryDto {
/**
* User this permission applies to
*/
@ValidateNested() @ValidateNested()
user: UserInfoDto; user: UserInfoDto;
/**
* True if the user is allowed to edit the note
* @example false
*/
@IsBoolean() @IsBoolean()
canEdit: boolean; canEdit: boolean;
} }
export class NoteUserPermissionUpdateDto { export class NoteUserPermissionUpdateDto {
/**
* Username of the user this permission should apply to
* @example "john.smith"
*/
@IsString() @IsString()
username: string; username: string;
/**
* True if the user should be allowed to edit the note
* @example false
*/
@IsBoolean() @IsBoolean()
canEdit: boolean; canEdit: boolean;
} }
export class GroupInfoDto { export class GroupInfoDto {
/**
* Name of the group
* @example "superheroes"
*/
@IsString() @IsString()
name: string; name: string;
/**
* Display name of this group
* @example "Superheroes"
*/
@IsString() @IsString()
displayName: string; displayName: string;
/**
* True if this group must be specially handled
* Used for e.g. "everybody", "all logged in users"
* @example false
*/
@IsBoolean() @IsBoolean()
special: boolean; special: boolean;
} }
export class NoteGroupPermissionEntryDto { export class NoteGroupPermissionEntryDto {
/**
* Group this permission applies to
*/
@ValidateNested() @ValidateNested()
group: GroupInfoDto; group: GroupInfoDto;
/**
* True if the group members are allowed to edit the note
* @example false
*/
@IsBoolean() @IsBoolean()
canEdit: boolean; canEdit: boolean;
} }
export class NoteGroupPermissionUpdateDto { export class NoteGroupPermissionUpdateDto {
/**
* Name of the group this permission should apply to
* @example "superheroes"
*/
@IsString() @IsString()
groupname: string; groupname: string;
/**
* True if the group members should be allowed to edit the note
* @example false
*/
@IsBoolean() @IsBoolean()
canEdit: boolean; canEdit: boolean;
} }
export class NotePermissionsDto { export class NotePermissionsDto {
/**
* User this permission applies to
*/
@ValidateNested() @ValidateNested()
owner: UserInfoDto; owner: UserInfoDto;
/**
* List of users the note is shared with
*/
@ValidateNested() @ValidateNested()
@IsArray() @IsArray()
sharedToUsers: NoteUserPermissionEntryDto[]; sharedToUsers: NoteUserPermissionEntryDto[];
/**
* List of groups the note is shared with
*/
@ValidateNested() @ValidateNested()
@IsArray() @IsArray()
sharedToGroups: NoteGroupPermissionEntryDto[]; sharedToGroups: NoteGroupPermissionEntryDto[];
} }
export class NotePermissionsUpdateDto { export class NotePermissionsUpdateDto {
/**
* List of users the note should be shared with
*/
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
sharedToUsers: NoteUserPermissionUpdateDto[]; sharedToUsers: NoteUserPermissionUpdateDto[];
/**
* List of groups the note should be shared with
*/
@IsArray() @IsArray()
@ValidateNested() @ValidateNested()
sharedToGroups: NoteGroupPermissionUpdateDto[]; sharedToGroups: NoteGroupPermissionUpdateDto[];

View file

@ -9,12 +9,22 @@ import { NoteAuthorshipDto } from './note-authorship.dto';
import { NoteMetadataDto } from './note-metadata.dto'; import { NoteMetadataDto } from './note-metadata.dto';
export class NoteDto { export class NoteDto {
/**
* Markdown content of the note
* @example "# I am a heading"
*/
@IsString() @IsString()
content: string; content: string;
/**
* Metadata of the note
*/
@ValidateNested() @ValidateNested()
metadata: NoteMetadataDto; metadata: NoteMetadataDto;
/**
* Authorship information of this note
*/
@IsArray() @IsArray()
@ValidateNested({ each: true }) @ValidateNested({ each: true })
editedByAtPosition: NoteAuthorshipDto[]; editedByAtPosition: NoteAuthorshipDto[];

View file

@ -8,12 +8,24 @@ import { IsDate, IsNumber } from 'class-validator';
import { Revision } from './revision.entity'; import { Revision } from './revision.entity';
export class RevisionMetadataDto { export class RevisionMetadataDto {
/**
* ID of this revision
* @example 13
*/
@IsNumber() @IsNumber()
id: Revision['id']; id: Revision['id'];
/**
* Datestring of the time this revision was created
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
createdAt: Date; createdAt: Date;
/**
* Number of characters in this revision
* @example 142
*/
@IsNumber() @IsNumber()
length: number; length: number;
} }

View file

@ -8,12 +8,30 @@ import { IsDate, IsNumber, IsString } from 'class-validator';
import { Revision } from './revision.entity'; import { Revision } from './revision.entity';
export class RevisionDto { export class RevisionDto {
/**
* ID of this revision
* @example 13
*/
@IsNumber() @IsNumber()
id: Revision['id']; id: Revision['id'];
/**
* Markdown content of the revision
* @example "# I am a heading"
*/
@IsString() @IsString()
content: string; content: string;
/**
* Patch from the preceding revision to this one
*/
@IsString() @IsString()
patch: string; patch: string;
/**
* Datestring of the time this revision was created
* @example "2020-12-01 12:23:34"
*/
@IsDate() @IsDate()
createdAt: Date; createdAt: Date;
} }

View file

@ -4,15 +4,41 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
export class UserInfoDto { export class UserInfoDto {
/**
* The username
* @example "john.smith"
*/
@IsString() @IsString()
userName: string; userName: string;
/**
* The display name
* @example "John Smith"
*/
@IsString() @IsString()
displayName: string; displayName: string;
/**
* URL of the profile picture
* @example "https://hedgedoc.example.com/uploads/johnsmith.png"
*/
@ApiProperty({
format: 'uri',
})
@IsString() @IsString()
photo: string; photo: string;
/**
* Email address of the user
* @example "john.smith@example.com"
*/
@ApiProperty({
format: 'email',
})
@IsString() @IsString()
email: string; email: string;
} }