RicoSuter / NSwag

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

TransformLegacyDocument does not work with variables #4684

Open hermanseder opened 8 months ago

hermanseder commented 8 months ago

If you have a NSwag file which uses variables and requires some legacy transformation, an exception occurs. I think the reason for that is, because if some transformation is necessary, it tries to parse (https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Commands/NSwagDocumentBase.cs#L179) the JSON file without substituting the variables. This is a problem if one substituted property is not of type string. For example, boolean or if you want to make the runtime configurable.

The following example leads to errors:

{
  "runtime": "$(NSwagRuntime)",
  "defaultVariables": null,
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "$(ProjectFilePath)",
      "documentName": "$(Version)",
      "msBuildProjectExtensionsPath": null,
      "configuration": null,
      "runtime": null,
      "targetFramework": null,
      "noBuild": true,
      "msBuildOutputPath": "",
      "verbose": false,
      "workingDirectory": null,
      "aspNetCoreEnvironment": null,
      "output": null,
      "newLineBehavior": "Auto"
    }
  },
 ....