mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
fix: incorrect serialization of parameter sample with hypen
This commit is contained in:
parent
299a59faad
commit
f7dd658a01
|
@ -163,11 +163,20 @@ function deepObjectEncodeField(fieldVal: any, fieldName: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
// URI.Template doesn't support names with hypen, while OpenAPI allow
|
||||
function escapeURITemplateName(template: string): string {
|
||||
return template.replace(/-/g, '%2D');
|
||||
}
|
||||
|
||||
function unescapeURITemplateName(template: string): string {
|
||||
return template.replace(/%2D/g, '-');
|
||||
}
|
||||
|
||||
function serializeFormValue(name: string, explode: boolean, value: any) {
|
||||
name = escapeURITemplateName(name);
|
||||
const suffix = explode ? '*' : '';
|
||||
const template = new URI.Template(`{?${name}${suffix}}`);
|
||||
|
||||
return template.expand({ [name]: value }).substring(1);
|
||||
return unescapeURITemplateName(template.expand({ [name]: value }).substring(1));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -188,7 +197,6 @@ export function urlFormEncodePayload(
|
|||
switch (style) {
|
||||
case 'form':
|
||||
return serializeFormValue(fieldName, explode, fieldVal);
|
||||
break;
|
||||
case 'spaceDelimited':
|
||||
return delimitedEncodeField(fieldVal, fieldName, '%20');
|
||||
case 'pipeDelimited':
|
||||
|
@ -211,6 +219,7 @@ function serializePathParameter(
|
|||
explode: boolean,
|
||||
value: any,
|
||||
): string {
|
||||
name = escapeURITemplateName(name);
|
||||
const suffix = explode ? '*' : '';
|
||||
let prefix = '';
|
||||
|
||||
|
@ -222,7 +231,7 @@ function serializePathParameter(
|
|||
|
||||
const template = new URI.Template(`{${prefix}${name}${suffix}}`);
|
||||
|
||||
return template.expand({ [name]: value });
|
||||
return unescapeURITemplateName(template.expand({ [name]: value }));
|
||||
}
|
||||
|
||||
function serializeQueryParameter(
|
||||
|
@ -273,12 +282,13 @@ function serializeHeaderParameter(
|
|||
explode: boolean,
|
||||
value: any,
|
||||
): string {
|
||||
name = escapeURITemplateName(name);
|
||||
switch (style) {
|
||||
case 'simple':
|
||||
const suffix = explode ? '*' : '';
|
||||
const template = new URI.Template(`{${name}${suffix}}`);
|
||||
|
||||
return template.expand({ [name]: value });
|
||||
return unescapeURITemplateName(template.expand({ [name]: value }));
|
||||
default:
|
||||
console.warn('Unexpected style for header: ' + style);
|
||||
return '';
|
||||
|
|
Loading…
Reference in New Issue
Block a user