-
Notifications
You must be signed in to change notification settings - Fork 507
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
perf: skip validation on default value #1708
base: master
Are you sure you want to change the base?
Conversation
performance improvement: if the provided value is the default value, no need to validate
Are these test correct? In both cases, set default value as string with type integer?
maybe
|
They should be, I think since we get them as strings Code, we probably never coerce them to the target data type when serializing the spec. |
@@ -325,7 +325,7 @@ describe('ValidationService', () => { | |||
describe('Param validate', () => { | |||
it('should apply defaults for optional properties', () => { | |||
const value = undefined; | |||
const propertySchema: TsoaRoute.PropertySchema = { dataType: 'integer', default: '666', required: false, validators: {} }; | |||
const propertySchema: TsoaRoute.PropertySchema = { dataType: 'integer', default: 666, required: false, validators: {} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert these changes? At least while we don't check/fix when creating the metadata for validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If revert it, test fails... it's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem then is that this is the schema with the default being a string is what we would generate "in the real world".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok, so this PR can't work!
@@ -53,7 +53,10 @@ export class ValidationService { | |||
return value; | |||
} | |||
} | |||
|
|||
// performance improvement: if the provided value is the default value, no need to validate | |||
if( property.default === value ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( property.default === value ){ | |
if(property.default === value){ |
Nitpicks, otherwise LGTM |
30cc104
to
82b61ec
Compare
performance improvement: if the provided value is the default value, no need to validate