Skip to content

Commit

Permalink
Handle IsObject and IsNotEmptyObject
Browse files Browse the repository at this point in the history
  • Loading branch information
epiphone committed Dec 31, 2020
1 parent 935f8b6 commit 22258da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
ArrayNotContains,
IsBoolean,
IsEmpty,
IsNotEmptyObject,
IsObject,
IsOptional,
IsString,
Length,
Expand All @@ -12,8 +14,6 @@ import {
ValidateNested,
} from 'class-validator'
import { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata'
import * as _ from 'lodash'

import { validationMetadatasToSchemas } from '../src'

class User {
Expand All @@ -29,6 +29,12 @@ class User {
tags: string[]

@IsEmpty() empty: string

@IsObject() object: object

@IsNotEmptyObject()
@IsOptional()
nonEmptyObject: {}
}

// @ts-ignore: not referenced
Expand Down Expand Up @@ -126,6 +132,8 @@ describe('classValidatorConverter', () => {
},
firstName: { minLength: 5, type: 'string' },
id: { type: 'string' },
object: { type: 'object' },
nonEmptyObject: { type: 'object', minProperties: 1 },
tags: {
items: {
maxLength: 20,
Expand All @@ -138,7 +146,7 @@ describe('classValidatorConverter', () => {
type: 'array',
},
},
required: ['id', 'firstName'],
required: ['id', 'firstName', 'object'],
type: 'object',
},
})
Expand Down
7 changes: 7 additions & 0 deletions src/defaultConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ export const defaultConverters: ISchemaConverters = {
[cv.IS_UPPERCASE]: {
type: 'string',
},
[cv.IS_OBJECT]: {
type: 'object',
},
[cv.IS_NOT_EMPTY_OBJECT]: {
type: 'object',
minProperties: 1,
},
[cv.MIN_LENGTH]: (meta) => ({
minLength: meta.constraints[0],
type: 'string',
Expand Down

0 comments on commit 22258da

Please sign in to comment.