-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[R][Client] Fix api response, JSON for maps and let httr2 api client handle empty response bodies #18049
Conversation
- from_encoding = NULL is invalid and produces an error, as only strings are allowed, see https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/iconv - defaulting to an empty string fixes this issue
@@ -330,7 +330,7 @@ | |||
{{/isArray}} | |||
{{#isMap}} | |||
{{#isPrimitiveType}} | |||
{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}"{{/isBoolean}}%s{{^isBoolean}}"{{/isBoolean}}{{/isNumeric}} | |||
{{#isNumeric}}%d{{/isNumeric}}{{^isNumeric}}{{^isBoolean}}{{/isBoolean}}%s{{^isBoolean}}{{/isBoolean}}{{/isNumeric}} |
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.
thanks for the PR. for this change, can we add a test model in the test spec to ensure it's tested moving forward?
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.
Please clarify what you need, or link a PR that did something similar. I would be glad to contribute some testing!
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.
please update modules/openapi-generator/src/test/resources/3_0/r/petstore.yaml with test schemas (models) to ensure the above change works as expected (and then regenerate the samples)
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 added a minimal map schema that leads to the generation of the toJSONString
behavior I mentioned above. Please see if this is what you wanted.
…ring and regenerated samples
lgtm. lets give it a try |
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)ApiResponse fix:
The current code for
response_to_text
is:But
from_encoding = NULL
is invalid and produces an error, as only strings are allowed, seeiconv
docs https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/iconv. I changed it to an empty string, which works as intended:JSON for maps fix:
Currently maps are generated like
by code following this pattern (actual snippet of my generated code):
which is wrong JSON and produces an error in the classes
toJSONString
function.I simply changed the template to produce
%s
instead of"%s"
for maps, which results in perfect JSON and removes the error. Resulting JSONs look likehttr2 api_client handling empty response bodies:
As it is currently, an empty response body will lead to
in the httr2
api_client.R
. I simply rewrote this to take the value of NULL instead of callingresp %>% resp_body_raw()
when the response body is empty.Mentioning technical staff: @Ramanth @saigiridhar21