swagger-api / swagger-js

Javascript library to connect to swagger-enabled APIs via browser or nodejs
http://swagger.io
Apache License 2.0
2.62k stars 760 forks source link

Rework encodeDisallowedCharacters function for OpenAPI 3.x request builders #3462

Closed glowcloud closed 6 months ago

glowcloud commented 6 months ago

encodeDisallowedCharacters function https://github.com/swagger-api/swagger-js/blob/f327d4bd28aa5d3ed646b412f8ec9422fe55441a/src/execute/oas3/style-serializer.js#L5 contains logic that should be moved out of it - the function should only encode characters. We can move the logic for converting numbers to strings and returning empty strings or non-string type values to the valueEncoder function. It should take care of converting all values to strings as it does now for objects and arrays. https://github.com/swagger-api/swagger-js/blob/f327d4bd28aa5d3ed646b412f8ec9422fe55441a/src/execute/oas3/style-serializer.js#L59

We can also remove the parse parameter as it is not used anywhere.

The signature of the function should be encodeCharacters(str, { characterSet = 'reserved' } = {} and the logic for returning non-encoded strings for when the escape value is set to false should also be moved to valueEncoder.

char0n commented 6 months ago

Addressed in https://github.com/swagger-api/swagger-js/pull/3463