-
-
Notifications
You must be signed in to change notification settings - Fork 418
Add possibility to change default request params #1466
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
6da2bce
18ae2cf
63cd658
8d62600
e1c2ff4
1f73987
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "swagger-typescript-api": patch | ||
| --- | ||
|
|
||
| Add possibility to change default request params | ||
|
|
||
| Useful when overriding the http client, and you want to make sure the request params are set. | ||
|
|
||
| Can be set to `""` in order to not make it optional. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ const requestConfigParam = { | |
| name: specificArgNameResolver.resolve(RESERVED_REQ_PARAMS_ARG_NAMES), | ||
| optional: true, | ||
| type: "RequestParams", | ||
| defaultValue: "{}", | ||
| defaultValue: config.defaultRequestParams ?? "{}", | ||
|
Comment on lines
16
to
19
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.
When Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| const argToTmpl = ({ name, optional, type, defaultValue }) => `${name}${!defaultValue && optional ? '?' : ''}: ${type}${defaultValue ? ` = ${defaultValue}` : ''}`; | ||
|
|
||
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.
Bug: Empty String Falsely Treated as Optional Parameter
When
config.defaultRequestParamsis an empty string"", theargToTmplfunction's!defaultValuecheck treats it as falsy. This incorrectly makes the parameter optional, contradicting the intent that an empty string should result in a required parameter without a default value.Additional Locations (1)
templates/modular/procedure-call.ejs#L18-L19Uh oh!
There was an error while loading. Please reload this page.
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.
Its intentional, see https://github.com/acacode/swagger-typescript-api/pull/1466/files#diff-e500dd0aa7886ed111db6230d9cf8ab5a78cdc81b0ef66a9ee8c184efe6807b1R39
test("defaultRequestParams with empty default", async () => {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.
It was an actual bug. Create a fix in e1c2ff4