PowershellFrameworkCollective / psframework

A module that provides tools for other modules and scripts
MIT License
427 stars 41 forks source link

Change Case with `ConvertTo-PSFHashTable -Remap` param #641

Closed Callidus2000 closed 1 week ago

Callidus2000 commented 4 weeks ago

Hi Fred, I need to convert parameters to a specific camelcase (for forwarding case insensitive function parameters to a case sensitive REST API).

Normally I use $PSBoundParameters | ConvertTo-PSFHashTable for generating the parameter variable, but with the case sensitivity it's not working.

# Example HashTable with missmatching case - API needs param lowercase
C:\> @{HubbA=123}|ConvertTo-Json -Compress
{"HubbA":123}

# Trying to use the remap param for it does not return a result at all
C:\> @{HubbA=123}|ConvertTo-PSFHashtable -Remap @{hubba='hubba'}|ConvertTo-Json -Compress
{}

# Adding CaseSenitive switch does generate a result, but the wrong one
C:\> @{HubbA=123}|ConvertTo-PSFHashtable -Remap @{hubba='hubba'} -CaseSensitive|ConvertTo-Json -Compress
{"HubbA":123}

# Doing it twice does the job but is ugly
C:\> @{HubbA=123}|ConvertTo-PSFHashtable -Remap @{hubba='bubba'}|ConvertTo-PSFHashtable -Remap @{bubba='hubba'}|ConvertTo-Json -Compress
{"hubba":123}

Could such thing be added?

FriedrichWeinmann commented 2 weeks ago

Case 2 should have worked, but did not due to an implementation bug, fixed in the next version (coming up)

FriedrichWeinmann commented 2 weeks ago

Fixed in 1.12.345