Skip to content

Commit

Permalink
fix: use url-template dependency (#1008)
Browse files Browse the repository at this point in the history
Fixes #1007
  • Loading branch information
MrFix93 authored and RomanHotsiy committed Sep 30, 2019
1 parent aceb343 commit 32a464a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"stickyfill": "^1.1.1",
"swagger2openapi": "^5.3.1",
"tslib": "^1.10.0",
"uri-template-lite": "^19.4.0"
"url-template": "^2.0.8"
},
"bundlesize": [
{
Expand Down
6 changes: 2 additions & 4 deletions src/utils/__tests__/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe('Utils', () => {
{ style: 'simple', explode: false, expected: 'role,admin,firstName,Alex' },
{ style: 'simple', explode: true, expected: 'role=admin,firstName=Alex' },
{ style: 'label', explode: false, expected: '.role,admin,firstName,Alex' },
{ style: 'label', explode: true, expected: '.role=admin,firstName=Alex' },
{ style: 'label', explode: true, expected: '.role=admin.firstName=Alex' },
{ style: 'matrix', explode: false, expected: ';id=role,admin,firstName,Alex' },
{ style: 'matrix', explode: true, expected: ';role=admin;firstName=Alex' },
],
Expand Down Expand Up @@ -516,9 +516,7 @@ describe('Utils', () => {
locationTestGroup.cases.forEach(valueTypeTestGroup => {
describe(valueTypeTestGroup.description, () => {
valueTypeTestGroup.cases.forEach(testCase => {
it(`should serialize correctly when style is ${testCase.style} and explode is ${
testCase.explode
}`, () => {
it(`should serialize correctly when style is ${testCase.style} and explode is ${testCase.explode}`, () => {
const parameter: OpenAPIParameter = {
name: locationTestGroup.name,
in: locationTestGroup.location,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname } from 'path';
import { URI } from 'uri-template-lite';
const URLtemplate = require('url-template');

import { OpenAPIParser } from '../services/OpenAPIParser';
import {
Expand Down Expand Up @@ -168,7 +168,7 @@ function serializeFormValue(name: string, explode: boolean, value: any) {
// e.g. URI.template doesn't parse names with hypen (-) which are valid query param names
const safeName = '__redoc_param_name__';
const suffix = explode ? '*' : '';
const template = new URI.Template(`{?${safeName}${suffix}}`);
const template = URLtemplate.parse(`{?${safeName}${suffix}}`);
return template
.expand({ [safeName]: value })
.substring(1)
Expand Down Expand Up @@ -227,7 +227,7 @@ function serializePathParameter(
// Use RFC6570 safe name ([a-zA-Z0-9_]) and replace with our name later
// e.g. URI.template doesn't parse names with hypen (-) which are valid query param names
const safeName = '__redoc_param_name__';
const template = new URI.Template(`{${prefix}${safeName}${suffix}}`);
const template = URLtemplate.parse(`{${prefix}${safeName}${suffix}}`);

return template.expand({ [safeName]: value }).replace(/__redoc_param_name__/g, name);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ function serializeHeaderParameter(

// name is not important here, so use RFC6570 safe name ([a-zA-Z0-9_])
const name = '__redoc_param_name__';
const template = new URI.Template(`{${name}${suffix}}`);
const template = URLtemplate.parse(`{${name}${suffix}}`);
return decodeURIComponent(template.expand({ [name]: value }));
default:
console.warn('Unexpected style for header: ' + style);
Expand Down

0 comments on commit 32a464a

Please sign in to comment.