RicoSuter / NSwag

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

TypeScript: interfaces with duplicated property types (MSBuild) #1742

Open marco-gallinari opened 5 years ago

marco-gallinari commented 5 years ago

Hi,

i'm using NSwag.MSbuild to generate TypeScript interfaces from C# Core classes, to be consumed in an Angular 6 library.

I'm generating from the following c# classes:

public class Parent
{
     public Child Son { get; set; }
}
public class Child
{
    public string Value { get; set; }
}

using NSwag.MSBuild 11.20.1 I get this TypeScript output:

export interface Parent {
    son?: Son;
}

export interface Child {
    value?: string;
}

export interface Son {
    value?: string;
}

while previously on version 11.17.6 i was getting the proper definition:

export interface Parent {
    son?: Child;
}

export interface Child {
    value?: string;
}

NSwag is running on this configuration:

{
  "runtime": "NetCore20",
  "swaggerGenerator": {
    "typesToSwagger": {
      "output": "core.swagger.json",
      "defaultPropertyNameHandling": "CamelCase",
      "assemblyPaths": [
        "$(OutDir)Assembly.dll"
      ],
      "classNames": [
        "MyNamespace.*"

      ]
    }
  },
  "codeGenerators": {
    "swaggerToTypeScriptClient": {
      "wrapDtoExceptions": false,
      "typeStyle": "Interface",
      "generateDtoTypes": true,
      "input": "core.swagger.json",
      "output": "core.server.ts"
    }
  }
}

Am I missing something in NSwag json?

RicoSuter commented 5 years ago

Strange, can you post the swagger spec?

marco-gallinari commented 5 years ago

Please find below a sample project to reproduce the issue:

SwagTest.zip