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: Fix API Parameter Type Bug Causing Undefined Error and Unintended Required Status #314

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion packages/core/src/lib/utils/normalizedStringValue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isUndefined } from 'lodash';
import { UserError } from './errors';

export const canBeNormalized = (type: string) => {
Expand All @@ -7,10 +8,14 @@ export const canBeNormalized = (type: string) => {
};

export const normalizeStringValue = (
value: string,
value: string | undefined,
dataName: string,
dataType: string
) => {
if (isUndefined(value)) {
return undefined;
}

switch (dataType.toLowerCase()) {
case 'number': {
if (value === '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class DateTypeValidator extends InputValidator {
}

public validateData(value: string, args?: DateInputArgs) {
if (isUndefined(value)) return;

let valid = dayjs(value).isValid();
// if there are args passed
if (!isUndefined(args)) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/test/utils/normalizedStringValue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ it.each([
['number', '1234', 1234],
['number', '-1234', -1234],
['number', '0', 0],
['number', undefined, undefined],
['boolean', '', true],
['boolean', '1', true],
['boolean', 'true', true],
['boolean', '0', false],
['boolean', 'false', false],
['boolean', undefined, undefined],
['date', '2022-08-23 14:44:23', new Date('2022-08-23 14:44:23')],
['date', undefined, undefined],
['string', '1234', '1234'],
['string', 'true', 'true'],
['string', '', ''],
['string', undefined, undefined],
])(
`Normalizer should return correct value with type %s and value %p`,
(type, value, expectedValue) => {
Expand Down