Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate ts files that import dependent classes? #326

Open
chrisrrowland opened this issue Jan 24, 2020 · 5 comments
Open

Generate ts files that import dependent classes? #326

chrisrrowland opened this issue Jan 24, 2020 · 5 comments

Comments

@chrisrrowland
Copy link

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
Copy link

@chrisrrowland
Copy link
Author

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
Copy link
Author

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
Copy link

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

@AdaskoTheBeAsT
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants