Coder Social home page Coder Social logo

typegen's People

Contributors

allov avatar bcrosnier avatar bergi9 avatar cs-net avatar dersia avatar elwynelwyn avatar jburzynski avatar michaelhthomas avatar mispencer avatar newdark90 avatar onliner10 avatar rametta avatar sdamian avatar sidney-pauly avatar stephtr avatar vsvirydau-cl 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  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  avatar  avatar

typegen's Issues

Add support for overwritten names from JSON.NET

We're using TypeGen to generate TypeScript models for an ASP.NET Core API, consumed by an Angular app. One of the models we have are sourced from an external API which returns JSON in a different format than we prefer, so I use JsonProperty from JSON.NET to customize the names. This is not detected by TypeGen, so I get a model with the wrong names.

Example:

public class ApplicableMeasureRow
{
    public int Id { get; private set; }
    [JsonProperty("goods_NOM_ITEM_ID")]
    public string GoodsNomenclatureItemId { get; private set; }
}

generates the TypeScript:

export class ApplicableMeasureRow {
  public id: number = undefined;
  public goodsNomenclatureItemId: string = undefined;
}

but the API serializes and sends it as goods_NOM_ITEM_ID, so my TypeScript code doesn't work.

I know it's possible to remap the properties in TypeGen, but that requires duplicate attributes, and since JSON.NET is so common, it would be nice if TypeGen could find that attribute and handle it automatically.

customTypeMappings side effects

I want to set string types to default to a union type of string | null.

"customTypeMappings": {
    "System.DateTime": "string | null",
    "System.String":  "string | null" 
  }

This has the expected result for string types but not for string arrays:

export interface SecurityRole {
  roleId: string;
  name: string | null;
  description: string | null;
  permissions: string | null[];
}

export default interface

Hi.

Is it possible to configure TypeGen to export a generated typescript interface as default?

Like this:

interface Address {
    AddressId: number;
    VisitingAddress: string;
    ZipCode: string;
    City: string;
    Country: string;
    Phone: string;
    Email: string;
}
export default Address;

or like this:

export default interface Address {
    AddressId: number;
    VisitingAddress: string;
    ZipCode: string;
    City: string;
    Country: string;
    Phone: string;
    Email: string;
}

(I actually prefer the first one because my VS highlights the keywords incorrectly in the second example)

How to add custom static property to class?

Is there a way to add some static properties to the typescript class, like assembly info.
Like this:

export class OrgViewModel {
    /** Id */
    id? : string;
    /** Path */
    path? : string;

    static readonly _className = "Admin.ViewModels.OrgViewModel";
    static readonly _assemblyName = "Admin.ViewModels";
}

Avoid [ExportTsInterface] attributes with tgconfig.json scanning (feature request)

Hi,

This is a feature request.

It would be nice to avoid having to add [ExportTsInterface] (or [ExportTsClass]) attributes on C# models. Ideally if there would be a way to provide a regex/namespace scanning expression for TypeGen to know what C# models to generate from.

