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

Actions that capture route values with nested type throw an error when you click to view their documentation details #2380

Closed
jonsagara opened this issue Mar 22, 2022 · 7 comments
Milestone

Comments

@jonsagara
Copy link

After I upgraded from 6.2.3 to 6.3.0, I noticed that clicking on an action to view its documentation details had started throwing errors. It appears to be related to my using properties in nested classes to capture route values. I never saw these errors in 6.2.3.

For example, this does not throw an error:

[HttpGet("GetNonNested/{id}")]
public async Task<IActionResult> GetNonNested(int id)
{
    await Task.CompletedTask;

    return Ok(new { message = "this is a non-nested class test" });
}

However, this does:

[HttpGet("GetNested/{id}")]
public async Task<IActionResult> GetNested(NestedActionModel.Query query)
{
    await Task.CompletedTask;

    return Ok(new { message = "this is a nested class test" });
}

NestedActionModel is defined as:

/// <summary>
/// XML documentation for top-level NestedActionModel class.
/// </summary>
public class NestedActionModel
{
    /// <summary>
    /// XML documentation for nested NestedActionModel.Query class.
    /// </summary>
    public class Query
    {
        /// <summary>
        /// Id property used in the getter.
        /// </summary>
        public int Id { get; set; }
    }
}

I have created a reproduction with detailed steps in this repository:

https://github.com/jonsagara/SwashbuckleAspNetCoreRepro

Thank you,

Jon

@jonsagara
Copy link
Author

Verified that the issue still exists in 6.5.0.

Is there anything I can do to help?

@domaindrivendev
Copy link
Owner

I'm unable to repro on 6.5.0. Could you plase create a simple project (ideally starting from scratch) that repro's and post to github where I can pull it down and troubleshoot?

@domaindrivendev domaindrivendev added the responded Responded with solution or request for more info label Jan 11, 2023
@jonsagara
Copy link
Author

@horseyhorsey
Copy link

After I upgraded from 6.2.3 to 6.3.0, I noticed that clicking on an action to view its documentation details had started throwing errors. It appears to be related to my using properties in nested classes to capture route values. I never saw these errors in 6.2.3.

This also fails in 6.2.3. I've come across this issue wanting to add to existing codebase that uses nested CQRS for api.

@horseyhorsey
Copy link

horseyhorsey commented Feb 23, 2023

Here you go: https://github.com/jonsagara/SwashbuckleAspNetCoreRepro

I can see now by looking at your repo that I have a different issue with nested where it won't generate at all.

"errors":"Failed to generate Operation for action - API.Controllers.MyController.Create (API). See inner exception"

Not sure how to get to this Inner Exception, haven't been able to spot that anywhere but swagger.json response.

I must say when I came across this, it's different to how I would do CQRS usually, from a single class model and not using a Query or Command as a parameter, it does make the actions cleaner though.

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Apr 26, 2024
@martincostello martincostello added help-wanted A change up for grabs for contributions from the community and removed responded Responded with solution or request for more info stale Stale issues or pull requests labels Apr 26, 2024
@jonsagara
Copy link
Author

The newly updated README documents a workaround for nested types:

#2703

Replace the + nested type separator with .:

builder.Services.AddSwaggerGen(c =>
{
    c.CustomSchemaIds(type => type.FullName.Replace("+", "."));
});

I tested this in my reproduction project, and it worked, so I will mark this as closed.

@martincostello martincostello removed the help-wanted A change up for grabs for contributions from the community label May 14, 2024
@martincostello martincostello added this to the v6.6.0 milestone May 14, 2024
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

No branches or pull requests

4 participants