-
Notifications
You must be signed in to change notification settings - Fork 2
QueryParameter returns URLSearchParams value #11
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
QueryParameter returns URLSearchParams value #11
Conversation
if (params.explode) { | ||
return Object.entries(params.value) | ||
.map(([k, v]) => `${k}=${v}`) | ||
.join(";"); |
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.
CookieParameterはURLSearchParams使うの良くなさそうなので旧実装もってきて分離しました。
explode: true
の場合の区切り文字は ;
の方が適切な気がしたので変更しています。
Coreの方にあった方がよければそちらに移します。
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.
style: form
、explode: true
でINPUTがobjectの場合以下の行に該当します。
RFC6570上で特にCookie Parameterについて言及を自分は見つけられませんでした。他にこの変更をサポートする仕様はありますか?
参考
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.
このPRはQueryParameterだけにフォーカスして、必要になったらCookie Parameterの方も調整しましょう 🙏
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.
了解です
src/Core.ts
Outdated
@@ -36,75 +36,97 @@ export const generateFromSimple = (key: string | number, params: ParameterOfSimp | |||
return undefined; | |||
}; | |||
|
|||
export const generateFormParamter = (key: string | number, params: ParameterOfForm): string => { | |||
export const generateFormParamter = (key: string | number, params: ParameterOfForm): URLSearchParams | undefined => { |
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.
既存の関数で返り値が変更になるような破壊的変更は望みません。
この関数の内部ではstring
を返すように変更をお願いします。
URLSearchParams
で返すようなAPIを既存の関数と独立してexport
し、ライブラリの利用者がどちらも利用可能な状態にしてください。
他も同様です。
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.
把握です
} | ||
return undefined; | ||
}; | ||
|
||
const generateFormParamter = (key: string | number, params: ParameterOfForm): string => { |
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.
こちらの関数利用したい場合はテストされるようにexport
し、テストを実施してください。
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.
把握です
@@ -90,7 +90,7 @@ describe("QueryParameter - style:spaceDelimited", () => { | |||
style: "spaceDelimited", | |||
explode: false, | |||
}); | |||
expect(result1).toBe("blue%20black%20brown"); | |||
expect(result1).toBe("color=blue+black+brown"); |
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.
ここはOpenAPI Formatterの仕様と異なるようです。
@@ -90,7 +90,7 @@ describe("QueryParameter - style:spaceDelimited", () => { | |||
style: "spaceDelimited", | |||
explode: false, | |||
}); | |||
expect(result1).toBe("blue%20black%20brown"); | |||
expect(result1).toBe("color=blue+black+brown"); |
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.
expect(result1).toBe("color=blue%20black%20brown");
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.
https://qiita.com/masakielastic/items/61f5d9a215c62b55ccf2
このような違いがあるようです。このライブラリはOpenAPI準拠で表すので%20
に寄せます。
@@ -102,7 +102,7 @@ describe("QueryParameter - style:spaceDelimited", () => { | |||
style: "spaceDelimited", | |||
explode: false, | |||
}); | |||
expect(result1).toBe("R%20100%20G%20200%20B%20150"); | |||
expect(result1).toBe("color=R+100+G+200+B+150"); |
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.
expect(result1).toBe("color=R%20100%20G%20200%20B%20150");
Merged #12 |
最終的なシリアライズを使う側でコントロールできるようにするために、QueryParameterはstringではなくURLSearchParamsを返すようにしました