Nullable Enums don't appear as "nullable: true" in swagger.json
See original GitHub issueI am running .NET 6.0 ASP.Net Core Web Api with SwashBuckle.AspNetCore version 6.3.0 (currently last stable)
The swagger.json doesn’t show nullable: true where there is a nullable enum in a dto class
{ "openapi": "3.0.1", "info": { "title": "TestBug", "version": "1.0" }, "paths": { "/api/My": { "get": { "tags": [ "My" ], "responses": { "200": { "description": "Success", "content": { "text/plain": { "schema": { "$ref": "#/components/schemas/MyDTO" } }, "application/json": { "schema": { "$ref": "#/components/schemas/MyDTO" } }, "text/json": { "schema": { "$ref": "#/components/schemas/MyDTO" } } } } } } } }, "components": { "schemas": { "MyDTO": { "type": "object", "properties": { "myEnum": { "$ref": "#/components/schemas/MyEnum" }, "myNullableEnum": { "$ref": "#/components/schemas/MyNullableEnum" }, "myNullableInt": { "type": "integer", "format": "int32", "nullable": true } }, "additionalProperties": false }, "MyEnum": { "enum": [ 0, 1, 2 ], "type": "integer", "format": "int32" }, "MyNullableEnum": { "enum": [ 0, 1, 2 ], "type": "integer", "format": "int32" } } } }
Steps to reproduce:

I am aware of using “UseAllOfToExtendReferenceSchemas”, but it’s not suitable in my case, since it’s breaking other logics.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:13 (2 by maintainers)
Top Related StackOverflow Question
Closing as the solution (i.e. to use
UseAllOfToExtendReferenceSchemas) has already been provided. If that’s breaking client generators then you should create an issue with them instead of SB.You could also try
UseInlineDefinitionsForEnumsas suggested by @anoordoverSolution that worked for me.
Based on: