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
feat: Impossible to use UUID as param for object construction #706 #708
feat: Impossible to use UUID as param for object construction #706 #708
Conversation
src/ActionParameterHandler.ts
Outdated
typeof value === 'object' && | ||
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type) | ||
) { | ||
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type); |
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.
includes()
would be better in this case
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.
src/ActionParameterHandler.ts
Outdated
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type) | ||
) { | ||
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type); | ||
const isTargetPrimitive = ['number', 'string', 'boolean'].indexOf(param.targetName) > -1; |
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.
Also use includes()
here
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.
test/ActionParameterHandler.spec.ts
Outdated
const expect = require('chakram').expect; | ||
|
||
describe('ActionParameterHandler', () => { | ||
it('handle', async () => { |
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.
You should add negative and positive cases
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.
Broader test coverage was added including two negative tests:
- https://github.com/typestack/routing-controllers/pull/708/files#diff-5c248b2b7632d75cc5c2d989e5b9387fe961cb04f00ef500c93b55ccc93e1a15R128
- https://github.com/typestack/routing-controllers/pull/708/files#diff-5c248b2b7632d75cc5c2d989e5b9387fe961cb04f00ef500c93b55ccc93e1a15R148
PASS test/ActionParameterHandler.spec.ts
ActionParameterHandler
✓ handle - should process string parameters (154 ms)
✓ handle - should process string parameters, returns empty if a given string is empty
✓ handle - should process number parameters (1 ms)
✓ handle - undefined on empty object provided
✓ handle - throws error if the parameter is required
✓ handle - throws error if the parameter is required, type file provided (10 ms)
test/ActionParameterHandler.spec.ts
Outdated
}); | ||
|
||
it('handle - throws error if the parameter is required', async () => { | ||
const driver = new ExpressDriver(); |
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.
You should wrap these negative cases with describe('negative', () => {})
and add beforeEach with
const driver = new ExpressDriver();
const actionParameterHandler = new ActionParameterHandler(driver);
const param = buildParamMetadata('uuid', 'file', true);
test/ActionParameterHandler.spec.ts
Outdated
}); | ||
|
||
it('handle - should process string parameters, returns empty if a given string is empty', async () => { | ||
const driver = new ExpressDriver(); |
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.
Look at my comment above and do the same with describe('positive', () => {})
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.
But, these 3 positive cases have only two common variables:
const driver = new ExpressDriver();
const actionParameterHandler = new ActionParameterHandler(driver);
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.
@qdanik thanks for the review and valuable feedback!
Could you take a look once again, please?
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.
@ivanproskuryakov Looks good for me. Please add @NoNameProvided into Reviewers
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.
@qdanik can't do so myself, this functionality is not available to me.
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.
Looks good for me
@qdanik @nolazybits @fabiob could the PR be merged, please? |
@nolazybits @jvelo @fabiob ping 📦 |
LGTM, but I don't have write access. |
@MichalLytek @jotamorais @NoNameProvided @rustamwin hi, can we merge this PR? |
Co-authored-by: Rustam Mamadaminov <rmamdaminov@gmail.com>
6af1287
typeof value === 'object' && | ||
['queries', 'headers', 'params', 'cookies'].some(paramType => paramType === param.type) | ||
) { | ||
if (isNormalisationNeeded) { |
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 (isNormalisationNeeded) { | |
if (isNormalizationNeeded) { |
33a38c5
to
2a3fa2b
Compare
2a3fa2b
to
039c89f
Compare
@rustamwin closed because to merging conflicts, the new PR - #753 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
The usage of UUID instead of id in routes like http://0.0.0.0:3000/api/products/04879b32-c329-48d7-a652-818794b684f1
Is trying to build JSON object while returning a raw parameter(UUID) provided.
Ref: #703
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
The conditions the inside
normalizeParamValue
now excluding "param" type, keeping UUID strings untouched