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 StackOverflowException in DescriptionOperationFilter if a type ha… #59

Closed
wants to merge 1 commit into from

Conversation

DerAtro
Copy link

@DerAtro DerAtro commented Oct 13, 2021

The DescriptionOperationFilter could cause a StackOverflowException due to circular calls of the recursive UpdateDescriptions() method. This happens if the used type for an operation parameter or response (in SwaggerResponseAttribute) has a property with its own type defined (see 'SelfReferencingTypeObject' in commit) and this property has a DescriptionAttribute defined - the value descriptions of the very same Schema would be updated again and again until the StackOverflowException is thrown.
A check has been added in UpdateDescription() if the Schema of the current type has already been updated with the descriptions, avoiding multiple/infinite updates.
I've also added a new type 'SelfReferencingTypeObjectResponse' holding the 'SelfReferencingTypeObject' and a controller method to illustrate/verify the issue.

…s a property referencing itself directly or indirectly and that property has a DescriptionAttribute defined. Added new type 'SelfReferencingTypeObjectResponse' with corresponding controller to illustrate the issue.
@mattfrear
Copy link
Owner

mattfrear commented Mar 4, 2022

Hi, sorry for the delay. This PR flew under my radar and I haven't done anything with this repo for a long time.
Most of it got ported to the .NET Core version at Swashbuckle.AspNetCore.Filters, and I deprecated the DescriptionOperationFilter from the .NET Core version, I can't remember why, probably because the same thing can be accomplished with XML comments.

I'll have a look at this some time soon.

@mattfrear
Copy link
Owner

When I wrote the DescriptionOperationFilter in 2017, I didn't know that Swashbuckle itself has a way to add Descriptions - by using XML comments. It's poorly documented here: https://github.com/domaindrivendev/Swashbuckle.WebApi#including-xml-comments

I just tested it, and it works like this:

        /// <summary>
        /// Their age, in years
        /// </summary>
        public int Age { get; set; }

        [Description("The first name of the person")] // this uses my filter
        public string FirstName { get; set; }

results in:
image

This is why I deprecated the DescriptionOperationFilter from my Swashbuckle.AspNetCore.Filters package, as it isn't needed.
My preference would be to do the same to the DescriptionOperationFilter here.

My question for you is: can you use XML comments to annotate your properties? Is there a good reason to keep my DescriptionOperationFilter?

@mattfrear
Copy link
Owner

I have removed the DescriptionOperationFilter from Swashbuckle.Examples 4.0.0.

@mattfrear mattfrear closed this Jul 13, 2022
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.

None yet

2 participants