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
This throws the following exception starting from nswag v13 (the generation works before v13):
System.ArgumentException: An item with the same key has already been added. Key: SampleProject.UserDefinedStruct
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at NJsonSchema.Generation.JsonSchemaResolver.AddSchema(Type type, Boolean isIntegerEnumeration, JsonSchema schema)
at NJsonSchema.Generation.JsonSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver)
at NSwag.Generation.OpenApiSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver) in /_/src/NSwag.Generation/OpenApiSchemaGenerator.cs:line 38
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](TSchemaType schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](Type type, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.Generate(Type type, JsonSchemaResolver schemaResolver)
at NSwag.Generation.OpenApiSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver) in /_/src/NSwag.Generation/OpenApiSchemaGenerator.cs:line 46
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](TSchemaType schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
at NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation) in /_/src/NSwag.Generation/OpenApiSchemaGenerator.cs:line 90
at NJsonSchema.Generation.JsonSchemaGenerator.LoadPropertyOrField(JsonProperty jsonProperty, ContextualAccessorInfo accessorInfo, Type parentType, JsonSchema parentSchema, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.GenerateProperties(Type type, JsonSchema schema, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver)
at NSwag.Generation.OpenApiSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver) in /_/src/NSwag.Generation/OpenApiSchemaGenerator.cs:line 38
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](TSchemaType schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](ContextualType contextualType, JsonSchemaResolver schemaResolver)
at NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
at NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation) in /_/src/NSwag.Generation/OpenApiSchemaGenerator.cs:line 90
at NSwag.Generation.Processors.OperationResponseProcessorBase.LoadDefaultSuccessResponse(ParameterInfo returnParameter, String successXmlDescription, OperationProcessorContext context) in /_/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs:line 281
at NSwag.Generation.Processors.OperationResponseProcessorBase.ProcessOperationDescriptions(IEnumerable`1 operationDescriptions, ParameterInfo returnParameter, OperationProcessorContext context, String successResponseDescription) in /_/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs:line
224
at NSwag.Generation.Processors.OperationResponseProcessorBase.ProcessResponseTypeAttributes(OperationProcessorContext operationProcessorContext, IEnumerable`1 responseTypeAttributes) in /_/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs:line 51
at NSwag.Generation.WebApi.Processors.OperationResponseProcessor.Process(OperationProcessorContext context) in /_/src/NSwag.Generation.WebApi/Processors/OperationResponseProcessor.cs:line 49
at NSwag.Generation.WebApi.WebApiOpenApiDocumentGenerator.RunOperationProcessors(OpenApiDocument document, Type controllerType, MethodInfo methodInfo, OpenApiOperationDescription operationDescription, List`1 allOperations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver) in
/_/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs:line 243
at NSwag.Generation.WebApi.WebApiOpenApiDocumentGenerator.AddOperationDescriptionsToDocument(OpenApiDocument document, Type controllerType, List`1 operations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver) in /_/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.c
s:line 211
at NSwag.Generation.WebApi.WebApiOpenApiDocumentGenerator.GenerateForController(OpenApiDocument document, Type controllerType, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver) in /_/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs:line 199
at NSwag.Generation.WebApi.WebApiOpenApiDocumentGenerator.GenerateForControllersAsync(IEnumerable`1 controllerTypes) in /_/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs:line 88
at NSwag.Commands.Generation.WebApi.WebApiToSwaggerCommand.RunIsolatedAsync(AssemblyLoader assemblyLoader) in /_/src/NSwag.Commands/Commands/Generation/WebApi/WebApiToOpenApiCommand.cs:line 106
at NSwag.Commands.IsolatedCommandBase`1.IsolatedCommandAssemblyLoader.Run(String commandType, String commandData, String[] assemblyPaths, String[] referencePaths) in /_/src/NSwag.Commands/Commands/IsolatedCommandBase.cs:line 76
at NSwag.Commands.IsolatedCommandBase`1.RunIsolatedAsync(String configurationFile) in /_/src/NSwag.Commands/Commands/IsolatedCommandBase.cs:line 61
at NSwag.Commands.IsolatedSwaggerOutputCommandBase`1.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/IsolatedSwaggerOutputCommandBase.cs:line 51
at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 275
at NSwag.Commands.NSwagDocument.ExecuteAsync() in /_/src/NSwag.Commands/NSwagDocument.cs:line 81
at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 85
at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 32
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61
The relevant code simpilified:
if (!dictionary.ContainsKey(typeof(Nullabe<UserDefinedStruct>)))
{
dictionary.Add(typeof(UserDefinedStruct), schema);
}
The problem is that the ContainsKey argument's type is different than the one actually added in case of nullable structs.
At some point the UserDefinedStruct is already in the Dictionary, but the Nullabe<UserDefinedStruct> type isn't.
The condition notices that the Nullabe<UserDefinedStruct> isn't there, so then it tries to add UserDefinedStruct , which throws an exception, because it's already in the Dictionary.
The text was updated successfully, but these errors were encountered:
Tomius
added a commit
to criteo-forks/NJsonSchema
that referenced
this issue
Sep 8, 2023
See the following C# controller:
On this server code, run client generation with
nswag run
, with the following config:This throws the following exception starting from nswag v13 (the generation works before v13):
The relevant code simpilified:
The problem is that the ContainsKey argument's type is different than the one actually added in case of nullable structs.
At some point the
UserDefinedStruct
is already in the Dictionary, but theNullabe<UserDefinedStruct>
type isn't.The condition notices that the
Nullabe<UserDefinedStruct>
isn't there, so then it tries to addUserDefinedStruct
, which throws an exception, because it's already in the Dictionary.The text was updated successfully, but these errors were encountered: