Skip to content

Commit

Permalink
External imports support base-type: any (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferozco authored and iamdanfox committed Jul 26, 2018
1 parent 144b862 commit c0d6d9f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public abstract class TypeName {
private static final Pattern CUSTOM_TYPE_PATTERN = Pattern.compile("^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$");
static final ImmutableSet<String> PRIMITIVE_TYPES =
ImmutableSet.of(
"unknown", "string", "integer", "double", "boolean", "safelong", "rid", "bearertoken", "uuid");


public static final TypeName UNKNOWN = TypeName.of("unknown");
"any", "string", "integer", "double", "boolean", "safelong", "rid", "bearertoken", "uuid");

@JsonValue
public abstract String name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public enum PrimitiveType implements LocalReferenceType {
SAFELONG(TypeName.of("safelong")),
RID(TypeName.of("rid")),
BEARERTOKEN(TypeName.of("bearertoken")),
UUID(TypeName.of("uuid"));
UUID(TypeName.of("uuid")),
ANY(TypeName.of("any"));

private static final Map<TypeName, PrimitiveType> types =
EnumSet.allOf(PrimitiveType.class).stream().collect(Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import com.google.common.collect.ImmutableList;
import com.palantir.conjure.parser.types.names.Namespace;
import com.palantir.conjure.parser.types.names.TypeName;
import com.palantir.conjure.parser.types.primitive.PrimitiveType;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -53,6 +55,13 @@ public void duplicate_keys_fail_to_parse() throws Exception {
.hasMessageContaining("Duplicate field 'services'");
}

@Test
public void testConjureExternalImports() {
ConjureDefinition conjure = ConjureParser.parse(new File("src/test/resources/example-external-types.yml"));
assertThat(conjure.types().imports().get(TypeName.of("ExampleAnyImport")).baseType())
.isEqualTo(PrimitiveType.fromString("any"));
}

@Test
public void testConjureRevisitedImports() throws IOException {
// create a hierarchy of dependencies such that a significant amount of files is visited repeatedly
Expand Down
14 changes: 14 additions & 0 deletions conjure-core/src/test/resources/example-external-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
types:
imports:
ExampleAnyImport:
base-type: any
external:
java: com.palantir.example.ExternalAnyImport
ExampleIntegerImport:
base-type: string
external:
java: com.palantir.example.ExternalIntegerImport
ExampleTypeScriptImport:
base-type: string
external:
typescript: "@palantir/foo"

0 comments on commit c0d6d9f

Please sign in to comment.