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

(fix) Handled the case of passing a function that returns a date to the MaxDate decorator #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 23 additions & 17 deletions src/defaultConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const defaultConverters: ISchemaConverters = {
if (typeof meta.target === 'function') {
const typeMeta = options.classTransformerMetadataStorage
? options.classTransformerMetadataStorage.findTypeMetadata(
meta.target,
meta.propertyName
)
meta.target,
meta.propertyName
)
: null
const childType = typeMeta
? typeMeta.typeFunction()
Expand Down Expand Up @@ -141,20 +141,26 @@ export const defaultConverters: ISchemaConverters = {
maximum: meta.constraints[0],
type: 'number',
}),
[cv.MIN_DATE]: (meta) => ({
description: `After ${meta.constraints[0].toJSON()}`,
oneOf: [
{ format: 'date', type: 'string' },
{ format: 'date-time', type: 'string' },
],
}),
[cv.MAX_DATE]: (meta) => ({
description: `Before ${meta.constraints[0].toJSON()}`,
oneOf: [
{ format: 'date', type: 'string' },
{ format: 'date-time', type: 'string' },
],
}),
[cv.MIN_DATE]: (meta) => {
const description = typeof meta.constraints[0] === 'function' ? `After a date computed dynamically` : `After ${meta.constraints[0]}`;
return {
description,
oneOf: [
{ format: 'date', type: 'string' },
{ format: 'date-time', type: 'string' },
],
}
},
[cv.MAX_DATE]: (meta) => {
const description = typeof meta.constraints[0] === 'function' ? `Before a date computed dynamically` : `Before ${meta.constraints[0]}`;
return {
description,
oneOf: [
{ format: 'date', type: 'string' },
{ format: 'date-time', type: 'string' },
],
}
},
[cv.IS_BOOLEAN_STRING]: {
enum: ['true', 'false'],
type: 'string',
Expand Down