Skip to content

feat: parameter deserialization #3116

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sdo-1A
Copy link
Contributor

@sdo-1A sdo-1A commented Apr 10, 2025

Proposed change

Provide deserialization functions as a tool to deserialize query and path parameters.
This PR was created as a split of PR #3076

Related issues

- No issue associated -

@sdo-1A sdo-1A requested a review from a team as a code owner April 10, 2025 13:00
Copy link

nx-cloud bot commented Apr 10, 2025

View your CI Pipeline Execution ↗ for commit 4d0e172.

Command Status Duration Result
nx run-many --target=test-int ✅ Succeeded 11m 57s View ↗
nx run-many --target=test-e2e ✅ Succeeded 3m 42s View ↗
nx run-many --target=build --projects=eslint-pl... ✅ Succeeded 2s View ↗
nx run-many --target=publish --nx-bail --userco... ✅ Succeeded 32s View ↗
nx run-many --target=prepare-publish --exclude-... ✅ Succeeded 7s View ↗
nx run-many --target=build,build-swagger ✅ Succeeded 6m 40s View ↗
nx affected --target=test --collectCoverage --c... ✅ Succeeded 21s View ↗
nx run ama-sdk-schematics:build-swagger ✅ Succeeded 4s View ↗
Additional runs (3) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-04-30 16:09:33 UTC

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.87%. Comparing base (2fa4a61) to head (4d0e172).
Report is 137 commits behind head on main.

✅ All tests successful. No failed tests found.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sdo-1A sdo-1A force-pushed the feat/param-deserialization branch from 8a7ca39 to 50908c7 Compare April 10, 2025 16:12
it('should correctly deserialize query parameters of type array', () => {
expect(deserializeQueryParams({ idArray: 'idArray=3&idArray=4&idArray=5' }, { idArray: { explode: true, style: 'form', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
expect(deserializeQueryParams({ idArray: 'idArray=3,4,5' }, { idArray: { explode: false, style: 'form', paramType: 'array' } })).toEqual({ idArray: ['3', '4', '5'] });
expect(deserializeQueryParams({ idArray: 'should-not-work' }, { idArray: { explode: true, style: 'spaceDelimited', paramType: 'array' } })).toEqual({ idArray: undefined });
Copy link
Contributor

Choose a reason for hiding this comment

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

should this return undefined or throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should return undefined, we don't throw errors for non-supported use cases

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect a function like this to throw when the format is not recognized, but I'm ok to return undefined

fpaul-1A
fpaul-1A previously approved these changes Apr 10, 2025
mrednic-1A
mrednic-1A previously approved these changes Apr 11, 2025
import {
CLOSING_SQUARE_BRACKET_URL_CODE,
OPENING_SQUARE_BRACKET_URL_CODE,
ParamSerialization,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ParamSerialization,
type ParamSerialization,

?

acc[queryParamName as keyof T] = deserializedValue;
}
return acc;
}, {} as { [p in keyof T]: SupportedParamType });
Copy link
Contributor

Choose a reason for hiding this comment

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

the type is a bit incorrect as this stage (accept if T is {}).
Maybe it would be more something like:

Suggested change
}, {} as { [p in keyof T]: SupportedParamType });
}, {} as Record<string, SupportedParamType>) as { [p in keyof T]: SupportedParamType };

Copy link
Contributor Author

@sdo-1A sdo-1A Apr 30, 2025

Choose a reason for hiding this comment

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

Isn't it fine to accept {} ? Because we have conditions in the functions to avoid unsupported use cases so it possible that we return an empty object
If I change the type to Record<string, SupportedParamType>, we could not return an empty object {}

Copy link
Contributor

Choose a reason for hiding this comment

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

{ [p in keyof T]: SupportedParamType } means that all fields of the object T should be present in your object. So if T has more than 1 field, the code {} as { [p in keyof T]: SupportedParamType } is wrong.

The purpose is not to change the return type (which remains { [p in keyof T]: SupportedParamType }) but the acc type to avoid wrong typing.

acc[pathParamName as keyof T] = deserializedValue;
}
return acc;
}, {} as { [p in keyof T]: SupportedParamType });
Copy link
Contributor

@kpanot kpanot Apr 11, 2025

Choose a reason for hiding this comment

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

Same comment as above:

Suggested change
}, {} as { [p in keyof T]: SupportedParamType });
}, {} as Record<string, SupportedParamType>);

@sdo-1A sdo-1A dismissed stale reviews from mrednic-1A and fpaul-1A via 4d0e172 April 30, 2025 15:41
@sdo-1A sdo-1A force-pushed the feat/param-deserialization branch from 50908c7 to 4d0e172 Compare April 30, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants