Skip to content

[Ruby] Incorrect return types if multiple responses are defined #7634

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

uyermolkin-hubspot
Copy link

Description

If you define multiple responses, the codegen will only support the first one (typically 200).

openapi-generator version

4.3.1 and higher

OpenAPI declaration file content or url

93476330-56d0d980-f902-11ea-8c1a-32a56a4508c3

Similar Issue for PHP

https://github.com/OpenAPITools/openapi-generator/issues/125

Similar Issue for Python

https://github.com/OpenAPITools/openapi-generator/issues/7426

@uyermolkin-hubspot
Copy link
Author

@spacether could you please check this PR? Thanks!

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for the PR!

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the travis ci errors?
There are failing ruby tests there.

@uyermolkin-hubspot
Copy link
Author

Can you fix the travis ci errors?
There are failing ruby tests there.

I'm confused, because these tests are failed not because of my changes. It fails even on master branch. Can you take a look? @spacether

@spacether
Copy link
Contributor

Ruby Technical Committee:
@cliffano (2017/07) @zlx (2017/09) @autopp (2019/02)
Any insights here?

@atanasiuk-hubspot
Copy link
Contributor

Hi, any updates on this?

return_type = opts[:debug_return_type]

return_types_map = {
200 => 'Array<Pet>',
Copy link
Contributor

@spacether spacether Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map value is incorrect. Can you update it to Array<Pet>?


return_types_map = {
200 => 'Array&lt;Pet&gt;',
400 => '',
Copy link
Contributor

@spacether spacether Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the value be empty string or nil?

new_options = opts.merge(
:operation => :"{{classname}}.{{operationId}}",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
:return_type => return_type,
:return_types_map => return_types_map
Copy link
Contributor

@spacether spacether Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using two parameters to pass in the same data here:

  • return_type
  • return_types_map

Both of these parameters are saying deserialize a response into this class.
How about only passing in return_types_map?

It looks the old code replace the return type with the debug_return_type if it is passed in.
If the user sets a :debug_return_type should we set all values of the map to :debug_return_type?
Also if a different status code is received and debug_return_type is passed in, what type should be used? If we want to use debug_return_type then we should pass it in as the initialization argument to Hash.new so it will be used for missing entries.
One could add this missing feature with:

return_types_map = Hash.new(opts[:debug_return_type])
if opts[:debug_return_type] != nil:
    # add the code to classname value here
# otherwise we keep the hash as-is and all access of it grabs the default value

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR overall it looks good.

  • One mapped value is incorrect and needs a fix.

I have a questions about:

  • using empty string vs nil
  • asking if we can use one parameter to store the data types rather than two for simplicity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Ruby] Incorrect return types if multiple responses are defined
3 participants