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

Add "default" property for optional parameters automatically #369

Closed
guangyang opened this issue Jun 1, 2015 · 2 comments
Closed

Add "default" property for optional parameters automatically #369

guangyang opened this issue Jun 1, 2015 · 2 comments
Milestone

Comments

@guangyang
Copy link

Right now I need to use some IOperationFilter to do this like:

public class ParameterDefaultValueFilter : IOperationFilter
{
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
    {
        var parameterDescriptors = apiDescription.ActionDescriptor.GetParameters();
        for (int i = 0; i < parameterDescriptors.Count; i++)
        {
            var pd = parameterDescriptors[i];
            if (pd.IsOptional && !(pd.ParameterBinderAttribute is FromBodyAttribute))
            {
                operation.parameters[i].@default = pd.DefaultValue;
            }
        }
    }
}

According to Swagger 2.0, default value on a parameter is supported as long as it's not from body. Could we add this support to Swashbuckle directly?

@domaindrivendev
Copy link
Owner

Should be resolved in latest release - 5.2.0

@tynor88
Copy link

tynor88 commented Jun 8, 2015

Is there some way you need to activate this? I have tried upgrading to 5.2.0, but my default params doesn't show without using the above code?

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

3 participants