Skip to content

Commit

Permalink
Expose optional annotations in TypescriptServiceGeneratorConfiguration (
Browse files Browse the repository at this point in the history
#45)

* Expose optional annotations in TypescriptServiceGeneratorConfiguration

* Add default optional annotations
  • Loading branch information
ccolgrove authored and ryanmcnamara committed Apr 20, 2016
1 parent bfa9cd4 commit bae91fc
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.palantir.code.ts.generator;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -15,6 +16,9 @@
import java.util.Map;
import java.util.Set;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import org.immutables.value.Value;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down Expand Up @@ -92,7 +96,7 @@ public boolean emitDuplicateJavaMethodNames() {
public boolean emitES6() {
return false;
}

/**
* A Java format string, expected to have exactly one %s where a generic should be placed.
* Specifies what return types should look like.
Expand All @@ -111,6 +115,15 @@ public Set<Class<?>> ignoredAnnotations() {
return new HashSet<>();
}

/**
* A list of annotations that will generate fields as optional in the typescript definitions.
*/
@Value.Default
@SuppressWarnings("unchecked")
public List<Class<? extends Annotation>> optionalAnnotations() {
return Lists.newArrayList(CheckForNull.class, Nullable.class);
}

/**
* The Typescript module to prefix all generated code under, for example: "MyProject.GeneratedCode"
*/
Expand Down Expand Up @@ -201,6 +214,7 @@ public Settings getSettings() {
settings.sortDeclarations = true;
settings.noFileComment = true;
settings.jsonLibrary = JsonLibrary.jackson2;
settings.optionalAnnotations = optionalAnnotations();
settings.outputKind = TypeScriptOutputKind.global;
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.extensions = Lists.newArrayList(new EnumConstantsExtension());
Expand Down

0 comments on commit bae91fc

Please sign in to comment.