Skip to content

Commit

Permalink
fix: use null value for enum fields in spec template
Browse files Browse the repository at this point in the history
  • Loading branch information
artemy-osipov committed Aug 11, 2020
1 parent bbd8a55 commit e68700c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'nebula.release' version '15.0.3'
id 'nebula.release' version '15.1.0'
id 'com.jfrog.bintray' version '1.8.5' apply false
id 'com.github.ben-manes.versions' version '0.28.0'
id 'com.github.ben-manes.versions' version '0.29.0'
}

def micronautModules = [project(':rest-bridge-micronaut'), project(':examples:micronaut-app')]
Expand All @@ -27,7 +27,7 @@ subprojects {
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'

testImplementation 'org.codehaus.groovy:groovy-test:3.0.4'
testImplementation 'org.codehaus.groovy:groovy-test:3.0.5'

def junitVersion = '5.6.2'
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
Expand All @@ -42,7 +42,7 @@ subprojects {

configure(micronautModules) {
dependencies {
def micronautBom = 'io.micronaut:micronaut-bom:2.0.0'
def micronautBom = 'io.micronaut:micronaut-bom:2.0.1'
annotationProcessor platform(micronautBom)
implementation platform(micronautBom)
testAnnotationProcessor platform(micronautBom)
Expand All @@ -51,7 +51,7 @@ configure(micronautModules) {

configure(springModules) {
dependencies {
def springBootBom = 'org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE'
def springBootBom = 'org.springframework.boot:spring-boot-dependencies:2.3.2.RELEASE'
implementation platform(springBootBom)
annotationProcessor platform(springBootBom)
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
Expand Down
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Jul 06 20:41:35 MSK 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion rest-bridge-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {
api 'org.apache.thrift:libthrift:0.13.0'

implementation 'org.reflections:reflections:0.9.12'
implementation 'io.github.artemy.osipov.thrift:jackson-datatype-thrift:0.3.0'
implementation 'io.github.artemy.osipov.thrift:jackson-datatype-thrift:0.3.1'

testImplementation project(':examples:thrift')
testImplementation 'org.mockito:mockito-core:3.3.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Getter
@RequiredArgsConstructor
public enum DataType {
ENUM(true),
STRING(true),
NUMBER(true),
BOOLEAN(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.Value;

import java.util.EnumMap;
import java.util.Map;

@Value
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ToString(of = "type")
public class SpecType {

private static final Map<DataType, SpecType> PRIMITIVES = new EnumMap<>(DataType.class);
Expand All @@ -32,8 +34,4 @@ public static SpecType primitive(DataType type) {
public static SpecType array(SpecType containerType) {
return new SpecType(DataType.ARRAY, containerType, null);
}

public String toString() {
return "SpecType(type=" + type + ", containerType=" + containerType + ", nested=" + nested.length + " count)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public SpecType from(Class<?> clazz) {
if (isAssignable(clazz, Number.class, byte.class, short.class, int.class, long.class, float.class, double.class)) {
return SpecType.primitive(DataType.NUMBER);
}
if (isAssignable(clazz, String.class, Enum.class, byte[].class, ByteBuffer.class)) {
if (isAssignable(clazz, Enum.class)) {
return SpecType.primitive(DataType.ENUM);
}
if (isAssignable(clazz, String.class, byte[].class, ByteBuffer.class)) {
return SpecType.primitive(DataType.STRING);
}
if (isAssignable(clazz, Boolean.class, boolean.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ class TestData {
new SpecField('i32Field', SpecType.primitive(DataType.NUMBER)),
new SpecField('i64Field', SpecType.primitive(DataType.NUMBER)),
new SpecField('doubleField', SpecType.primitive(DataType.NUMBER)),
new SpecField('enumField', SpecType.primitive(DataType.STRING)),
new SpecField('enumField', SpecType.primitive(DataType.ENUM)),
new SpecField('binaryField', SpecType.primitive(DataType.STRING)),
new SpecField('structField', simpleStructSpecType()),
new SpecField('listStructField', SpecType.array(simpleStructSpecType())),
new SpecField('unionField', SpecType.object(
new SpecField('enum1', SpecType.primitive(DataType.STRING)),
new SpecField('enum2', SpecType.primitive(DataType.STRING))
new SpecField('enum1', SpecType.primitive(DataType.ENUM)),
new SpecField('enum2', SpecType.primitive(DataType.ENUM))
))
)),
new SpecField('listStructField', SpecType.array(simpleStructSpecType())),
Expand Down Expand Up @@ -168,7 +168,7 @@ class TestData {
"i32Field": 0,
"i64Field": 0,
"doubleField": 0,
"enumField": "",
"enumField": null,
"binaryField": "",
"structField": {
"f1": false,
Expand All @@ -179,8 +179,8 @@ class TestData {
"f2": ""
}],
"unionField": {
"enum1": "",
"enum2": ""
"enum1": null,
"enum2": null
}
},
"listStructField": [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SpecTypeAdapterTest {
Arguments.of(double.class, SpecType.primitive(DataType.NUMBER)),
Arguments.of(Double.class, SpecType.primitive(DataType.NUMBER)),
Arguments.of(String.class, SpecType.primitive(DataType.STRING)),
Arguments.of(Enum.class, SpecType.primitive(DataType.STRING)),
Arguments.of(Enum.class, SpecType.primitive(DataType.ENUM)),
Arguments.of(byte[].class, SpecType.primitive(DataType.STRING)),
Arguments.of(ByteBuffer.class, SpecType.primitive(DataType.STRING))
)
Expand All @@ -54,7 +54,7 @@ class SpecTypeAdapterTest {
void "should build spec from enum"() {
def spec = adapter.from(TestEnum)

assert spec == SpecType.primitive(DataType.STRING)
assert spec == SpecType.primitive(DataType.ENUM)
}

@Test
Expand All @@ -69,8 +69,8 @@ class SpecTypeAdapterTest {
def spec = adapter.from(TestUnion)

assert spec == SpecType.object(
new SpecField("enum1", SpecType.primitive(DataType.STRING)),
new SpecField("enum2", SpecType.primitive(DataType.STRING))
new SpecField("enum1", SpecType.primitive(DataType.ENUM)),
new SpecField("enum2", SpecType.primitive(DataType.ENUM))
)
}

Expand Down
4 changes: 2 additions & 2 deletions rest-bridge-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {

dependencies {
implementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
implementation 'io.rest-assured:rest-assured:4.3.0'
api 'org.mockito:mockito-core:3.3.3'
implementation 'io.rest-assured:rest-assured:4.3.1'
api 'org.mockito:mockito-core:3.4.6'

implementation project(':rest-bridge-core')
implementation project(':examples:thrift')
Expand Down

0 comments on commit e68700c

Please sign in to comment.