Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyphenless followup #1192

Merged
merged 43 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
357118d
fix: handle hyphens in path parameters
chohmann May 19, 2020
fb20ad1
Merge branch 'master' into fix/hyphenated_query_params
XVincentX May 19, 2020
879bae2
fix: handle hyphens when generating example paths
chohmann May 19, 2020
eafc968
Merge branch 'fix/hyphenated_query_params' of github.com:stoplightio/…
chohmann May 20, 2020
98fa507
test: input validation with hypens in path params
chohmann May 20, 2020
c4981cb
test: paths util with hyphens tests
chohmann May 20, 2020
aa353e5
chore: remove the .only from tests
chohmann May 20, 2020
527defb
fix: put real values back into URL
chohmann May 20, 2020
6bb759d
test: test for query params with hyphens
chohmann May 20, 2020
6fd670e
fix: safer approach for adding real names back
chohmann May 20, 2020
28cba6a
test: tests that will fail with unsafe approach
chohmann May 20, 2020
f8ac487
fix: don’t let urijs escape %20 to +
chohmann May 21, 2020
358bea1
chore: move types dev-dep to root package.json
chohmann May 21, 2020
697ab22
remove depreacted software
XVincentX May 21, 2020
91a47ef
fix: pass file path or schema object to dereference
chohmann May 21, 2020
64eb8ac
test: update tests to pass in schema object instead of string
chohmann May 21, 2020
bcd7df2
fix indentation
XVincentX May 21, 2020
722f4fa
fix: add missing info block
chohmann May 21, 2020
65cb942
Merge branch 'fix/hyphenated_query_params' of github.com:stoplightio/…
chohmann May 21, 2020
94206fc
test: hyphen query/path param harness tests
chohmann May 22, 2020
b9c2d8a
chore: update harness readme with troubleshooting tips
chohmann May 22, 2020
066041f
test: update validator test
chohmann May 22, 2020
6dd4f44
chore: toString() instead of valueOf()
chohmann May 22, 2020
779a7f6
chore: refactor for loop into reduce
chohmann May 22, 2020
2a272cf
chore: type the getPathParams function
chohmann May 22, 2020
c73999d
chore: refactor out detectTransformOperationsFn
chohmann May 22, 2020
34e0b7f
chore: refactor remove detectTransformOperationsFn
chohmann May 22, 2020
93f9fb2
Merge branch 'fix/hyphenated_query_params' of github.com:stoplightio/…
chohmann May 22, 2020
58d0e14
feat: use query object
XVincentX May 22, 2020
0afa9de
bring stuff back
XVincentX May 22, 2020
377d0a5
Merge branch 'master' into feat/hypheless-map
XVincentX May 22, 2020
b32a51e
docs: changelog line
XVincentX May 22, 2020
13f5244
remove getHttpOperationsFromResource function
XVincentX May 24, 2020
ebfe4c2
Update urijs
XVincentX May 25, 2020
a150a8d
Merge branch 'master' into feat/hypheless-map
XVincentX May 25, 2020
0d555e0
Merge branch 'master' into feat/hypheless-map
XVincentX May 25, 2020
6d7c311
fix: OpenAPI 3 harness tests for hyphen handling fix (#1211)
karol-maciaszek May 25, 2020
1279e7c
fix
XVincentX May 25, 2020
fe6167d
use flow
XVincentX May 25, 2020
59be21e
Merge branch 'master' into feat/hypheless-map
XVincentX May 25, 2020
86ef3b8
upgrade uri tempalte lite
XVincentX May 26, 2020
828821a
revert custom code
XVincentX May 26, 2020
c2b98f9
Update packages/cli/src/util/paths.ts
XVincentX May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: handle hyphens when generating example paths
  • Loading branch information
chohmann committed May 19, 2020
commit 879bae256b6c0583cfd1aa4345539ade201b7f38
15 changes: 12 additions & 3 deletions packages/cli/src/util/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ export function createExamplePath(
): E.Either<Error, string> {
return DoEither.bind('pathData', generateTemplateAndValuesForPathParams(operation))
.bindL('queryData', ({ pathData }) => generateTemplateAndValuesForQueryParams(pathData.template, operation))
.return(({ pathData, queryData }) =>
URI.expand(queryData.template, transformValues({ ...pathData.values, ...queryData.values }))
);
.return(({ pathData, queryData }) => {
// replace "-" in template path and query params
const cleanedTemplate = queryData.template.replace(/(?<=\{.*)(?=.*\})(-)/g, '');
const realValues = transformValues({ ...pathData.values, ...queryData.values });
const cleanedValues = {};
for (const realValue in realValues) {
const cleanedValue = realValue.replace(/-/g, '');
cleanedValues[cleanedValue] = realValues[realValue];
}

return URI.expand(cleanedTemplate, cleanedValues);
});
}

function generateParamValue(spec: IHttpParam): E.Either<Error, unknown> {
Expand Down
7 changes: 2 additions & 5 deletions packages/http/src/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ const validateOutput: ValidatorFn<IHttpOperation, IHttpResponse> = ({ resource,
};

function getPathParams(path: string, template: string, realParams: IHttpPathParam[]) {
// replace "-" in template path params
const cleanedTemplate = template
.split('/')
.map(part => (part.startsWith('{') ? part.replace(/-/g, '') : part))
.join('/');
// replace "-" in template path and query params
const cleanedTemplate = template.replace(/(?<=\{.*)(?=.*\})(-)/g, '');

const pathParams = new URI.Template(cleanedTemplate).match(path);

Expand Down