({ path, url: _url }: PathSerializer)
| 16 | export const PATH_PARAM_RE = /\{[^{}]+\}/g |
| 17 | |
| 18 | export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => { |
| 19 | let url = _url |
| 20 | const matches = _url.match(PATH_PARAM_RE) |
| 21 | if (matches) { |
| 22 | for (const match of matches) { |
| 23 | let explode = false |
| 24 | let name = match.substring(1, match.length - 1) |
| 25 | let style: ArraySeparatorStyle = "simple" |
| 26 | |
| 27 | if (name.endsWith("*")) { |
| 28 | explode = true |
| 29 | name = name.substring(0, name.length - 1) |
| 30 | } |
| 31 | |
| 32 | if (name.startsWith(".")) { |
| 33 | name = name.substring(1) |
| 34 | style = "label" |
| 35 | } else if (name.startsWith(";")) { |
| 36 | name = name.substring(1) |
| 37 | style = "matrix" |
| 38 | } |
| 39 | |
| 40 | const value = path[name] |
| 41 | |
| 42 | if (value === undefined || value === null) { |
| 43 | continue |
| 44 | } |
| 45 | |
| 46 | if (Array.isArray(value)) { |
| 47 | url = url.replace(match, serializeArrayParam({ explode, name, style, value })) |
| 48 | continue |
| 49 | } |
| 50 | |
| 51 | if (typeof value === "object") { |
| 52 | url = url.replace( |
| 53 | match, |
| 54 | serializeObjectParam({ |
| 55 | explode, |
| 56 | name, |
| 57 | style, |
| 58 | value: value as Record<string, unknown>, |
| 59 | valueOnly: true, |
| 60 | }), |
| 61 | ) |
| 62 | continue |
| 63 | } |
| 64 | |
| 65 | if (style === "matrix") { |
| 66 | url = url.replace( |
| 67 | match, |
| 68 | `;${serializePrimitiveParam({ |
| 69 | name, |
| 70 | value: value as string, |
| 71 | })}`, |
| 72 | ) |
| 73 | continue |
| 74 | } |
| 75 |
no test coverage detected