GithubHelp home page GithubHelp logo

mtt's People

Contributors

bluebasher avatar codyschrank avatar dammejed avatar devel0 avatar elestedt avatar geirsagberg avatar itielbeeri avatar jj05y avatar kolyamba-mamba avatar rcheung9 avatar stewartgordonsitka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mtt's Issues

Ignores collection properties with initializers

Given the classes:

public class ItemModel {
  public string Title { get; set; }
}

public class MyListModel {
  public string Title { get; set; }
  public ICollection<ItemModel> Items { get; set; } = new List<ItemModel();
}

The generated file for MyListModel is:

export interface MyListModel {
  title: string;
}

If I remove the collection initializer, i.e.:

public class MyListModel {
  public string Title { get; set; }
  public ICollection<ItemModel> Items { get; set; }
}

Then it generates correctly:

import { ItemModel } from "./itemModel"

export interface MyListModel {
  title: string;
  items: ItemModel[];
}

Also, I noticed IList-properties are generated as any instead of arrays.

Collection properties marked virtual gets incorrectly translated.

public class Model {
  public virtual ICollection<OtherModel> OtherModels { get; set; }
}

gets turned into

export interface Model {
    iCollection<OtherModel>: any;
}

Which is plainly wrong, remove the virtual keyword and it will work. It also works for properties that are not generic types.

The Virtual keyword is required for the lazy-loading routines in EF Core 2.1 - but I don't see any reason for virtual properties to not be handled properly in this case.

Override type generation

When sending data from a backend service to the client the data is in many cases converted to JSON. Complex data types such as DateTime is serialized into strings.

Therefor it would be a much needed feature to be able to override the output type in the generator, so that in this example the DateTime becomes strings. Otherwise the TS interfaces would need a concrete class implementation to be useful (someone that creates a new Date() from the JSON).

One way to solve this, and this is indeed how we solves it now in my project, is to simple let the date times be strings on the C# end as well and then we parse them manually. But this could be done all by magic by the JSON serializer.

Suggestion:
Imlement a overide feature that take From>To type by config that is valid for all types in folder.
Or a To type in a data annotation.

Option to generate 'barrel' file

Would generate ConvertDirectory/index.ts to re-export all generated classes as a barrel:

export * from './Resources/Parts/Unit/units';
export * from './Resources/Parts/part';
export * from './Resources/Vehicles/vehicle';
export * from './Resources/Vehicles/vehicleState';
export * from './Resources/entity';

I've got a basic implementation of this working, just need to add the task option & tests.

Const enums not assignable

'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query.

Nullable properties are lost

Source classes:

public class CommentDto
{
    public long Id { get; set; }
    public UserSimpleDto? Author { get; set; }
    public DateTime DateTime { get; set; }
    public DateTime? LastEdit { get; set; }
    public ushort EditCount { get; set; }
    public bool Owned { get; set; }
    public string Body { get; set; }
    public EDeletedBy? DeletedBy { get; set; }
}
public class UserSimpleDto
{
    public string UserName { get; set; }
    public string Avatar { get; set; }
    public string Title { get; set; }
    public IEnumerable<RoleDto> Roles { get; set; }
}
public class RoleDto
{
    public long Id { get; set; }
    public string Name { get; set; }
    public string? Color { get; set; }
    public bool IsStaff { get; set; }
    public int Order { get; set; }
}

Generated classes:

export interface CommentDto {
    id: number;
    author?: any;
    dateTime: Date;
    lastEdit?: Date;
    editCount: number;
    owned: boolean;
    body: string;
    deletedBy?: any;
}
import { RoleDto } from "./roleDto";

export interface UserSimpleDTO {
    userName: string;
    avatar: string;
    title: string;
    roles: RoleDto[];
}
export interface RoleDto {
    id: number;
    name: string;
    color?: string;
    isStaff: boolean;
    order: number;
}

While the userSimpleDTO references RoleDto properly, CommentDto does not reference UserSimpleDTO, instead opting for any.

AutoGenerated tag doesn't use the correct newline for the environment

When writing the /* AutoGenerated */ comment at the beginning of the TS file, a linefeed (alone) is hardcoded.

This is the wrong newline character(s) for a windows environment.
The rest of the file uses the correct newline characters because WriteLine implicitly uses the correct character.

I wouldn't mind, except that the projects in our environment are checking in the generated files, and all newline characters are automatically transformed to the correct format for the environment at checkin/checkout. It means that every time I build, there's a single difference in the newline character on the first line (CRLF -> LF) that uselessly marks these files as modified.

Dictionary not generated correctly

I have a property like so

public UserSettingsVM Settings { get; set; }
public Dictionary<string, bool> Permissions { get; set; }

But it generates this

settings: UserSettingsVM;
bool>: any;

Nullable types with ?

If I have a property such as public bool? IsCurrent { get; set; }, it gets converted to isCurrent?: boolean;

It should be isCurrent: boolean | null;

Support Multiple source DTO's In One File

Currently the engine treats each source file as either 1 class or 1 enum.

Ideally the engine would be able to discern between two or more classes in one source .cs file and subsequently generate typescript models for each.

Error when Trying to Convert DTOs

Hi

I receive the following error:

The "ConvertMain" task failed unexpectedly.
System.ArgumentException: For parsing, C# DTO's must use curly braces on the next line
in AllocationRuleDTO.cs
"        public string Routenumber { get; set; }"