The recently added customTypeMappings in tgconfig.json (#36) brings us even closer to avoid attributes is most cases.

What do you think?

GENERIC ERROR: Value cannot be null.

I can't get this to work. Im using VS 2017 and TypeGen 1.6.1 on .NET v461

Here is the PM output I get.

`PM> TypeGen TypeGenDemo

Generating files for project "TypeGenDemo"...

GENERIC ERROR: Value cannot be null.

Parameter name: path2

at System.IO.Path.Combine(String path1, String path2)

at TypeGen.Cli.Program.Generate(String projectFolder, String configPath, Boolean verbose)

at TypeGen.Cli.Program.Main(String[] args)

PM>`

StackOverflowException

I have TypeGen 2.1.1 package installed and am using version 2.1.1 of the CLI.

I created the GenerationSpec below and added it to the root of my project.

    public class MyGenerationSpec : GenerationSpec
    {
        public MyGenerationSpec()
        {
            AddEnum<FarmDTOs.Loss.Causes>();
        }
    }

FarmDTOs.Loss.Causes is an enum inside of a class which resides in a Nuget package:

namespace FarmDTOs
{
    public class Loss
    {
        public string Id;
        public DateTime Date;
        public Causes Cause;
        public int Amount;

        public Loss();

        public enum Causes
        {
            Unspecified = 0,
            Earthquake = 1,
            Fire = 2,
        }
    }
}

When I run dotnet typegen generate I get the following messages:

Generating files for project "."...
Process is terminating due to StackOverflowException.

Any ideas as to what would be causing this?

Export as ".d.ts" declaration files instead of modules

Hey there, thank you very much for this nice tool. I'm currently playing with it to see if it fits our needs.

One thing we would like to do is to export all our C# classes as namespaced TS declaration files (.d.ts files), so we don't have to explicitly import them everywhere. I didn't see an option to do this so I was wondering if this is something you have considered yet?

Thanks again.

Self-referencing class creates duplicate identifier

public class MyClass {
    public MyClass MyMember { get; set; }
}

generates typescript file my-class.ts:

import { MyClass } from "./my-class";
export class MyClass {
    myMember: MyClass;
}

which gives typescript error [ts] Import declaration conflicts with local declaration of 'MyClass'. It's easy enough to delete the self-referential import, but it will get recreated the next time TypeGen is run.

(This is in TypeGen v1.5.5)

System.Guid & GENERIC ERROR: Object reference not set to an instance of an object.

After trying to apply some new model changes today, TypeGen was giving me the following errors. I'm not sure how to trace it down. Possibly related is that it still has a problem with System.Guid (first stack), but even after I overrode all those to TsType.String, TypeGen gave the second error.

(I know this is not much to go on, but I'm at wit's end. If you want me to look for particular things in our update to debug this, I'll certainly oblige.)

APPLICATION ERROR: Generated type must be either a C# class or enum. Error when generating type System.Guid
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateType(Type type)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateType(Type type)
   at TypeGen.Core.Generator.Generate(Type type)
   at TypeGen.Core.Generator.Generate(Assembly assembly)
   at TypeGen.Cli.Program.<>c__DisplayClass10_0.<Generate>b__0(IEnumerable`1 acc, Assembly assembly)
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at TypeGen.Cli.Program.Generate(String projectFolder, String configPath, Boolean verbose)
   at TypeGen.Cli.Program.Main(String[] args)
GENERIC ERROR: Object reference not set to an instance of an object.
   at TypeGen.Core.Extensions.TypeExtensions.<>c__DisplayClass0_0.<GetInterface>b__0(Type i)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at TypeGen.Core.Extensions.TypeExtensions.GetInterface(Type type, String name)
   at TypeGen.Core.Business.TypeService.IsDictionaryType(Type type)
   at TypeGen.Core.Business.TypeService.IsCollectionType(Type type)
   at TypeGen.Core.Business.TypeService.GetFlatType(Type type)
   at TypeGen.Core.Business.TypeDependencyService.GetMemberTypeDependencies(Type type)
   at TypeGen.Core.Business.TypeDependencyService.GetTypeDependencies(Type type)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateNotMarked(Type type, String outputDirectory)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateType(Type type)
   at TypeGen.Core.Generator.GenerateTypeDependencies(Type type, String outputDir)
   at TypeGen.Core.Generator.GenerateClass(Type type, ExportTsClassAttribute classAttribute)
   at TypeGen.Core.Generator.GenerateType(Type type)
   at TypeGen.Core.Generator.Generate(Type type)
   at TypeGen.Core.Generator.Generate(Assembly assembly)
   at TypeGen.Cli.Program.<>c__DisplayClass10_0.<Generate>b__0(IEnumerable`1 acc, Assembly assembly)
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at TypeGen.Cli.Program.Generate(String projectFolder, String configPath, Boolean verbose)
   at TypeGen.Cli.Program.Main(String[] args)

enum : short crashes

public enum MyEnum: short{
            ValA= 1,
            ValB = 2,
}

It will crash in Generator.cs, in GetEnumValueText(object enumValue, Type type) on line var enumValueInt = (int)enumValue; because that is invalid cast (note that enumValueInt= (int)(short)enumValue would work).
Could this be fixed, and is there some way to disable enum generation in the meantime? I would be fine with numbers instead of all enums.

Specifying generated enum value types

In my project we use enums serialized as strings. It would be great if it was possible to specify string value generation, to support the following generated TypeScript:

export enum EnumExample {
    ExampleValue1 = "ExampleValue1",
    ExampleValue2 = "ExampleValue2"
}

Such a feature should probably include the possibility to support different casings between name and value.

I didn't find anything in GeneratorOptions which hints to this.

Thanks for a neat piece of software!

Generate sources as post-build event

Hello,

Thanks for this project. I recently started to use it, so far works great!

I have a question, is it possible to somehow configure the TS source generation to run after specific project is build?

So essentially what I would want is to have all my ts files generated when my WebAPI (ASP.NET Core 2.1) project is built. Ideally this should work when building the project on local VS as well in CI (dotnet build ...). I tried the CLI tool, but it said Error Package 'TypeGen.DotNetCli 2.0.0' has a package type 'DotnetTool' that is not supported by project 'xxx.xxx.WebAPI'.

[Feature Request] Provide a way to change the boilerplate text

It would be nice if there was a way to modify the boilerplate text that goes at the top of the generated TypeScript files. Either from the GenerationSpec or the dotnet typegen generate command.

My use case is that I want to provide a version number to all of my TypeScript files.

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 * **FooDTOs version 3**
 */

Great project by the way. Extremely useful.

Property default values missing in output

TypeGen v2.2.1.
Using GenerationSpec + I don't want to use annotations.

The following class:

class Test
    {
        public string myFieldString = "Hello";
        public string myPropertyString { get; set; } = "World!";
    }

is converted to typescript but it lacks the default value 'World!' for the property myPropertyString. Default property values are available since C# 6.0.

export class Test {
    myFieldString: string = "Hello";
    myPropertyString: string;
}

Please advise!

ExportTsInterface from C# interface

How do I generate a TypeScript interface from a C# interface? When I use the [ExportTsInterface] attribute on a public interface, I get a build-time error: "Attribute 'ExportTsInterface' is not valid on this declaration type. It is only valid on 'class' declarations.".

[Question] How to handle duplicate C# names?

I have C# DTOs that contains something like the following:

namespace MyDTOs.ParentClass
{
    public class ClassFoo
    {
		public MyEnums EnumValue;
		
		public enum MyEnums
		{
			Aaa = 1,
			Bbb = 2,
			Ccc = 3
		}
	}
}

and

namespace MyDTOs.ParentClass
{
    public class ClassBar
    {
		public MyEnums EnumValue;
		
		public enum MyEnums
		{
			Xxx = 1,
			Yyy = 2,
			Zzz = 3
		}
	}
}

I'm using a generation spec that looks like the following:

public class MyGenerationSpec : GenerationSpec
{
	public MyGenerationSpec()
	{
		AddClass<MyDTOs.ParentClass>();
	}
}

Everything works great; however, the issue is that one file gets created for MyEnums. I need a TypeScript file created for each of MyEnums as they contain different values. Is there a way to configure TypeGen to rename certain classes/enums or a proper way to handle duplicate C# class/enum names?

ForAssembly not available in version 2.2.1 in generation specs

The ForAssembly() method has been removed from generation specs in version 2.2.1. Instead, TypeGen now exposes the GetLoadableTypes() extension method which allows to write the following instead:

// generate everything from an assembly

foreach (Type type in GetType().Assembly.GetLoadableTypes())
{
    AddClass(type);
}

// generate types by namespace

IEnumerable<Type> types = GetType().Assembly.GetLoadableTypes()
    .Where(x => x.FullName.StartsWith("MyProject.Web.Dtos"));
foreach (Type type in types)
{
    AddClass(type);
}

Tab indentation in generated files

Is it possible for the generated files to have tab indentation instead of space indentation? I read about the "tabLength" configuration option in the documentation, but I could not find anything about switching indentation modes.

Using a generic field gives error Generic Error Type.ContainsGenericParameters is true

TypeGen v2.2.1.
Using GenerationSpec because I don't want to use annotations.

The following generic class, with a generic property works.

   class Test<T>
    {
        public T somename { get; set; }
    }

It is generated as:

export class Test<T> {
    somename: T;
}

However, as soon as i change the property to a field, like this, i get an error:

   class Test<T>
    {
        public T somename;
    }

The error says:

GENERIC error : Cannot create an instance of SampleProject.Test`1[T] because Type.ContainsGenericParameters is true.

Stack trace:

at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at TypeGen.Core.Generator.GetFieldValueText(FieldInfo fieldInfo) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 450
at TypeGen.Core.Generator.GetClassPropertyText(MemberInfo memberInfo) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 511
at TypeGen.Core.Generator.b__43_0(String current, MemberInfo memberInfo) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 551
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func)
at TypeGen.Core.Generator.GetClassPropertiesText(Type type) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 550
at TypeGen.Core.Generator.GenerateClassOrInterface(Type type, ExportTsClassAttribute classAttribute, ExportTsInterfaceAttribute interfaceAttribute) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 390
at TypeGen.Core.Generator.Generate(Type type, Boolean initializeGeneration) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 257
at TypeGen.Core.Generator.b__24_0(IEnumerable1 acc, KeyValuePair2 kvp) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 161
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func)
at TypeGen.Core.Generator.Generate(GenerationSpec generationSpec) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Core\Generator.cs:line 160
at TypeGen.Cli.Program.<>c__DisplayClass9_0.b__4(IEnumerable1 acc, GenerationSpec spec) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 147 at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func`3 func)
at TypeGen.Cli.Program.Generate(String projectFolder, String configPath) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 143
at TypeGen.Cli.Program.Main(String[] args) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 75

Attempts to install CLI tooling on mac are failing!

Hi!

Not sure if this is user error or a limitation of the CLI package, but I'll ask anyway!

I'm struggling to install the CLI tooling in my mac .net core 2.1 (v2.1.401) development environment.

I ran the following command...
dotnet tool install -g TypeGen.DotNetCli

And was presented with the following output..

error NU1212: Invalid project-package combination for TypeGen.DotNetCli 1.6.7. DotnetToolReference project style can only contain references of the DotnetTool type
The tool package could not be restored.
Tool 'typegen.dotnetcli' failed to install. This failure may have been caused by:

  • You are attempting to install a preview release and did not use the --version option to specify the version.
  • A package by this name was found, but it was not a .NET Core tool.
  • The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
  • You mistyped the name of the tool.

Any thoughts or ideas??

APPLICATION ERROR: Project file (*.csproj or *.xproj) not found in the project folder and no assembly path found in the config file

PM> typegen -v generate
Generating files for project "."...
No config file found for project ".". Default configuration will be used.
Assembly path not found in the config file. Assembly file will be searched for recursively in the project's bin\.
APPLICATION ERROR: Project file (*.csproj or *.xproj) not found in the project folder and no assembly path found in the config file
   at TypeGen.Cli.Business.ConfigProvider.GetDefaultAssemblyPath(String projectFolder) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Business\ConfigProvider.cs:line 106
   at TypeGen.Cli.Business.ConfigProvider.UpdateConfigAssemblyPaths(TgConfig config, String projectFolder) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Business\ConfigProvider.cs:line 75
   at TypeGen.Cli.Business.ConfigProvider.GetConfig(String configPath, String projectFolder) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Business\ConfigProvider.cs:line 48
   at TypeGen.Cli.Program.Generate(String projectFolder, String configPath) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 116
   at TypeGen.Cli.Program.Main(String[] args) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 78

The project is there so it looks like a bug

Restart Visual Studio required

You might need to mention in the docs, that one has to restart VS before you can use TypeGen in the PM. Otherwise I like your tool.

Add option to clear output directory (feature request)

Hi,

While using the TypeGen.DotNetCli I noticed the output directory leaves old TS models for classes C# that were already deleted. Is it possible to add an option to the tgconfig.json to remove all files in output dir prior TS model generation?

Without that, we might keep on aggregating old TS models when people forget to remove them.

Thanks,

Circular reference creates Stack Overflow

Given

public class Foo
{
    public Bar myBar { get; set; }
}

public class Bar
{
    public Foo myFoo { get; set; }
}

TypeGen crashes with stack overflow

Process is terminated due to StackOverflowException.

Giving the type with, eg, [TsType("Foo", "./foo")] works fine.

Error when running DotNetCli after tool upgrade

Hi,

We are running the dotnet-typegen -v generate as a post build event script. With every upgrade some of the 3 developers involved get issues that either the DLL or a class was not found and the CLI tool fails. This is the last issue my colleague has after he upgraded from 2.1.0 to 2.1.2 (both the package and cli tool).

C:\AppDev\Path\MyProjectName.WebAPI>dotnet-typegen -v generate
Generating files for project “.”...
Reading the config file from “.\tgconfig.json”
Assembly path not found in the config file. Assembly file will be searched for recursively in the project’s bin\.
Could not resolve assembly: MyProjectName.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null in any of the searched directories:
Could not resolve assembly: MyProjectName.Domain.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null in any of the searched directories:
Converter ‘PascalCaseToKebabCaseConverter’ not found in assemblies: ‘MyProjectName.WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Falling back to TypeGen.Core.
Converter ‘PascalCaseToKebabCaseConverter’ found in TypeGen.Core
Converter ‘PascalCaseToCamelCaseConverter’ not found in assemblies: ‘MyProjectName.WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Falling back to TypeGen.Core.
Converter ‘PascalCaseToCamelCaseConverter’ found in TypeGen.Core
Converter ‘ApiModelsGenerationSpec’ not found in assemblies: ‘MyProjectName.WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Falling back to TypeGen.Core.
APPLICATION ERROR: Converter ‘ApiModelsGenerationSpec’ not found in TypeGen.Core or any of the assemblies: ‘MyProjectName.WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’
  at TypeGen.Cli.Business.TypeResolver.ResolveNoAssembly(String typeName, String typeNameSuffix) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Business\TypeResolver.cs:line 84
  at TypeGen.Cli.Business.TypeResolver.Resolve(String typeIdentifier, String typeNameSuffix, IEnumerable`1 interfaceConstraints, IEnumerable`1 baseTypeConstraints) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Business\TypeResolver.cs:line 54
  at TypeGen.Cli.Program.<>c__DisplayClass9_1.<Generate>b__1(String name) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 144
  at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
  at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
  at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
  at TypeGen.Cli.Program.Generate(String projectFolder, String configPath, Boolean verbose) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 143
  at TypeGen.Cli.Program.Main(String[] args) in D:\Google Drive\Projects\type-gen\src\TypeGen\TypeGen.Cli\Program.cs:line 75

We all have .NET Core 2.1 in similar versions. Here is the tgconfig.json:

{
  "outputPath": "..\\MyProjectName.WebApp\\ClientApp\\src\\app\\common-services\\models",
  "customTypeMappings": {
    "System.Guid": "string",
    "System.DateTime": "string",
    "System.DateTimeOffset": "string"
  },
  "singleQuotes": true,
  "generationSpecs": [ "ApiModelsGenerationSpec" ],
  "clearOutputDirectory": true
}

The ApiModelsGenerationSpec is

    public class ApiModelsGenerationSpec : GenerationSpec
    {
        public ApiModelsGenerationSpec()
        {
            GetType().Assembly
                .GetTypes()
                .Where(x => x.IsClass && !x.IsAbstract && x.Namespace.StartsWith("MyProjectName.WebAPI.ApiModels", StringComparison.InvariantCulture))
                .ToList()
                .ForEach(x => AddInterface(x));
            //ForAssembly(GetType().Assembly)
            //    .AddInterfaces(@"MyProjectName.WebAPI\.ApiModels\.(.+)");
        }
    }

That also fails when my fellow colleague navigates to the project folder using command prompt and executes dotnet-typegen -v generate. This is to test it's irrelevant on the post-build. Also we ensured the project DLLs with the spec file are in the bin folder.

The weird thing is that I had no issues after upgrading. It also works fine in Azure Pipelines after upgrades. The colleague that has the issue right now, the previous upgrade we made it worked fine for him but failed for another colleague (some non determinism).

We tried:

  • Uninstalling the cli tool and installing it (VS and machine was reboot in between)
  • Removing all nuget packages

Have you run into this before or do you have any suggestions?
It feels like there is some caching issue or non deterministic issue after the upgrade.

Thanks,

Default strategy doesn't find .NET core assemblies

Without providing the assemblies property in tgconfig.json, TypeGen ProjectFolder outputs the following error:

GENERIC ERROR: Value cannot be null.
Parameter name: assemblyFile

Adding "bin/Debug/netcoreapp1.[x]/[ProjectName].dll" to assemblies resolves this. I don't think our project is configured exceptionally. Maybe the default strategy should look there for assemblies?

Project is .NET core 1.1 using VS2015.

Duplicate class names not supported

I would like to generate ts interfaces based on my existing models, but because they have the same name, only one interface is generated. My structure looks a bit like this:

public class GetFoo {
    public class Query<Response> {
        public string SomeProperty { get; set; }
    }

    public class Response {
        public string PropertyA { get; set; }
    }
}

public class GetBar {
    public class Query<Response> {
        public string SomeProperty { get; set; }
    }

    public class Response {
        public string PropertyB { get; set; }
    }
}

I am able to manipulate the type name with a type name converter and get the interfaces GetFooQuery, GetBarQuery, GetFooResponse and GetBarResponse, but the file name converter does not have any knowledge of the type which means I only get one Query.ts and one Response.ts file.

If I had access to the type in the name converter, or if I could apply the type converter before the name converter I guess it might work. It's currently not possible as far as I can see from the docs, maybe there is some other solution that I haven't come across?

singleQuotes doesn't affect enum

Hi,

We are trying to generate typescript enums with the string single quotes.

TGConfig get these to values.

"enumStringInitializers": true,
"singleQuotes": true,

But it is still generating enums with double quotes

Index file per folder

So, I like the index file generation feature, but it seems like overkill for the number of generated files I have. I wish it was usable on a per folder basis, based on "outDir" string on AddClass/Interface/etc.

feat: default OutputDir

Option to include a default output directory in tgconfig.json so that it doesn't need to be included in each annotation.

TsCustomBaseAttribute doesn't generate 'import-part'

From @salmin89 on June 21, 2018 8:58

SomeClass.cs

using TypeGen.Core.TypeAnnotations;

namespace MyProject.Types
{
    [TsIgnoreBase]
    [TsCustomBase("CustomBase")]
    [ExportTsInterface]
    public class SomeClass: CustomBase{ }
}

CustomBase.cs

using TypeGen.Core.TypeAnnotations;

namespace MyProject.Types
{
    [ExportTsInterface]
    public class CustomBase
    {
        public string name { get; set; }
        public string url { get; set; }
        [TsOptional]
        public string thumbnail { get; set; }
    }
}

SomeClass.ts

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export interface SomeClass extends CustomBase{

}

I'm missing import { CustomBase} from "./CustomBase"; from SomeClass.ts

Copied from original issue: jburzynski/TypeGenDocs#1

Configurable default type mappings

Would be great if it was possible to inject the ITypeService instance or if there were some other way to affect the generated types. For example, for DateTime I'd like the TypeScript files to have the type string, and guid should map to string.

If I could provide ITypeService I wouldn't need to annotate all my source code. :)

I also need to provide TS generation for nuget packages, which I can't necessarily easily add type annotations to. Providing type mapping by convention would allow me to solve that locally.

Originally posted by @maxmalmgren in #35 (comment)

TsDefaultValue mucks up property names

adding TsDefaultValue results in $tg{} being prepended to property names:

[TsDefaultValue("\"\"")]
public string MyString { get; set; }

=>

$tg{}myString = "";

Feature: Parsing complex custom types

This annotation

[TsType("MyType[]", "./my-type")]

currently results in this incorrect import

import { MyType[] } from "./my-type";

The results are similar with MyType?. The workaround is to manually import the type in the .ts file with a custom header and not specify an import in TsType. Since that's simple enough to do, this issue is a feature request for parsing in the TsType attribute.

Build a .NET Core Cli Tool

It would be nice if this package could be published as a .NET Core Cli Tool.
An advantage would be, that one could simply add <DotNetCliToolReference Include="TypeGen" Version="1.6.0" /> to the *.csproj file and after restoring run dotnet TypeGen. Global install of the tool would then also be supported by dotnet tool install -g TypeGen.
Since there is already a TypeGen Cli it maybe wouldn't need much work.

Generated files successfully but not seeing any files

I have TypeGen 2.1.2 package installed and am using version 2.1.2 of the CLI.

I created the GenerationSpec below and added it to the root of my project.

    public class MyGenerationSpec : GenerationSpec
    {
        public MyGenerationSpec()
        {
            AddEnum<FarmDTOs.Loss.Causes>();
        }
    }

When I run dotnet typegen generate I get the following messages:

Generating files for project "."...
Files for project "." generated successfully.

However, I don't see any files created in my project. Any ideas?

Error in converting Data Type: Guid - DateTimeOffset - TimeSpan in EF6 model

I tried to convert EF6 model classes to type script.
I get error to the following data type:

  • Guid
  • DateTimeOffset
  • TimeSpan

Unhandled Exception: TypeGen.Core.CoreException: Generated type must be either a
C# class or enum. Error when generating type System.DateTimeOffset; inside type: System.DateTimeOffset, in Model ....

Is there any mapping to these data types?
What can I do to successfully convert the EF6 to type script?

Not compatible with dot net core 1.1

Is dotnet core compatibility on the roadmap for this project? I would love to use it. Thanks!

Errors in C:\Users\[REDACTED].xproj
    Package TypeGen 1.4.1 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package TypeGen 1.4.1 supports: net (.NETFramework,Version=v0.0)
    One or more packages are incompatible with .NETCoreApp,Version=v1.1.

Relative import-path is not updated when using custom OutputDir

Hi,

The import-path for any reference-classes is not following the structure. It will try to import it directly in the same folder /MySpecificFolder, no matter where the referenceClass is stored

[ExportTsInterface(OutputDir = "MySpecificFolder")]
public class MyTestClass
    {
        public List<ReferenceClass> ListOfThings{ get; set; }
    }

like this:
import { ReferenceClass} from "./MyOtherClasses/ReferenceClass";

The correct import would be ../ because we know that we are 1 level deep into "MySpecificFolder"

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.