Git Product home page Git Product logo

jtsgen's People

Contributors

dzuvic avatar exonity avatar fvonberg avatar scholld 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

Watchers

 avatar  avatar  avatar  avatar  avatar

jtsgen's Issues

name space mapping

the name space of the generated types could be shortened, e.g. by mapping a specific top level package to a shorter one or even to the root name space. The priority of this feature depends on usability of the IDE regarding imports.

NPE when Type Mapping is not available

java.lang.NullPointerException: type
	at java.util.Objects.requireNonNull(Objects.java:228)
	at dz.jtsgen.processor.model.TSRegularMemberBuilder.<init>(TSRegularMemberBuilder.java:26)
	at dz.jtsgen.processor.model.TSRegularMemberBuilder.of(TSRegularMemberBuilder.java:183)
	at dz.jtsgen.processor.jtp.conv.JavaTypeElementExtractingVisitor.visitExecutable(JavaTypeElementExtractingVisitor.java:100)
	at dz.jtsgen.processor.jtp.conv.JavaTypeElementExtractingVisitor.visitExecutable(JavaTypeElementExtractingVisitor.java:43)

create module

Example:
`
declare module "exampleApi" {
export interface Order {
items: Array;
customer: Person;
}

}
`

and in package.json: instead typings use main

support exporting for direct usage

The easiest way for importing is to generate the output directly into the the client. Example:

import {Person} from "./api_types/exampleapi/example-api";

Kotlin Boolean doesn't show up

When using Kotlin and jtsgen classes with boolean members will not convert properly. Minimal example:

// Kotlin input
@TypeScript
class Foo(val bar: Boolean)

// Output
export interface Foo{}

Kotlin generates for bar the getter getBar(). A workaround is to provide a function isBar() as getter. Then the output is generated right.

// Kotlin input
@TypeScript
class Foo(val bar: Boolean) { isBar() = bar }

//Output
export interface Foo {
  bar: boolean
}

Refactoring: Rename TSTargetType

The name of this type misleading. It should be renamed to something like TypeMapInfo. It also represents a kind of type, but not a used one. During: #46

Bug: Java Bean Protocol not complete

Private members with is-Getter are not generated in output file.

private boolean registered;
public boolean isRegistered() {
        return registered;
    }

User defined conversions

Getting jtsgen in a usable state user defined conversion has to be made possible:

  • Some kind of plug-in: The user defines a class that the processor calls for conversion: that smells a bit over engineered
  • additional parameter at the TypeScript annotation: easiest way to implement, but the user has to type this conversion every time
  • add the conversion as annotation parameter:
  • using a new annotation for defining a typescript module at package

TSOption or TSReadOnly Annotation

since version 0.0.2 readonly values are supported. But i think it's done in a weird way, for instance: take a bean with finals and a constructor: currently all members are declared read only, but that is not correct in any way, because it depends on how the instance is created. I am not sure if it could be possible to extract that information without type annotations, which are not supported by the regular annotation processing api. Therefore the user should be able to override read only types.

Option to generate classes instead of interfaces

There a several use cases having classes instead of interfaces:

  • creating objects adhering a generated interface is a bit cumbersome (either using partial or filling up all values)
  • sometimes it might be useful exposing constants
  • the type guard should be a member of a class
  • possibility to generate type specific default values

The mapping DSL has to be changed reflecting the default values of a type. The Default value should be changed by an TSOption Annotation

Capability generate User-Defined Type Guards (enable basic TypeCheck at Runtime)

Since we are working with plain objects in JavaScript and not with class-instances we can't do typeof checks. TypeScript has a feature called Type Guards that can help you with that.

Example:


class Person {
  name: string;
  age: number;
  mail: string;
  optionalVal?: any;
}

const person: Person = {
  name: 'Can',
  age: 6,
  mail: '[email protected]'
};

const notAPerson =  {
  name: 'Can',
  mail: '[email protected]'
};
console.log(typeof person, typeof person === typeof Person); // --> 'object', false :(



// with a  'typeguard' function 
function instanceOfPerson(object: any): object is Person {
  return 'name' in object
      && 'age' in object
      && 'mail' in object;
}

// usage:
console.log(typeof person, instanceOfPerson(person)); // --> 'object', true :)
console.log(typeof person, instanceOfPerson(notAPerson)); // --> 'object', false :)

https://codepen.io/anon/pen/weJbEr

So it'd be nice to have a setting || annotation to enable the generation for instanceOfX functions.

User-Defined Type Guards - TypeScript Docs

TypeScript Deep Dive

Bug: Generics in Ouput are missing

Input:

public class Test<T> {
private List<T> someList = new ArrayList<>();
public List<T> getSomeList() { return this.someList;}
public void setSomeList(List<T> someList) {this.someList = someList;}
}

should result in:

export interface Test<T> {
someList: T[]; // or someList: Array<T>;
}

Missing Type Variable

The Type Variable is not generated:

Example:

interface Bla<T> {
    val bla:Int
}

@TypeScript
interface BlaBla<T> : Bla<T> {
    val blabla:Int
}

Leads to

  export interface Bla<T>  {
    bla: number;
  }

  export interface BlaBla<T>  extends Bla {
    blabla: number;
  }

jtsgen should respect @JsonProperty annotation

When using Jackson and the @JsonProperty annotation to rename properties, jtsgen generates interfaces with wrong name.

Example:

@Typescript
data class Foo(
    @JsonProperty("foo_bar") @get:JsonProperty("foo_bar") val bar: String
)

generates: interface Foo { bar: string }

Using JDK9 some tests fail

  • One test using sun.misc.Version testing exclusion.
  • warning: Implicitly compiled files were not subject to annotation processing.

Support only direct only type mapping

This is a followup of #28. Direct only type mapping should also be supported. But maybe this is not needed. At first a proper use case should be defined for this kind of mapping.

Support for no name space mapping

  • The name space mapping list is prepended to the calculated one
  • to override the name space mapping, a new name space mapping strategy is needed

Support generating Ouptput without an annotation

Types that are not defined in it's own compilation unit are not extracted without a reference to an annotated class. Therefore

  • Add a compile option adding these types
  • Add a similar data structure to the TSModule annotation

Bug: wrong dependency in Processor

the runtime scope of the generated maven pom is wrong:

    <dependency>
      <groupId>org.immutables</groupId>
      <artifactId>value</artifactId>
      <version>2.5.5</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.immutables</groupId>
      <artifactId>builder</artifactId>
      <version>2.5.5</version>
      <scope>runtime</scope>
    </dependency>

Map Collection<T> to T[] instead of List<T>

The following two mapping should be done i another way:

  • a java.util.Collection<T> and its sub types should be mapped to T[]
  • a java.util.map<K,V> should be mapped to list of a type {[key: K]: V}

For this the mapping DSL should be extended to the the following:

  • the mapping DSL consists of two parts distinguished by an single arrow ->
  • The left hand side is the canonical Java type with type parameters
  • The right hand side consists of literals and type variables, where the converted type from the java will be inserted
  • The type variables on the right hand side are escaped using arrow braces or back tick symbols. arrow braces are kept, back ticks are removed from the result

For example, when defining a mapping like this:

java.uti.Map<K,V> -> {[key: `K`]: `V`}

the an HashMap<String,Integer> will be converted to {[kex: string]: number}

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.