my DTO:

    public abstract class AllocationRuleBaseDTO : VersionedElementBaseDTO
    {
        public int FkProductgenerickey { get; set; }
        public string Dep { get; set; }
        public string Flightnumber { get; set; }
        public string Routenumber { get; set; }
        public int? FkDepregiongenerickey { get; set; }
        public string Dest { get; set; }
        public int? FkDestregiongenerickey { get; set; }
        public TimeSpan? Starttime { get; set; }
        public TimeSpan? Endtime { get; set; }
        public TimeSpan? DurationStarttime { get; set; }
        public TimeSpan? DurationEndtime { get; set; }
        public List<int> FkAircraftregistrations { get; set; }
        public List<int> FkAircraftTypes { get; set; }
        public string Carrier { get; set; }
        public string Owner { get; set; }
        public DateTime? SpecialStartdate { get; set; }
        public DateTime? SpecialEnddate { get; set; }
        public bool? IsReturnRule { get; set; }
    }

Is the problem related to TimeSpan?

IDictionary to plainobject

We need to be able to express the JSON plain object in our C# interfaces.

Either by IDictionary<T1, T2> or KeyValuePair<T1, T2>
Or actually any Map:isch type would do. Preferably Dictionary.

Expected out:
{[key:T1]: T2}

Example:
public KeyValuePair<string, string> Entities { get; set; }; >> {[key:string]: string}
public IDictionary<string, IEntity[]> Entities { get; set; }; >> {[key:string]: IEntity[]}

The "ConvertMain" task failed unexpectedly

I have around 15 convert tasks in my project, like below.

 <Target Name="ConvertHubMessages" BeforeTargets="PrepareForBuild">
    <Message Text="Generating model :  HubMessages" Importance="high" />
    <ConvertMain WorkingDirectory="SignalRHubs/HubMessages/" ConvertDirectory="clientApp/server-models/hubMessages/" />
  </Target>
  <Target Name="ConvertEnums" BeforeTargets="PrepareForBuild">
    <Message Text="Generating model :  Enums" Importance="high" />
    <ConvertMain WorkingDirectory="../../src/SomeProject.BackOffice.Common/Enums/" ConvertDirectory="clientApp/server-models/enums/" />
  </Target>
  <Target Name="ConvertAccount" BeforeTargets="PrepareForBuild">
    <Message Text="Generating model :  Account" Importance="high" />
    <ConvertMain WorkingDirectory="Controllers/Api/Account/Models/" ConvertDirectory="clientApp/server-models/account/" />
  </Target>

When i build from scratch (no models generated) it works ok, but the second and other times the ConvertMain task crashes with the error:

  Error	MSB4018	The "ConvertMain" task failed unexpectedly.
System.UnauthorizedAccessException: Access to the path 'C:\projects\SomeProject\BackOffice\src\SomeProject.BackOffice.Web\clientApp\server-models\hubMessages' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.GetDirectories(String path)
   at MTT.ConvertService.DeleteDirectory(String path, Int32 iteration)
   at MTT.ConvertService.GetConvertDirectory()
   at MTT.ConvertService.Execute()
   at MSBuildTasks.ConvertMain.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	SomeProject.BackOffice.Web	C:\projects\SomeProject\BackOffice\src\Project.BackOffice.Web\SomeProject.BackOffice.Web.csproj	131	

It is not always the first one, more or less a random convert task. Is this related to the multiple tasks setup? Is there a way to prevent this?

Add Option For Single Quotes

Add an option to change the output to use single quotes in import statements.

Without:
import { WeatherDto } from "./weatherDto";

With:
import { WeatherDto } from './weatherDto';

Base classes and interfaces transform into invalid import statements

Using MTT 0.4.7.

Transforming a class that inherits from an interface:

public class UserProfileViewModel : IIndividual

Results in an interface like the following:

/* Auto Generated */

import { IIndividual } from ""

export interface UserProfileViewModel extends IIndividual {
...
}

It would be great if there were options to specify how to handle these. For instance, in the example I gave, I don't care to emit the interface in the TypeScript definition.

I haven't dug into the code you're using to load the C# yet, but if you're only loading the C# files in the WorkingDirectory, you may never encounter these objects anyways.

If you're open to it, I think reflection could be used on the output binary to find attributed models. Then, those attributes could be used to configure how the model is transformed. Project references would likely need to be resolved, but I think that could be retrieved from msbuild. What do you think?

P.S. I still think it's crazy that after all this time, you're the only one I've found who cares to support .NET Core\Standard in the build rather than through a VS Extension. Thanks for your hard work.

Support Multiline constructors

Currently MTT only supports (more correctly ignores) single line constructors.
public MyClass(string param, string param, string param, string param)

And either fails to run, or generates incorrect artifacts if the constructor is spread over several lines like this:
public MyClass(
string param,
string param,
string param,
string param)

Support for multiline constructors would be great.

Support for records

The generated ts for following dto definition
public record UserDto(string Name, string Surname, string Id);
is
export interface UserDto { }

Support for the record type would be much appreciated because in my opinion, the new record type in C# 9 is perfect for DTOs

Support dto bundles

It would be very nice if you could add support for saving the interfaces in a dtos.ts file, so we do not have to export every single file from our module. So something like bundle=true, would make all the C# classes in dir: workDir/Folder1/dtoClass1.cs into
ConvertDir/Folder1/Folder1DTOs.ts or ConvertDir/Folder1DTOs.ts, where Folder1DTOs.ts contains all of the interfaces for the C# classes under Folder1.

then in index.ts I can just do export * from "ConvertDir/Folder1/Folder1DTOs.ts";

I hope it makes sense :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.