Skip to content

Stackoverflow in toExampleValue() for python client#8054

Merged
spacether merged 1 commit intoOpenAPITools:masterfrom
fbl100:fix_issue_8052
Dec 28, 2020
Merged

Stackoverflow in toExampleValue() for python client#8054
spacether merged 1 commit intoOpenAPITools:masterfrom
fbl100:fix_issue_8052

Conversation

@fbl100
Copy link
Contributor

@fbl100 fbl100 commented Nov 30, 2020

Added a Set to the toExampleValueRecursive() method to detect circular references.
Added a watered down GeoJson API that, prior to this commit, would have thrown a StackOverflowException
Added a unit test (testRecursiveToExample()) and expected output confirming that the fix works.

@spacether this solution may be a little heavy handed. I tried not to introduce another parameter to the toExampleValueRecursive(), but this seemed like the cleanest way to do it.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@spacether
Copy link
Contributor

Hey there. Thanks for your PR. Yup adding a new parameter is the cleanest way to handle it.
Can you please run 'bin/utils/ensure-up-to-date' locally and commit changes? That will fix the CI error.

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.

please regenerate the samples to eliminate the CI error

return fullPrefix + modelName + closeChars;
} else if(modelName != null && !modelName.isEmpty()){
// if the model is non-null and non-empty, add it to the set
processedModels.add(modelName);
Copy link
Contributor

@spacether spacether Dec 1, 2020

Choose a reason for hiding this comment

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

Shouldn't we only add a model when we have finished generating its sample?
What are our recursive base cases here for cycles?
How about naming them seenModels because we have not finished processing it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll go back and take a look at this again, thanks. I didn't realize that the 'ran /bin/utils/ensure-up-to-date' was required and didn't pick up on the fact that my examples had changed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spacether Got a CircleCI build error that I'm having a hard time interpreting. Do you mind taking a look and providing pointers for how to reproduce locally?

Copy link
Contributor

Choose a reason for hiding this comment

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

That error is unrelated. We. can ignore it.

@spacether spacether linked an issue Dec 1, 2020 that may be closed by this pull request
6 tasks
@fbl100 fbl100 marked this pull request as draft December 3, 2020 17:06
@fbl100 fbl100 marked this pull request as ready for review December 11, 2020 19:55
@fbl100
Copy link
Contributor Author

fbl100 commented Dec 11, 2020

@spacether We took another crack at the toExampleValueRecursive() issue.

Copy link
Contributor

@spacether spacether Dec 14, 2020

Choose a reason for hiding this comment

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

null is invalid in Python. Can you update this value? If the list is not explicitly nullable, then the example value should be [] (empty list). If it is nullable, then the example value can be None.

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.

Thank you for making these changes. It is almost there!
Your tests sample includes null which is not valid python code.
Can you update the string null to be the string None?

@fbl100
Copy link
Contributor Author

fbl100 commented Dec 18, 2020

Hi @spacether, We have updated the example value to be None in the recursive case.

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.

Thank you for making that update. So looking at your spec None is not a valid value for geometries because geometries is type array and that array is not Nullable. Sorry for asking for None here earlier. Please change the empty value to be empty list for your output example. The only valid values for geometries as defined in your spec are:

  • []
  • [one or more GeoJsonGeometry]

@spacether
Copy link
Contributor

When /i is passed in can we turn on case insensitive in RgxGen? If you don't want to do this now we can leave it to the future.
The author of that library explained that we can use the CASE_INSENSITIVE option like this code does.

@fbl100
Copy link
Contributor Author

fbl100 commented Dec 24, 2020

We changed the default value for the recursive item to:
None - if it's nullable
[] - if it's an array type
{} - if it's an object type

Added a Set<String> in toExampleValueRecursive() to keep track of which models we have
generated to avoid an infinite recursion for recursive models.  An example of a recursive
model would be a GeoJson GeometryCollection.
@fbl100
Copy link
Contributor Author

fbl100 commented Dec 28, 2020

Hello @spacether, I noticed that this PR had conflicts with the latest master. I went ahead and fixed the conflicts and pushed the latest. Let me know if you need any other changes.

@spacether spacether added this to the 5.0.1 milestone Dec 28, 2020
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.

Not: the Shippable CI error is unrelated
@fbl100 thank you for your PR and for making those updates. This looks great!

@spacether spacether merged commit fd02bc3 into OpenAPITools:master Dec 28, 2020
@spacether
Copy link
Contributor

This PR broke master so I am reverting it. There is a java test failure that we missed

@fbl100
Copy link
Contributor Author

fbl100 commented Dec 29, 2020

@spacether everything passed on my side. Can you point me to the build log that failed? I'll figure it out.

@spacether
Copy link
Contributor

spacether commented Dec 29, 2020

Thank you so much! Here is a log
https://github.com/OpenAPITools/openapi-generator/runs/1622405497?check_suite_focus=true
By eye it looks like it may be an os newline issue.

@wing328 wing328 changed the title Fixes issue 8052: Stackoverflow in toExampleValue() for python client Stackoverflow in toExampleValue() for python client Feb 3, 2021
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.

[BUG] Stackoverflow in toExampleValue()

3 participants