Monday, February 20, 2017

Exclude properties in your Swagger OpenAPI metadata

.NET (core) has OpenAPI support through Swashbuckle, a NuGet package that generates OpenAPI metadata based on your API controllers.

I was asked to manipulate the Swagger metadata to exclude a specific property from the document metadata.

I found 2 possible solutions to achieve this goal:

Option 1 – Add a JsonIgnore attribute on your object:

Option 2 – Create a SchemaFilter:

Don’t forget to register the filter in your Swagger configuration:

No comments: