-
Notifications
You must be signed in to change notification settings - Fork 762
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
clean code #2289
clean code #2289
Changes from all commits
e35c4a1
f986710
4471555
1521f82
42a7f8b
c7f5035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,10 +160,10 @@ export function normalizeSwagger(parsedSpec) { | |
|
||
const opList = map[oid]; | ||
if (opList.length > 1) { | ||
opList.forEach((o, i) => { | ||
opList.forEach((op, key) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
// eslint-disable-next-line no-underscore-dangle | ||
o.__originalOperationId = o.__originalOperationId || o.operationId; | ||
o.operationId = `${oid}${i + 1}`; | ||
op.__originalOperationId = op.__originalOperationId || op.operationId; | ||
op.operationId = `${oid}${key + 1}`; | ||
}); | ||
} else if (typeof operation.operationId !== 'undefined') { | ||
// Ensure we always add the normalized operation ID if one already exists | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -202,7 +202,7 @@ function formatKeyValue(key, input, skipEncoding = false) { | |||||||||
const { collectionFormat, allowEmptyValue, serializationOption, encoding } = input; | ||||||||||
// `input` can be string | ||||||||||
const value = typeof input === 'object' && !Array.isArray(input) ? input.value : input; | ||||||||||
const encodeFn = skipEncoding ? (k) => k.toString() : (k) => encodeURIComponent(k); | ||||||||||
const encodeFn = (k) => (skipEncoding ? k.toString() : encodeURIComponent(k)); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering here what is the motivation and arguments behind your change? If I would to simplify this I'd probably go with the following:
Suggested change
Explanation: it's a simple ternary that chooses an appropriate function to be used as value of |
||||||||||
const encodedKey = encodeFn(key); | ||||||||||
|
||||||||||
if (typeof value === 'undefined' && allowEmptyValue) { | ||||||||||
|
@@ -290,8 +290,10 @@ function formatKeyValueBySerializationOption(key, value, skipEncoding, serializa | |||||||||
: serializationOption && serializationOption.allowReserved | ||||||||||
? 'unsafe' | ||||||||||
: 'reserved'; | ||||||||||
const encodeFn = (v) => encodeDisallowedCharacters(v, { escape }); | ||||||||||
const encodeKeyFn = skipEncoding ? (k) => k : (k) => encodeDisallowedCharacters(k, { escape }); | ||||||||||
const encodeFn = (str) => encodeDisallowedCharacters(str, { escape }); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using If our goal is simplifying the cleaning the code what would you say to following?
Suggested change
|
||||||||||
const encodeKeyFn = skipEncoding | ||||||||||
? (str) => str | ||||||||||
: (str) => encodeDisallowedCharacters(str, { escape }); | ||||||||||
|
||||||||||
// Primitive | ||||||||||
if (typeof value !== 'object') { | ||||||||||
|
@@ -432,8 +434,8 @@ export function mergeInQueryOrForm(req = {}) { | |||||||||
|
||||||||||
// Wrap a http function ( there are otherways to do this, consider this deprecated ) | ||||||||||
export function makeHttp(httpFn, preFetch, postFetch) { | ||||||||||
postFetch = postFetch || ((a) => a); | ||||||||||
preFetch = preFetch || ((a) => a); | ||||||||||
postFetch = postFetch || ((req) => req); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding variable naming - yeah, great change!
|
||||||||||
preFetch = preFetch || ((req) => req); | ||||||||||
return (req) => { | ||||||||||
if (typeof req === 'string') { | ||||||||||
req = { url: req }; | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -97,7 +97,7 @@ class SpecMap { | |||||
return true; | ||||||
} | ||||||
|
||||||
return path.every((val, i) => val === tested[i]); | ||||||
return path.every((val, key) => val === tested[key]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
}; | ||||||
|
||||||
return function* generator(patches, specmap) { | ||||||
|
@@ -342,7 +342,7 @@ class SpecMap { | |||||
|
||||||
// A different plugin runs, wait for all promises to resolve, then retry | ||||||
if (plugin !== this.currentPlugin && this.promisedPatches.length) { | ||||||
const promises = this.promisedPatches.map((p) => p.value); | ||||||
const promises = this.promisedPatches.map((parameter) => parameter.value); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. origina
Suggested change
|
||||||
|
||||||
// Waits for all to settle instead of Promise.all which stops on rejection | ||||||
return Promise.all(promises.map((promise) => promise.then(noop, noop))).then(() => | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,9 @@ export default { | |
const val = { ...properties }; | ||
|
||
// eslint-disable-next-line no-restricted-syntax, guard-for-in | ||
for (const k in properties) { | ||
for (const position in properties) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about changing |
||
try { | ||
val[k].default = specmap.modelPropertyMacro(val[k]); | ||
val[position].default = specmap.modelPropertyMacro(val[position]); | ||
} catch (e) { | ||
const err = new Error(e); | ||
err.fullPath = fullPath; // This is an array | ||
|
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.
Why we added import to Buffer here? We got rid of it in e96702f