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

perf: skip validation on default value #1708

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cesco69
Copy link
Contributor

@cesco69 cesco69 commented Oct 24, 2024

performance improvement: if the provided value is the default value, no need to validate

performance improvement: if the provided value is the default value, no need to validate
@cesco69
Copy link
Contributor Author

cesco69 commented Oct 28, 2024

Are these test correct?
https://github.com/lukeautry/tsoa/blob/master/tests/unit/swagger/templateHelpers.spec.ts#L328
https://github.com/lukeautry/tsoa/blob/master/tests/unit/swagger/templateHelpers.spec.ts#L354

In both cases, set default value as string with type integer?

{ dataType: 'integer', default: '666' }

maybe

{ dataType: 'integer', default: 666 }

@WoH
Copy link
Collaborator

WoH commented Oct 30, 2024

Are these test correct? https://github.com/lukeautry/tsoa/blob/master/tests/unit/swagger/templateHelpers.spec.ts#L328 https://github.com/lukeautry/tsoa/blob/master/tests/unit/swagger/templateHelpers.spec.ts#L354

In both cases, set default value as string with type integer?

{ dataType: 'integer', default: '666' }

maybe

{ dataType: 'integer', default: 666 }

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.

@cesco69 cesco69 changed the title performance improvement: skip validation on default value perfimprovement: skip validation on default value Oct 30, 2024
@cesco69 cesco69 changed the title perfimprovement: skip validation on default value perf: skip validation on default value Oct 30, 2024
@@ -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: {} };
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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".

Copy link
Contributor Author

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 ){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if( property.default === value ){
if(property.default === value){

@WoH
Copy link
Collaborator

WoH commented Nov 11, 2024

Nitpicks, otherwise LGTM

@WoH WoH force-pushed the master branch 2 times, most recently from 30cc104 to 82b61ec Compare December 8, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants