frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
537 stars 132 forks source link

Generate ts files that import dependent classes? #326

Open chrisrrowland opened 4 years ago

chrisrrowland commented 4 years ago

Perhaps I'm just doing something incorrectly, but if I have a cs class like

namespace ReportPortalAPI.Controllers.v1.Model
{
    public class GetReportResponse
    {
        public Guid Id { get; set; }
        public IEnumerable<Collection> Collections { get; set; }
    }
}

Similarly there is a .cs file for Collections. then the generated code is like so

module ReportPortalAPI {

$Properties[public $name: $Type][, ]

    export class GetReportResponse {

        // ID
        public id: string = "00000000-0000-0000-0000-000000000000";

        // COLLECTIONS
        public collections: Collection[] = [];
    }

}

The Collections.ts is generated but not imported. Is it wrong to think it should be? Is there a way to configure this?

AdaskoTheBeAsT commented 4 years ago

you can check my solution if it will help https://github.com/AdaskoTheBeAsT/netcoretypewriterrecipes/blob/master/Angular/AutogeneratedModels.tst

chrisrrowland commented 4 years ago

you can check my solution if it will help https://github.com/AdaskoTheBeAsT/netcoretypewriterrecipes/blob/master/Angular/AutogeneratedModels.tst

Thanks, I'm trying to tweak that to work with the minor modifications I had. It is generating .ts files but it's not importing anything.

I had tried removing the bits for IncludeClass/IncludeEnums since my model classes didn't end with Model, but even when I renamed one to end with Model and retained those it still didn't produce any import statements.

Any thoughts?

chrisrrowland commented 4 years ago

I believe I wasn't actually triggering the correct code to run. When I changed that, it is giving me the error

10:40:35.168 ERROR: Error rendering template. Cannot get identifier 'GenerateTypeInit'. Source path: CollectionModel.cs System.ArgumentOutOfRangeException: Length cannot be less than zero.

That class just looks like

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ReportPortalAPI.Controllers.v1.Model
{
    public class CollectionModel
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string CreatedByUniqname { get; set; }
    }
}
AdaskoTheBeAsT commented 4 years ago

hi I will try to dig into this on the weekend and I will get back to you

AdaskoTheBeAsT commented 4 years ago

hi - sorry for long delay in method GenerateTypeInit replace var pos = c.FullName.IndexOf(".Models"); with var pos = c.FullName.IndexOf(".Model");

on last line please add finishing }

you can start from here