Skip to content
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

Fix recursion failure when generating examples #431

Merged

Conversation

scottydawg
Copy link
Contributor

This fixes an issue documented in Issue 9546 in the swagger-codegen repo. The ExampleGenerator recurses infinitely when a schema object is self-referencing.

This fixes the issue by indexing the processed models by their schema reference, and returning existing examples when they already exist.

return schema.getExample();
}
processedModels.add(name);
processedModels.add(schema.get$ref());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These processedModels are passed to resolveSchemaToExample() at line 290.

I changed this from using the name because names are not guaranteed to be unique within an object tree. For example, an id property on the top-level schema could be redundant with an id in a nested object. In the case of a self-referencing or circular structure, names are certain not to be unique.

@HugoMario
Copy link
Contributor

hello @scottydawg, thanks a lot for PR, i reviewed and it does fix the stackoverflow issue, but add another one, usually for petstore sample in aspnet generated code we use to get an example json of the schemas, however with your changes we're getting this output:

exampleJson = "[ null, null ]";

i'll try to work with your chages and improve the class in order to merge the PR, thanks!

@HugoMario HugoMario merged commit bb26cc2 into swagger-api:master Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants