-
Notifications
You must be signed in to change notification settings - Fork 338
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
Compare content type parameters separately #1159
Conversation
b0af738
to
86c3e58
Compare
86c3e58
to
7675796
Compare
0978cc4
to
cd31e13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a changelog if this is something that is user-visible. I'm not sure, TBH 😄
f2679b5
to
0c265e0
Compare
344df58
to
aa54ed6
Compare
aa54ed6
to
c286dd6
Compare
afa29ef
to
d4d4ab9
Compare
dbbb502
to
5302c23
Compare
f50bed8
to
393b2c9
Compare
393b2c9
to
2286cd2
Compare
b40fd4f
to
2f85784
Compare
@@ -1 +1 @@ | |||
* @XVincentX @marcelltoth @karol-maciaszek | |||
* @XVincentX @karol-maciaszek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😩
pipe( | ||
mediaTypes | ||
.map(mt => contentType.parse(mt)) | ||
.filter(mt => Object.keys(mt.parameters).length > 0) | ||
.map(mt => mt.type), | ||
fromArray, | ||
O.chain(mediaTypesWithNoParameters => findBestHttpContentByMediaType(contents, mediaTypesWithNoParameters)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically a "retry with only the Q parameter"
exampleKey, | ||
}, | ||
response | ||
return pipe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is huge but all I did here for real was to move the if(mediatypes) in the pipe
@@ -289,19 +291,19 @@ const helpers = { | |||
pipe( | |||
previous, | |||
O.alt(() => { | |||
logger.trace(`Unable to find a ${statusCodes[index]} response definition`); | |||
logger.debug(`Unable to find a ${statusCodes[index]} response definition`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trace is not caught by our signals logger, so I moved it back to debug as it should be
findEmptyResponse( | ||
response, | ||
response.headers || [], | ||
get(contentWithExamples, 'mediaType', get(responseWithSchema, 'schema')) || ['*/*'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentWithExamples
is always undefined in this branch, that's why I've removed it
7e37d17
to
2ab18ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work and nice package of improvements. I dropped a few comments.
pipe( | ||
mediaTypes | ||
.map(mt => contentType.parse(mt)) | ||
.filter(mt => Object.keys(mt.parameters).filter(k => k !== 'q').length > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter(mt => Object.keys(mt.parameters).filter(k => k !== 'q').length > 0) | |
.filter(({ parameters }) => Object.keys(parameters).find(k => k !== 'q')) |
or for more clarity:
.filter(mt => Object.keys(mt.parameters).filter(k => k !== 'q').length > 0) | |
.filter(({ parameters }) => !!Object.keys(parameters).find(k => k !== 'q')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point. @karol-maciaszek how about this: bbb4c73
@@ -10,7 +10,7 @@ describe('InternalHelpers', () => { | |||
}; | |||
|
|||
it('should respect the q parameter', () => { | |||
const possibleResponse = findBestHttpContentByMediaType(avaiableResponses, [ | |||
const possibleResponse = findBestHttpContentByMediaType(avaiableResponses.contents, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const possibleResponse = findBestHttpContentByMediaType(avaiableResponses.contents, [ | |
const possibleResponse = findBestHttpContentByMediaType(availableResponses.contents, [ |
Will need updates in the code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | ||
}); | ||
|
||
describe('multiple media types avaiable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('multiple media types avaiable', () => { | |
describe('multiple media types available', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ mediaType: 'application/json; version=1; q=1' }, | ||
{ mediaType: 'application/json; version=1; q=0.6' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ mediaType: 'application/json; version=1; q=1' }, | |
{ mediaType: 'application/json; version=1; q=0.6' }, | |
{ mediaType: 'application/json; version=1; q=0.6' }, | |
{ mediaType: 'application/json; version=1; q=1' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | ||
|
||
describe('and the requeste media type matches, but has parameter', () => { | ||
const result = validator.validateMediaType([content], 'application/vnd.archa.api+json; version=1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have bad experience in tracking errors outside it()
functions. Anything against moving to it()
?
@marcelltoth I added the changelog line indeed. |
Co-authored-by: Karol Maciaszek <karol@maciaszek.pl>
Co-authored-by: Karol Maciaszek <karol@maciaszek.pl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it!
* compare parameters separately * tmp: mediaType from nullable * use isMatch * Parse media type only once * tmp changes * keep the chain as much as possible * add launch.json instructions * remove incorrect assumption * you can alwasy create an empty response * avoid nesting * create empty response cannot fail * do not bloat with stuff we do not need * restore stuff * restore * chore: restrict surface * reduce stuff * pipe all together * replace with debug * bye bye marcell * test: add validator test * use realish media types * remove parameters and try again * eeek * docs: changelog * test: add * test: refactor and add * test: harness * remove only * keep the q parameter * add yet another test * refactor: use some * spell error * spell error again * reverse order to make sure test is not passing by chance * move data retr in it block * move tests in internal helpers where they should be2 * test fix * Update packages/http/src/validator/__tests__/index.spec.ts Co-authored-by: Karol Maciaszek <karol@maciaszek.pl> * Update packages/http/src/validator/__tests__/index.spec.ts Co-authored-by: Karol Maciaszek <karol@maciaszek.pl> Co-authored-by: Karol Maciaszek <karol@maciaszek.pl>
This pull request implements a backup strategy to ignore parameters in content type when is possible. Since they're not standard (apart for the
q
value) we won't assume anything about it and drop them in some casesCloses #1152