This issue is copied from https://github.com/dotnet/aspnetcore/issues/41595 as the developers there have suggested the issue is likely with NSwag. I'm just hoping they are correct as I'm not familiar with this tool.
Is there an existing issue for this?
[X] I have searched the existing issues
Describe the bug
The openapi2client client throws an exception when you use the required key on a header object with a boolean value
Expected Behavior
Per the spec:
The Header Object follows the structure of the Parameter Object with the following changes:
name MUST NOT be specified, it is given in the corresponding headers map.
in MUST NOT be specified, it is implicitly in header.
All traits that are affected by the location MUST be applicable to a location of header (for example, style).
And the parameter defines the required key as such:
required
boolean
Determines whether this parameter is mandatory. If the parameter locationis "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false.
If you remove the required key then it should build fine. This indicates it's the required key causing the issue. The error message below seems to be clipping the full path.
Exceptions (if any)
> dotnet build
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
GenerateNSwagCSharp:
dotnet --roll-forward-on-no-candidate-fx 2 /Users/cwelchmi/.nuget/packages/nswag.msbuild/13.0.5/build/../tools/NetCore21//dotnet-nswag.dll openapi2csclient /className:petstoreClie
NSwag command line tool for .NET Core NetCore21, toolchain v13.0.5.0 (NJsonSchema v10.0.22.0 (Newtonsoft.Json v11.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: /Users/cwelchmi/.nuget/packages/nswag.msbuild/13.0.5/tools/NetCore21
Newtonsoft.Json.JsonSerializationException: Error converting value True to type 'System.Collections.Generic.ICollection`1[System.String]'. Path 'paths['/pet'].put.responses.200.head.
---> System.ArgumentException: Could not cast or convert from System.Boolean to System.Collections.Generic.ICollection`1[System.String].
at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, Js)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target)
at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader, Object target)
at NJsonSchema.ExtensionDataDeserializationConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containe)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract c)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, Js)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract c)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containe)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract c)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, Js)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target)
at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader, Object target)
at NJsonSchema.ExtensionDataDeserializationConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
at NSwag.OpenApiPathItem.OpenApiPathItemConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\projects\nswag\src\NSwag.Cor5
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containe)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract c)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, Js)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target)
at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader, Object target)
at NJsonSchema.ExtensionDataDeserializationConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at NJsonSchema.Infrastructure.JsonSchemaSerialization.FromJson[T](String json, IContractResolver contractResolver)
at NJsonSchema.Infrastructure.JsonSchemaSerialization.FromJsonAsync[T](String json, SchemaType schemaType, String documentPath, Func`2 referenceResolverFactory, IContractResolver)
at NSwag.OpenApiDocument.FromJsonAsync(String data, String documentPath, SchemaType expectedSchemaType, Func`2 referenceResolverFactory) in C:\projects\nswag\src\NSwag.Core\OpenA0
at NSwag.OpenApiDocument.FromFileAsync(String filePath) in C:\projects\nswag\src\NSwag.Core\OpenApiDocument.cs:line 211
at NSwag.Commands.OutputCommandBase.ReadSwaggerDocumentAsync(String input) in C:\projects\nswag\src\NSwag.Commands\Commands\OutputCommandBase.cs:line 49
at NSwag.Commands.InputOutputCommandBase.GetInputSwaggerDocument() in C:\projects\nswag\src\NSwag.Commands\Commands\InputOutputCommandBase.cs:line 46
at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.<RunAsync>b__83_0() in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGeneration\OpenApiToCSharpClientCommand.cs:0
at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.RunAsync() in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGeneration\OpenApiToCSharpClientCommand.cs:line 228
at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\CodeGen7
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.Process(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 56
/Users/cwelchmi/.nuget/packages/nswag.apidescription.client/13.0.5/build/NSwag.ApiDescription.Client.targets(28,5): error MSB3073: The command "dotnet --roll-forward-on-no-candidate-f]
Build FAILED.
/Users/cwelchmi/.nuget/packages/nswag.apidescription.client/13.0.5/build/NSwag.ApiDescription.Client.targets(28,5): error MSB3073: The command "dotnet --roll-forward-on-no-candidate-f]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.51
This issue is copied from https://github.com/dotnet/aspnetcore/issues/41595 as the developers there have suggested the issue is likely with NSwag. I'm just hoping they are correct as I'm not familiar with this tool.
Is there an existing issue for this?
Describe the bug
The
openapi2client
client throws an exception when you use therequired
key on a header object with a boolean valueExpected Behavior
Per the spec:
And the parameter defines the
required
key as such:Steps To Reproduce
The repo https://github.com/michaelgwelch/petstore2 demonstrates a header named
CUSTOM
withrequired
set totrue
. If you attempt to build you will get an exception.If you remove the
required
key then it should build fine. This indicates it's therequired
key causing the issue. The error message below seems to be clipping the full path.Exceptions (if any)
.NET Version
6.0.202
Anything else?