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

[Bug]: Optional route parameter gets rendered as required #3078

Open
sommmen opened this issue Sep 23, 2024 · 4 comments
Open

[Bug]: Optional route parameter gets rendered as required #3078

sommmen opened this issue Sep 23, 2024 · 4 comments
Labels
bug help-wanted A change up for grabs for contributions from the community

Comments

@sommmen
Copy link

sommmen commented Sep 23, 2024

Describe the bug

The following endpoint:

    [HttpGet("packing-dashboard")]
    [HttpGet("packing-dashboard/{partner?}")]
    public async Task<IActionResult> GetDashboard([FromRoute] string? partner = default, CancellationToken cancellationToken = default)

Makes the partner value required in the UI:

image

Ditto for the document:
image

Expected behavior

The partner variable should be optional.

Actual behavior

Its required.

Steps to reproduce

Paste the sample code above in a controller.

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

Latest (6.8.0)

.NET Version

net8.0

Anything else?

No response

@sommmen sommmen added the bug label Sep 23, 2024
@martincostello
Copy link
Collaborator

Latest

To confirm, is this with 6.8.0?

@sommmen
Copy link
Author

sommmen commented Sep 23, 2024

Latest

To confirm, is this with 6.8.0?

Did not expect the 2hrs ago release - i will recheck if this issue persists on that version.

@sommmen
Copy link
Author

sommmen commented Sep 23, 2024

Latest

To confirm, is this with 6.8.0?

Unfortunately the issue remains with 6.8.0.

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Sep 23, 2024
@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Sep 23, 2024

This seems to be the expected behaviour:

// From the OpenAPI spec:
// If the parameter location is "path", this property is REQUIRED and its value MUST be true.
if (apiParameter.IsFromPath())
{
return true;
}

Last PR against this: #2183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

3 participants