Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add IsRequired, DefaultValue to ApiParameterDescription #7563

Closed
rynowak opened this issue Mar 27, 2018 · 2 comments
Closed

Add IsRequired, DefaultValue to ApiParameterDescription #7563

rynowak opened this issue Mar 27, 2018 · 2 comments
Assignees
Labels
3 - Done bug cost: M Will take from 3 - 5 days to complete PRI: 1 - Required Must be handled in a reasonable time

Comments

@rynowak
Copy link
Member

rynowak commented Mar 27, 2018

This is low hanging fruit that we just missed for whatever reason. This means that Swashbuckle/NSwag and other libraries that produce swagger can't see default values when they apply to query string parameters, and can't tell when a parameter should be documented as 'required'.

This makes a lot more sense for us to add now that we have validation on parameters.

We currently only support default values for route parameters via https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Abstractions/ApiExplorer/ApiParameterDescription.cs

The fix for would look like:

  • Add ApiParameterDescription.IsRequired and ApiParameterDescription.DefaultValue
  • Deprecate ApiParameterRouteInfo.DefaultValue - the new parameter handles more cases
  • Update DefaultApiDescriptionProvider to add new logic to set these

By default most parameters will be optional because that's the truth of MVC.

Now that we support validation of parameter nodes we can actually provide this data. A parameter should be considered required if it:

  • Is [FromBody]
  • Has [BindRequired]
  • Is a required route parameter

We may need to polish that list of conditions a bit, but that's a good start.

@mkArtakMSFT
Copy link
Member

Thanks @rynowak. Do you think this is something we should push for during preview2 timeframe?

@rynowak
Copy link
Member Author

rynowak commented Mar 28, 2018

I don't think this is time critical. It would be nice to have for rc since it rounds out work we did in 2.1.0 but I think that depends on the costing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 - Done bug cost: M Will take from 3 - 5 days to complete PRI: 1 - Required Must be handled in a reasonable time
Projects
None yet
Development

No branches or pull requests

3 participants