You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Bug]: SwaggerGeneratorException (Failed to generate schema for type - System.Nullable`1[{enum_type}]) when using UseAllOfToExtendedReferenceSchemas
#2904
Closed
marcominerva opened this issue
May 16, 2024
· 3 comments
· Fixed by #2895
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate Operation for action - EnumController.Get (NullableEnumIssue). See inner exception
---> Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate schema for type - System.Nullable`1[LogLevel]. See inner exception
---> System.ArgumentException: The specified type LogLevel must derive from the specific value's type System.Int32.
at System.Text.Json.ThrowHelper.ThrowArgumentException_DeserializeWrongType(Type type, Object value)
at System.Text.Json.JsonSerializer.ValidateInputType(Object value, Type inputType)
at System.Text.Json.JsonSerializer.Serialize(Object value, Type inputType, JsonSerializerOptions options)
at Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver.JsonConverterFunc(Object value, Type type)
at Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver.<>c__DisplayClass2_0.<GetDataContractForType>b__4(Object value)
at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchemaForParameter(Type modelType, SchemaRepository schemaRepository, ParameterInfo parameterInfo, ApiParameterRouteInfo routeInfo)
at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type modelType, SchemaRepository schemaRepository, MemberInfo memberInfo, ParameterInfo parameterInfo, ApiParameterRouteInfo routeInfo)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo, ApiParameterRouteInfo routeInfo)
--- End of inner exception stack trace ---
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository, PropertyInfo propertyInfo, ParameterInfo parameterInfo, ApiParameterRouteInfo routeInfo)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateParameter(ApiParameterDescription apiParameter, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<>c__DisplayClass16_0.<GenerateParameters>b__1(ApiParameterDescription apiParam)
at System.Linq.Enumerable.WhereSelectListIterator`2.ToList()
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateParameters(ApiDescription apiDescription, SchemaRepository schemaRespository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
--- End of inner exception stack trace ---
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutFilters(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Swashbuckle.AspNetCore version
6.6.1
.NET Version
8.0.5
Anything else?
No response
The text was updated successfully, but these errors were encountered:
- Fix schema generation of default values for nullable enums with System.Text.Json.
- Resolve some IDE refactoring suggestions.
- Render the response if an integration test fails.
Resolvesdomaindrivendev#2904.
- Fix schema generation of default values for nullable enums with System.Text.Json.
- Resolve some IDE refactoring suggestions.
- Render the response if an integration test fails.
Resolvesdomaindrivendev#2904.
Describe the bug
If I use the
UseAllOfToExtendedReferenceSchemas
extension method:And then I use a nullable enum type:
When I run the application, I get the following exception:
SwaggerGeneratorException: Failed to generate schema for type - System.Nullable
1[LogLevel]`With this inner exception:
ArgumentException: The specified type LogLevel must derive from the specific value's type System.Int32.
Expected behavior
Swashbuckle.AspNetCore should not throw any exception.
Actual behavior
No response
Steps to reproduce
Minimal repro: https://github.com/marcominerva/NullableEnumIssue
Exception(s) (if any)
Swashbuckle.AspNetCore version
6.6.1
.NET Version
8.0.5
Anything else?
No response
The text was updated successfully, but these errors were encountered: