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

Default Values in a Body Parameter #397

Closed
allenpsuner opened this issue Jun 15, 2015 · 3 comments
Closed

Default Values in a Body Parameter #397

allenpsuner opened this issue Jun 15, 2015 · 3 comments

Comments

@allenpsuner
Copy link

I have a request that takes a JSON body as a parameter. When I start up the service and pull up the UI, and look at the request, I notice that in the body some default values are imposed on the fields in the JSON body:

screen shot 2015-06-15 at 12 23 24 pm

I want to take advantage of being able to click that UI element and auto-populating the "payload" text field, but those default parameters make me wary of exposing this feature to the users. Is there a way to set those default values for the fields in the JSON payload? Or maybe could I pass in an instance of that class to an attribute of the controller, something like:

[SwaggerDefaultValue(payload, new ExamplePayload)]
public IHttpActionResult ExampleAction(string id, ExamplePayload payload)
{
...
}

Where I set the default value of the parameter by it's name with a value I pass in? I apologize if this issue has been raised already before, but I didn't see anything like it already.

@domaindrivendev
Copy link
Owner

Checkout #283 - it details a solution to this problem via per-schema filters. In summary, you would create a schema filter specific to the type in question, which assigns the "default" property accordingly, and then wire it up as follows:

[SwaggerSchemaFilter(typeof(CustomerPayloadExamples))]
public class CustomerPayload
{
....

@domaindrivendev
Copy link
Owner

The thread in that issue is pretty long - start reading from here onwards: #283 (comment)

@allenpsuner
Copy link
Author

Thanks @domaindrivendev, you're prompt responses are always appreciated.

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

2 participants