See https://www.nuget.org/packages/Swashbuckle.AutoRestExtensions/
Install-Package Swashbuckle.AutoRestExtensions
Starting version 5.6.0, version of this package will follow SwachBuckle version
Install Autorest
npm install -g autorest
GlobalConfiguration.Configuration
.EnableSwagger(
c =>
{
c.SingleApiVersion("v1", "Web Api");
c.ApplyAutoRestFilters(
new SwaggerDocsConfigExtensionsConfiguration()
{
ApplyEnumTypeSchemaFilter = true,
ApplyNullableTypeSchemaFilter = true,
ApplyNonNullableAsRequiredSchemaFilter = true
},
null);
c.DescribeAllEnumsAsStrings(true);
})
.EnableSwaggerUi();
This Filter will apply the x-nullable attributes in the generated JSON, x-nullable is handled poorly in V 0.17.3 of Autorest so this is why I recommend using nightly. If you don't want to use nightly build you may end up having your complex property like SomeDto.List<Guid>
generated as SomeDto.List<Guid?>
. See Azure/autorest#1578 for more information about Enumerable being generated with nullable properties.
This looks at the schema for the x-nullable property and if the property is marked as x-nullable = false, it add the property in the required array which will be validation against null when generated back to C#.
- Compile the code with Visual Studio 2017
- Run the following command in VS console
Nuget Pack .\Swashbuckle.AutoRestExtensions\Swashbuckle.AutoRestExtensions.csproj -IncludeReferencedProjects
Feel free to contribute
This work is a fork of @gitfool. See : https://github.com/gitfool/Swashbuckle/tree/autorest-extensions