Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Aug 8, 2022
1 parent 97b9d8c commit 7e6c892
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ private static FieldInfo fieldInfo(AnnotatedValueResolver resolver,
FieldRequirement.REQUIRED : FieldRequirement.OPTIONAL)
.build();
} else {
return FieldInfo.of(elementType.getName(), toTypeSignature(elementType));
return FieldInfo.builder(elementType.getName(), toTypeSignature(elementType))
.requirement(resolver.shouldExist() ?
FieldRequirement.REQUIRED : FieldRequirement.OPTIONAL)
.build();
}
}
}
Expand Down Expand Up @@ -351,7 +354,7 @@ static TypeSignature toTypeSignature(Type type) {
if (type == Double.class || type == double.class) {
return DOUBLE;
}
if (type == char.class) {
if (type == Character.class || type == char.class) {
return CHAR;
}
if (type == String.class) {
Expand Down Expand Up @@ -409,10 +412,6 @@ static TypeSignature toTypeSignature(Type type) {
return TypeSignature.ofList(toTypeSignature(clazz.getComponentType()));
}

if (clazz.isEnum()) {
return TypeSignature.ofNamed(clazz);
}

return TypeSignature.ofNamed(clazz);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private static <T> T extractFromGetter(JavaType classType, JavaType fieldType, S
return null;
}

private StructInfo newReflectiveStructInfo(Class<?> clazz) {
private static StructInfo newReflectiveStructInfo(Class<?> clazz) {
return (StructInfo) ReflectiveNamedTypeInfoProvider.INSTANCE.newNamedTypeInfo(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import java.util.Arrays;
import java.util.List;

import com.linecorp.armeria.common.annotation.Nullable;
import javax.annotation.Nonnull;

import com.linecorp.armeria.server.annotation.Description;
import com.linecorp.armeria.server.docs.DescriptionInfo;
import com.linecorp.armeria.server.docs.FieldInfo;
Expand All @@ -41,13 +42,9 @@ enum ReflectiveNamedTypeInfoProvider implements NamedTypeInfoProvider {

INSTANCE;

@Nullable
@Nonnull
@Override
public NamedTypeInfo newNamedTypeInfo(Object typeDescriptor) {
if (!(typeDescriptor instanceof Class)) {
return null;
}

final Class<?> clazz = (Class<?>) typeDescriptor;
final List<FieldInfo> fieldInfos = Arrays.stream(clazz.getDeclaredFields())
.filter(field -> !Modifier.isStatic(field.getModifiers()))
Expand Down Expand Up @@ -80,12 +77,10 @@ private static FieldInfo fieldInfo(Field field) {

private static DescriptionInfo descriptionInfo(AnnotatedElement element) {
final Description description = AnnotationUtil.findFirst(element, Description.class);
final DescriptionInfo descriptionInfo;
if (description == null) {
descriptionInfo = DescriptionInfo.empty();
return DescriptionInfo.empty();
} else {
descriptionInfo = DescriptionInfo.from(description);
return DescriptionInfo.from(description);
}
return descriptionInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,19 @@ public DocServiceBuilder injectedScriptSupplier(
return this;
}

/**
* Adds the specified {@link NamedTypeInfoProvider}s used to create a {@link NamedTypeInfo} from
* a type descriptor.
*/
public DocServiceBuilder namedTypeInfoProvider(
Iterable<? extends NamedTypeInfoProvider> namedTypeInfoProviders) {
requireNonNull(namedTypeInfoProviders, "namedTypeInfoProviders");
for (NamedTypeInfoProvider typeInfoProvider : namedTypeInfoProviders) {
namedTypeInfoProvider(typeInfoProvider);
}
return this;
}

/**
* Adds the specified {@link NamedTypeInfoProvider} used to create a {@link NamedTypeInfo} from
* a type descriptor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.linecorp.armeria.server.docs;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;

import java.util.EnumSet;
Expand Down Expand Up @@ -131,11 +132,11 @@ public EnumInfo withDescriptionInfo(DescriptionInfo descriptionInfo) {
return new EnumInfo(name, values, descriptionInfo);
}

private static Iterable<EnumValueInfo> toEnumValues(Class<? extends Enum<?>> enumType) {
private static List<EnumValueInfo> toEnumValues(Class<? extends Enum<?>> enumType) {
final Class<?> rawEnumType = requireNonNull(enumType, "enumType");
@SuppressWarnings({ "unchecked", "rawtypes" })
final Set<Enum> values = EnumSet.allOf((Class<Enum>) rawEnumType);
return values.stream().map(e -> new EnumValueInfo(e.name()))::iterator;
return values.stream().map(e -> new EnumValueInfo(e.name())).collect(toImmutableList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public interface NamedTypeInfoProvider {
* Returns a newly created {@link NamedTypeInfoProvider} that tries this {@link NamedTypeInfoProvider}
* first and then the specified {@link NamedTypeInfoProvider} when the first call returns {@code null}.
*/
default NamedTypeInfoProvider orElse(NamedTypeInfoProvider provider) {
requireNonNull(provider, "provider");
default NamedTypeInfoProvider orElse(NamedTypeInfoProvider other) {
requireNonNull(other, "other");
return typeDescriptor -> {
final NamedTypeInfo structInfo = newNamedTypeInfo(typeDescriptor);
if (structInfo != null) {
return structInfo;
} else {
return provider.newNamedTypeInfo(typeDescriptor);
return other.newNamedTypeInfo(typeDescriptor);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ public static ParamQuery of(String query) {
@Nullable
private final String query;

@Description("param query2")
@Nullable
private final Optional<String> query2 = null;

private ParamQuery(@Nullable String query) {
this.query = query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConf
NamedTypeInfoProvider namedTypeInfoProvider) {
requireNonNull(serviceConfigs, "serviceConfigs");
requireNonNull(filter, "filter");
requireNonNull(namedTypeInfoProvider, "namedTypeInfoProvider");

final Set<GrpcService> addedService = new HashSet<>();
final ImmutableList.Builder<HttpEndpoint> httpEndpoints = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public ServiceSpecification generateSpecification(Set<ServiceConfig> serviceConf
NamedTypeInfoProvider namedTypeInfoProvider) {
requireNonNull(serviceConfigs, "serviceConfigs");
requireNonNull(filter, "filter");
requireNonNull(namedTypeInfoProvider, "namedTypeInfoProvider");

final Map<Class<?>, EntryBuilder> map = new LinkedHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

/**
* A {@link NamedTypeInfoProvider} to create a {@link NamedTypeInfo} from a Thrift type such as {@link TBase}
* , {@link TEnum} or {@link TException}.
* {@link TEnum} or {@link TException}.
*/
public final class ThriftNamedTypeInfoProvider implements NamedTypeInfoProvider {

Expand Down

0 comments on commit 7e6c892

Please sign in to comment.