@team-supercharge/oasg 15.0.0 → 15.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
@@ -927,7 +927,7 @@ Validations from OpenAPI spec:
|
|
927
927
|
| isDouble | IsNumber | ✅ | ✅ | ✅ | ✅ | |
|
928
928
|
| isEnum | IsEnum | ✅ | ✅ | ✅ | ✅ | |
|
929
929
|
| isArray | IsArray | ✅ | ✅ | ✅ | ✅ | |
|
930
|
-
| isDate |
|
930
|
+
| isDate | IsValidISO8601Date | ✅ | ✅ | ✅ | ✅ | |
|
931
931
|
| isDateTime | IsISO8601 | ✅ | ✅ | ✅ | ✅ | |
|
932
932
|
| **String** | | | | | | |
|
933
933
|
| pattern | Matches | ✅ | ✅ | ✅ | ✅ | |
|
package/package.json
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { registerDecorator, buildMessage } from "class-validator";
|
2
|
+
|
3
|
+
export const IsValidISO8601Date = () => {
|
4
|
+
return (object: Object, propertyName: string) => {
|
5
|
+
registerDecorator({
|
6
|
+
name: "isValidISO8601Date",
|
7
|
+
target: object.constructor,
|
8
|
+
propertyName: propertyName,
|
9
|
+
constraints: [],
|
10
|
+
options: {},
|
11
|
+
validator: {
|
12
|
+
validate(value: string) {
|
13
|
+
const [year, month, day] = value.split("-").map(Number);
|
14
|
+
const date = new Date(year, month - 1, day);
|
15
|
+
|
16
|
+
// Check if the date components are valid
|
17
|
+
return (
|
18
|
+
date.getFullYear() === year &&
|
19
|
+
date.getMonth() === month - 1 &&
|
20
|
+
date.getDate() === day
|
21
|
+
);
|
22
|
+
},
|
23
|
+
defaultMessage: buildMessage(
|
24
|
+
(eachPrefix) =>
|
25
|
+
eachPrefix +
|
26
|
+
"$property must be a valid ISO 8601 date string (YYYY-mm-DD format)"
|
27
|
+
),
|
28
|
+
},
|
29
|
+
});
|
30
|
+
};
|
31
|
+
};
|
@@ -5,6 +5,7 @@ import { IsString, IsNumber, IsBoolean, IsEnum, IsArray, ValidateNested } from '
|
|
5
5
|
import { Max, Min, IsInt } from 'class-validator';
|
6
6
|
import { Matches, IsEmail, IsUUID } from 'class-validator';
|
7
7
|
import { IsISO8601 } from 'class-validator';
|
8
|
+
import { IsValidISO8601Date } from '../is-valid-iso8601-date.validator';
|
8
9
|
|
9
10
|
export class {{classname}}{{#allParents}}{{#-first}} extends {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/allParents}} { {{>modelGenericAdditionalProperties}}
|
10
11
|
{{#vars}}
|
@@ -19,7 +20,10 @@ export class {{classname}}{{#allParents}}{{#-first}} extends {{/-first}}{{{.}}}{
|
|
19
20
|
@IsEmail(){{/isEmail}}{{#isUuid}}
|
20
21
|
@IsUUID(){{/isUuid}}{{/isString}}{{#isDateTime}}
|
21
22
|
@IsString()
|
22
|
-
@IsISO8601({ strict: true, strictSeparator: true }){{/isDateTime}}{{#
|
23
|
+
@IsISO8601({ strict: true, strictSeparator: true }){{/isDateTime}}{{#isDate}}
|
24
|
+
@IsString()
|
25
|
+
@IsISO8601()
|
26
|
+
@IsValidISO8601Date(){{/isDate}}{{#isInteger}}
|
23
27
|
@IsInt(){{/isInteger}}{{#isLong}}
|
24
28
|
@IsInt(){{/isLong}}{{#isShort}}
|
25
29
|
@IsInt(){{/isShort}}{{#isNumber}}
|