RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.68k stars 1.24k forks source link

Confusing whether Swagger Specification Url can be yaml #1960

Open nojaf opened 5 years ago

nojaf commented 5 years ago

When generating C# code in NSwagStudio it is somewhat confusing when downloading an openapi file.

Create local Copy, I get the following exception:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: o. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at NSwagStudio.ViewModels.SwaggerGenerators.SwaggerInputViewModel.<>c__DisplayClass8_0.<<LoadSwaggerUrlAsync>b__0>d.MoveNext() in C:\projects\nswag\src\NSwagStudio\ViewModels\SwaggerGenerators\SwaggerInputViewModel.cs:line 30
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<>c__DisplayClass14_0.<<RunTaskAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<RunTaskAsync>d__12`1.MoveNext()

So it kinda makes sense that I'm seeing this, but the yaml does get downloaded into the Swagger Specification JSON field and is able to generate C# code.

Is yaml now supported or not? //cc @gillesdb

RicoSuter commented 5 years ago

In the url it should be supported...

RicoSuter commented 5 years ago

Sometimes the conversion from YAML to/from JSON is not working correctly... so the YAML support might need some more work.